[Winpcap-users] Trying a example

Gianluca Varenni gianluca.varenni at cacetech.com
Wed Nov 28 17:40:28 GMT 2007


I suggest you to take out of the samples from the winpcap developer's pack.

You are using pcap_lookupdev, which is obsolete (and on Windows it doesn't have the same semantics of pcap_lookupdev undex Unix).

Please use pcap_findalldevs to get the list of adapters.

Have a nice day
GV

  ----- Original Message ----- 
  From: Ziara . 
  To: winpcap 
  Sent: Tuesday, November 27, 2007 1:49 PM
  Subject: [Winpcap-users] Trying a example


  Hi! I'm trying other example in Builder c++, someone can tell me why this code doesn't work? what is it wrong?
   
  int main(int argc, char **argv)
  {
  char *net; // direccion de red
  char *mask; // mascara de subred
  char *dev; // nombre del dispositivo de red
  int ret; // codigo de retorno
  char errbuf[PCAP_ERRBUF_SIZE]; // buffer para mensajes de error
  bpf_u_int32 netp; // direcion de red en modo raw
  bpf_u_int32 maskp; // mascara de red en modo raw
  struct in_addr addr;
  if ((dev = pcap_lookupdev(errbuf))== NULL) //conseguimos la primera interfaz libre
  {
          printf("ERROR %s\n",errbuf);
          exit(-1);
  }
  printf("Nombre del dispositivo: %s\n",dev); //mostramos el nombre del dispositivo
  if ((ret = pcap_lookupnet(dev,&netp,&maskp,errbuf))==-1) //consultamos las direccion de red y las mascara
  {
          printf("ERROR %s\n",errbuf);
          exit(-1);
  }
  addr.s_addr = netp; //Traducimos la direccion de red a algo legible
  if ((net = inet_ntoa(addr))==NULL)
  {
          perror("inet_ntoa");
          exit(-1);
  }
  printf("Direccion de Red: %s\n",net);
  addr.s_addr = maskp; //Idem para la mascara de subred
  mask = inet_ntoa(addr);
  if ((net=inet_ntoa(addr))==NULL)
  {
          perror("inet_ntoa");
          exit(-1);
  }
  printf("Mascara de Red: %s\n",mask);
  return 0;
  }
   
  when and build and run the .exe, only appear:
   
  Nombre del dispostivo: /
  Direccion de Red: 0.0.0.0
  Mascara de Red: 0.0.0.0
   
  thanks


------------------------------------------------------------------------------
  Tecnología, moda, motor, viajes,…suscríbete a nuestros boletines para estar a la última MSN Newsletters 


------------------------------------------------------------------------------


  _______________________________________________
  Winpcap-users mailing list
  Winpcap-users at winpcap.org
  https://www.winpcap.org/mailman/listinfo/winpcap-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.winpcap.org/pipermail/winpcap-users/attachments/20071128/2417042b/attachment.htm


More information about the Winpcap-users mailing list