<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<STYLE>.hmmessage P {
        PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px
}
BODY.hmmessage {
        FONT-SIZE: 10pt; FONT-FAMILY: Verdana
}
</STYLE>

<META content="MSHTML 6.00.6000.16788" name=GENERATOR></HEAD>
<BODY class=hmmessage bgColor=#ffffff>
<DIV><FONT face="Courier New">Have you debugged your application? Where does it 
crash exactly? within your app code or within the winpcap dlls?</FONT></DIV>
<DIV><FONT face="Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New">Have a nice day</FONT></DIV>
<DIV><FONT face="Courier New">GV</FONT></DIV>
<BLOCKQUOTE 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV 
  style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B> 
  <A title=samudavid@hotmail.com href="mailto:samudavid@hotmail.com">samu</A> 
  </DIV>
  <DIV style="FONT: 10pt arial"><B>To:</B> <A title=winpcap-users@winpcap.org 
  href="mailto:winpcap-users@winpcap.org">winpcap-users@winpcap.org</A> </DIV>
  <DIV style="FONT: 10pt arial"><B>Sent:</B> Sunday, January 04, 2009 5:35 
  PM</DIV>
  <DIV style="FONT: 10pt arial"><B>Subject:</B> [Winpcap-users] Problem getting 
  local MAC</DIV>
  <DIV><BR></DIV>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>
  <P>
  <HR>

  <P></P>_______________________________________________<BR>Winpcap-users 
  mailing 
  list<BR>Winpcap-users@winpcap.org<BR>https://www.winpcap.org/mailman/listinfo/winpcap-users<BR></BLOCKQUOTE></BODY></HTML>