[Winpcap-users] Trying a example

john mcnicholas jomcn1 at gmail.com
Wed Nov 28 20:52:38 GMT 2007


Ziara,

Couple of points/suggs:

- I'd follow GV's advice and look at the samples

- I believe the obsolete api you used returned a unicode string ; i.e. every
other byte was 0
  hence, the single character for the name.  Plus there is a good chance it
might return
  "Generic Dialup Adapter" which wouldn't have been much use;
   In short, pcap_findalldevs is a better way to go.

- Note: you were also  using a WinSock api and although it wasn't necessary
for this
  app/api, it is probably a good idea to initialize WinSock via WSAStartup()
and WSACleanup.

good luck.

John

On Nov 28, 2007 12:40 PM, Gianluca Varenni <gianluca.varenni at cacetech.com>
wrote:

>  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 . <essence_z at hotmail.com>
> *To:* winpcap <winpcap-users at winpcap.org>
> *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<http://newsletters.msn.com/hm/maintenanceeses.asp?L=ES&C=ES&P=WCMaintenance&Brand=WL&RU=http%3a%2f%2fmail.live.com>
>
> ------------------------------
>
> _______________________________________________
> Winpcap-users mailing list
> Winpcap-users at winpcap.org
> https://www.winpcap.org/mailman/listinfo/winpcap-users
>
>
> _______________________________________________
> 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/440f7000/attachment-0001.htm


More information about the Winpcap-users mailing list