[Winpcap-users] Not getting IP address from WinPcap?

Janne Heikkinen janne.m.heikkinen at helsinki.fi
Fri Apr 17 03:57:03 PDT 2009


Following code shows IP address 0.0.0.0 for Intel card that has
IP 169.254.45.253 according to ipconfig/all :

  if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
  {
    fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
    exit(1);
  }

  char buff[512];

  for(d=alldevs; d; d=d->next)
  {
         pcap_addr *n;
	AF_INET;
	struct sockaddr *addr;
	struct sockaddr_in *in;

	for (n=d->addresses; n ; n=n->next)
	{
		if (n->addr->sa_family == AF_INET)
		{
			in = (struct sockaddr_in *)n->addr;

			unsigned char *p = (unsigned char *)&in->sin_addr;
			sprintf(buff, "%d.%d.%d.%d", *p, *(p+1), *(p+2), *(p+3));

			printf("IP: %s\n",buff);
		}
	}
  }

ipconfig/all shows this info for the adapter in question:

   Ethernet adapter Local Area Connection 4:

    Connection-specific DNS Suffix  . :
    Description . . . . . . . . . . . : Intel(R) PRO/1000 PT Desktop Adapter
    Physical Address. . . . . . . . . : 00-1B-21-1E-59-C2
    DHCP Enabled. . . . . . . . . . . : Yes
    Autoconfiguration Enabled . . . . : Yes
    Autoconfiguration IPv4 Address. . : 169.254.45.253(Preferred)
    Subnet Mask . . . . . . . . . . . : 255.255.0.0
    Default Gateway . . . . . . . . . :
    NetBIOS over Tcpip. . . . . . . . : Enabled

Any ideas about what could be wrong?

- Janne



More information about the Winpcap-users mailing list