On Tue, Apr 30, 2002 at 10:20:47AM +0200, Brad Knowles wrote:
>       The segment of code that calls this routine says:
> 
>      if (pcap_lookupnet(iname, (uint32_t *)&(interf.net),
>                                   (uint32_t *)&(interf.netmask), errbuf) < 0) {
>          fprintf(stderr,"pcap_lookupnet: %s\n",errbuf);
>          return -1;
>      }
> 
>       Looking at the libpcap header files, it seems that pcap.h defines:
> 
> /*
>   * Compatibility for systems that have a bpf.h that
>   * predates the bpf typedefs for 64-bit support.
>   */
> #if BPF_RELEASE - 0 < 199406
> typedef int bpf_int32;
> typedef u_int bpf_u_int32;
> #endif
> 
>       But this value does not seem to be otherwise defined anywhere in 
> /usr/local/include/pcap*.h -- the value is used in a variety of 
> places, but this seems to be the only potential definition.

Well, yes, the idea is that on systems where BPF_RELEASE is defined and
has a value of 199406 or greater, <net/bpf.h> defines bpf_int32 and
bpf_u_int32.

<pcap.h> from tcpdump.org includes <net/bpf.h>, so if <net/bpf.h> either
defines BPF_RELEASE as a value >= 199406 and has typedefs for bpf_int32
and bpf_u_int32, or doesn't define BPF_RELEASE, or defines it as a value
< 199406, either <pcap.h> will define them itself or will include a
header file that defines them.

Therefore, either

        1) whatever <pcap.h> you're including isn't the one from
           tcpdump.org

or

        2) <pcap.h> is including some version of <net/bpf.h> that
           defines BPF_RELEASE as a value >= 199406 but that *doesn't*
           have typedefs for bpf_int32 and bpf_u_int32.

>       Partially.  Using the same definitions for lo0, en0, and en1 that 
> were previously posted, I get:
> 
> # xprobe -v -i lo0 127.0.0.1
> X probe ver. 0.0.2
> ------------------
> Interface: lo0/127.0.0.1

        [success]

> # xprobe -v -i en1 10.0.1.12
> X probe ver. 0.0.2
> ------------------
> ioctl(SIOCGIFADDR): Can't assign requested address

That's not the error that libpcap 0.7.1 generates for a failed
SIOCGIFADDR, so that's presumably an error coming from xprobe itself,
not libpcap.

As such, I don't know why xprobe with no "-i" argument was failing to
find or open en1.

I've attached the test program that the guy who did the
"pcap_findalldevs()" did as a test program; try compiling that, and
linking it with the version of libpcap 0.7.1 you built, and run it as
root, and see what it reports.

>       Hmm.  Maybe my failures were a result of a DHCP license that was 
> in the process of being dropped and renewed?  Things seem to have 
> worked okay afterwards.

Could be - but that shouldn't have caused pcap_open_live() to fail, just
caused "pcap_lookupnet()", or something inside xprobe itself, to fail.
#include "pcap.h"
#include <sys/socket.h>
#include <netinet/in.h>

void ifprint(pcap_if_t *d);
char *iptos(u_long in);

int main()
{
  pcap_if_t *alldevs;
  pcap_if_t *d;
  char *s;
  bpf_u_int32 net, mask;
  
  char errbuf[PCAP_ERRBUF_SIZE+1];
  if (pcap_findalldevs(&alldevs, errbuf) == -1)
  {
    fprintf(stderr,"Error in pcap_findalldevs: %s\n",errbuf);
    exit(1);
  }
  for(d=alldevs;d;d=d->next)
  {
    ifprint(d);
  }

  if ( (s = pcap_lookupdev(errbuf)) == NULL)
  {
    fprintf(stderr,"Error in pcap_lookupdev: %s\n",errbuf);
  }
  else
  {
    printf("Preferred device name: %s\n",s);
  }

  if (pcap_lookupnet(s, &net, &mask, errbuf) < 0)
  {
    fprintf(stderr,"Error in pcap_lookupnet: %s\n",errbuf);
  }
  else
  {
    printf("Preferred device is on network: %s/%s\n",iptos(net), iptos(mask));
  }
  
  exit(0);
}

void ifprint(pcap_if_t *d)
{
  pcap_addr_t *a;
  printf("%s\n",d->name);
  if (d->description)
    printf("\tDescription: %s\n",d->description);
  printf("\tLoopback: %s\n",(d->flags & PCAP_IF_LOOPBACK)?"yes":"no");

  for(a=d->addresses;a;a=a->next) {
    printf("\tAddress Family: #%d\n",a->addr->sa_family);
  
    switch(a->addr->sa_family)
    {
      case AF_INET:
        printf("\tAddress Family Name: AF_INET\n");
        if (a->addr)
          printf("\tAddress: %s\n",iptos(((struct sockaddr_in 
*)a->addr)->sin_addr.s_addr));
        if (a->netmask)
          printf("\tNetmask: %s\n",iptos(((struct sockaddr_in 
*)a->netmask)->sin_addr.s_addr));
        if (a->broadaddr)
          printf("\tBroadcast Address: %s\n",iptos(((struct sockaddr_in 
*)a->broadaddr)->sin_addr.s_addr));
        if (a->dstaddr)
          printf("\tDestination Address: %s\n",iptos(((struct sockaddr_in 
*)a->dstaddr)->sin_addr.s_addr));
        break;
      default:
        printf("\tAddress Family Name: Unknown\n");
        break;
    }
  }
  printf("\n");
}

/* From tcptraceroute */
#define IPTOSBUFFERS    12
char *iptos(u_long in)
{
        static char output[IPTOSBUFFERS][3*4+3+1];
        static short which;
        u_char *p;

        p = (u_char *)&in;
        which = (which + 1 == IPTOSBUFFERS ? 0 : which + 1);
        sprintf(output[which], "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
        return output[which];
}

Reply via email to