<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
</style>
</head>
<body class='hmmessage'>
Hello everybody,<br><br>Im using WPCAP to send and capture ethernet packets. My program is written in VS C 2003.<br><br>I need to get my local MAC address to send ethernets frames with my MAC address in the source field. I was looking for it in the mail list and found the following example in the developers pack:<br><pre>Examples-Remote/PacketDriver/GetMacAdress<br><br>The program works perfectly, but when i add the code to my program it stops working. I´ve comment <br>out all the things that i don´t need.<br><br>When i run the program it fails (in run time) with an exception accesing a memory location. I´ve <br>checked that the array "AdapterList" stores the correct information.<br><br>Thanks a lot to everybody, i hope that the problem is easy to be solved. <br><br><br><br>#define Max_Num_Adapter 10<br>int CRSACOM::ObtenerMACLocal(int Open)<br>{<br>        <br>char AdapterList[Max_Num_Adapter][1024];<br><br>        LPADAPTER        lpAdapter = 0;<br>        int                        i;<br>        DWORD                dwErrorCode;<br>        char                AdapterName[8192];<br>        char                *temp,*temp1;<br>        int                        AdapterNum=0;<br>        ULONG                AdapterLength;<br>        PPACKET_OID_DATA  OidData;<br>        BOOLEAN                Status;<br>        <br>        <br><br><br><br>        //<br>        // Obtain the name of the adapters installed on this machine<br>        //<br><br>//        printf("Packet.dll test application. Library version:%s\n", PacketGetVersion());<br>        <br>        //printf("Adapters installed:\n");<br>        i=0;        <br>        <br>        AdapterLength = sizeof(AdapterName);<br>        <br>        if(PacketGetAdapterNames(AdapterName,&amp;AdapterLength)==FALSE){<br>                //printf("Unable to retrieve the list of the adapters!\n");<br>                return -1;<br>        }<br>        temp=AdapterName;<br>        temp1=AdapterName;<br><br>        while ((*temp!='\0')||(*(temp-1)!='\0'))<br>        {<br>                if (*temp=='\0') <br>                {<br>                        memcpy(AdapterList[i],temp1,temp-temp1);<br>                        temp1=temp+1;<br>                        i++;<br>                }<br>                temp++;<br>        }<br>                  <br>        AdapterNum=i;<br>        //for (i=0;i&lt;AdapterNum;i++)<br>        //        printf("\n%d- %s\n",i+1,AdapterList[i]);<br>        //printf("\n");<br><br>/*<br>        do <br>        {<br>                printf("Select the number of the adapter to open : ");<br>                scanf("%d",&amp;Open);<br>                if (Open&gt;AdapterNum) printf("\nThe number must be smaller than %d",AdapterNum); <br>        } while (Open&gt;AdapterNum);<br>        <br>*/<br>        //<br>        // Open the selected adapter<br>        //<br><br>        lpAdapter =   PacketOpenAdapter(AdapterList[Open]);<br>        <br>        <br>        if (!lpAdapter || (lpAdapter-&gt;hFile == INVALID_HANDLE_VALUE))<br>        {<br>                dwErrorCode=GetLastError();<br>                //printf("Unable to open the adapter, Error Code : %lx\n",dwErrorCode); <br><br>                return -1;<br>        }        <br><br>        // <br>        // Allocate a buffer to get the MAC adress<br>        //<br><br>        <br>        OidData = (PACKET_OID_DATA*)malloc(6 + sizeof(PACKET_OID_DATA));<br>        if (OidData == NULL) <br>        {<br>                //printf("error allocating memory!\n");<br>                PacketCloseAdapter(lpAdapter);<br>                return -1;<br>        }<br><br>        // <br>        // Retrieve the adapter MAC querying the NIC driver<br>        //<br><br>        OidData-&gt;Oid = OID_802_3_CURRENT_ADDRESS;<br><br>        OidData-&gt;Length = 6;<br>        ZeroMemory(OidData-&gt;Data, 6);<br>        <br>        Status = PacketRequest(lpAdapter, FALSE, OidData);<br><br><br>        if(Status)<br>        {<br><br>                memcpy(MACLocal,OidData-&gt;Data,6);<br>        /*        printf("The MAC address of the adapter is %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",<br>                        (PCHAR)(OidData-&gt;Data)[0],<br>                        (PCHAR)(OidData-&gt;Data)[1],<br>                        (PCHAR)(OidData-&gt;Data)[2],<br>                        (PCHAR)(OidData-&gt;Data)[3],<br>                        (PCHAR)(OidData-&gt;Data)[4],<br>                        (PCHAR)(OidData-&gt;Data)[5]);*/<br>        }<br>        else<br>        {<br>                //printf("error retrieving the MAC address of the adapter!\n");<br>        }<br><br>        free(OidData);<br>        PacketCloseAdapter(lpAdapter);<br>        return (0);<br><br>}<br></pre><br /><hr />¡Accede al correo desde el móvil!  <a href='http://vivelive.com/encuesta/' target='_new'>¿Qué opinas? </a></body>
</html>