1 /* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
3 * Copyright (c) 1994, 1995, 1996, 1997, 1998
4 * The Regents of the University of California. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the Computer Systems
17 * Engineering Group at Lawrence Berkeley Laboratory.
18 * 4. Neither the name of the University nor of the Laboratory may be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 #include <pcap-stdinc.h>
43 #include <sys/param.h>
47 #include <sys/ioctl.h>
48 #include <sys/socket.h>
49 #ifdef HAVE_SYS_SOCKIO_H
50 #include <sys/sockio.h>
53 struct mbuf
; /* Squelch compiler warnings on some platforms for */
54 struct rtentry
; /* declarations in <net/if.h> */
56 #include <netinet/in.h>
65 #if !defined(WIN32) && !defined(__BORLANDC__)
67 #endif /* !WIN32 && !__BORLANDC__ */
71 #define INT_MAX 2147483647
76 #ifdef HAVE_OS_PROTO_H
80 /* Not all systems have IFF_LOOPBACK */
82 #define ISLOOPBACK(name, flags) ((flags) & IFF_LOOPBACK)
84 #define ISLOOPBACK(name, flags) ((name)[0] == 'l' && (name)[1] == 'o' && \
85 (isdigit((unsigned char)((name)[2])) || (name)[2] == '\0'))
89 #define ISUP(flags) ((flags) & IFF_UP)
95 #define ISRUNNING(flags) ((flags) & IFF_RUNNING)
97 #define ISRUNNING(flags) 0
101 dup_sockaddr(struct sockaddr
*sa
, size_t sa_length
)
103 struct sockaddr
*newsa
;
105 if ((newsa
= malloc(sa_length
)) == NULL
)
107 return (memcpy(newsa
, sa
, sa_length
));
111 get_instance(const char *name
)
113 const char *cp
, *endcp
;
116 if (strcmp(name
, "any") == 0) {
118 * Give the "any" device an artificially high instance
119 * number, so it shows up after all other non-loopback
125 endcp
= name
+ strlen(name
);
126 for (cp
= name
; cp
< endcp
&& !isdigit((unsigned char)*cp
); ++cp
)
129 if (isdigit((unsigned char)*cp
))
137 add_or_find_if(pcap_if_t
**curdev_ret
, pcap_if_t
**alldevs
, const char *name
,
138 u_int flags
, const char *description
, char *errbuf
)
141 pcap_if_t
*curdev
, *prevdev
, *nextdev
;
143 char open_errbuf
[PCAP_ERRBUF_SIZE
];
146 * Is there already an entry in the list for this interface?
148 for (curdev
= *alldevs
; curdev
!= NULL
; curdev
= curdev
->next
) {
149 if (strcmp(name
, curdev
->name
) == 0)
150 break; /* yes, we found it */
153 if (curdev
== NULL
) {
155 * No, we didn't find it.
157 * Can we open this interface for live capture?
159 * We do this check so that interfaces that are
160 * supplied by the interface enumeration mechanism
161 * we're using but that don't support packet capture
162 * aren't included in the list. Loopback interfaces
163 * on Solaris are an example of this; we don't just
164 * omit loopback interfaces on all platforms because
165 * you *can* capture on loopback interfaces on some
168 * On OS X, we don't do this check if the device
169 * name begins with "wlt"; at least some versions
170 * of OS X offer monitor mode capturing by having
171 * a separate "monitor mode" device for each wireless
172 * adapter, rather than by implementing the ioctls
173 * that {Free,Net,Open,DragonFly}BSD provide.
174 * Opening that device puts the adapter into monitor
175 * mode, which, at least for some adapters, causes
176 * them to deassociate from the network with which
177 * they're associated.
179 * Instead, we try to open the corresponding "en"
180 * device (so that we don't end up with, for users
181 * without sufficient privilege to open capture
182 * devices, a list of adapters that only includes
186 if (strncmp(name
, "wlt", 3) == 0) {
191 * Try to allocate a buffer for the "en"
194 en_name_len
= strlen(name
) - 1;
195 en_name
= malloc(en_name_len
+ 1);
196 if (en_name
== NULL
) {
197 (void)snprintf(errbuf
, PCAP_ERRBUF_SIZE
,
198 "malloc: %s", pcap_strerror(errno
));
201 strcpy(en_name
, "en");
202 strcat(en_name
, name
+ 3);
203 p
= pcap_open_live(en_name
, 68, 0, 0, open_errbuf
);
207 p
= pcap_open_live(name
, 68, 0, 0, open_errbuf
);
210 * No. Don't bother including it.
211 * Don't treat this as an error, though.
219 * Yes, we can open it.
220 * Allocate a new entry.
222 curdev
= malloc(sizeof(pcap_if_t
));
223 if (curdev
== NULL
) {
224 (void)snprintf(errbuf
, PCAP_ERRBUF_SIZE
,
225 "malloc: %s", pcap_strerror(errno
));
233 curdev
->name
= strdup(name
);
234 if (curdev
->name
== NULL
) {
235 (void)snprintf(errbuf
, PCAP_ERRBUF_SIZE
,
236 "malloc: %s", pcap_strerror(errno
));
240 if (description
!= NULL
) {
242 * We have a description for this interface.
244 curdev
->description
= strdup(description
);
245 if (curdev
->description
== NULL
) {
246 (void)snprintf(errbuf
, PCAP_ERRBUF_SIZE
,
247 "malloc: %s", pcap_strerror(errno
));
256 curdev
->description
= NULL
;
258 curdev
->addresses
= NULL
; /* list starts out as empty */
260 if (ISLOOPBACK(name
, flags
))
261 curdev
->flags
|= PCAP_IF_LOOPBACK
;
263 curdev
->flags
|= PCAP_IF_UP
;
264 if (ISRUNNING(flags
))
265 curdev
->flags
|= PCAP_IF_RUNNING
;
268 * Add it to the list, in the appropriate location.
269 * First, get the instance number of this interface.
271 this_instance
= get_instance(name
);
274 * Now look for the last interface with an instance number
275 * less than or equal to the new interface's instance
276 * number - except that non-loopback interfaces are
277 * arbitrarily treated as having interface numbers less
278 * than those of loopback interfaces, so the loopback
279 * interfaces are put at the end of the list.
281 * We start with "prevdev" being NULL, meaning we're before
282 * the first element in the list.
287 * Get the interface after this one.
289 if (prevdev
== NULL
) {
291 * The next element is the first element.
295 nextdev
= prevdev
->next
;
298 * Are we at the end of the list?
300 if (nextdev
== NULL
) {
302 * Yes - we have to put the new entry
309 * Is the new interface a non-loopback interface
310 * and the next interface a loopback interface?
312 if (!(curdev
->flags
& PCAP_IF_LOOPBACK
) &&
313 (nextdev
->flags
& PCAP_IF_LOOPBACK
)) {
315 * Yes, we should put the new entry
316 * before "nextdev", i.e. after "prevdev".
322 * Is the new interface's instance number less
323 * than the next interface's instance number,
324 * and is it the case that the new interface is a
325 * non-loopback interface or the next interface is
326 * a loopback interface?
328 * (The goal of both loopback tests is to make
329 * sure that we never put a loopback interface
330 * before any non-loopback interface and that we
331 * always put a non-loopback interface before all
332 * loopback interfaces.)
334 if (this_instance
< get_instance(nextdev
->name
) &&
335 (!(curdev
->flags
& PCAP_IF_LOOPBACK
) ||
336 (nextdev
->flags
& PCAP_IF_LOOPBACK
))) {
338 * Yes - we should put the new entry
339 * before "nextdev", i.e. after "prevdev".
348 * Insert before "nextdev".
350 curdev
->next
= nextdev
;
353 * Insert after "prevdev" - unless "prevdev" is null,
354 * in which case this is the first interface.
356 if (prevdev
== NULL
) {
358 * This is the first interface. Pass back a
359 * pointer to it, and put "curdev" before
364 prevdev
->next
= curdev
;
367 *curdev_ret
= curdev
;
372 * XXX - on FreeBSDs that support it, should it get the sysctl named
373 * "dev.{adapter family name}.{adapter unit}.%desc" to get a description
374 * of the adapter? Note that "dev.an.0.%desc" is "Aironet PC4500/PC4800"
375 * with my Cisco 350 card, so the name isn't entirely descriptive. The
376 * "dev.an.0.%pnpinfo" has a better description, although one might argue
377 * that the problem is really a driver bug - if it can find out that it's
378 * a Cisco 340 or 350, rather than an old Aironet card, it should use
379 * that in the description.
381 * Do NetBSD, DragonflyBSD, or OpenBSD support this as well? FreeBSD
382 * and OpenBSD let you get a description, but it's not generated by the OS,
383 * it's set with another ioctl that ifconfig supports; we use that to get
384 * a description in FreeBSD and OpenBSD, but if there is no such
385 * description available, it still might be nice to get some description
386 * string based on the device type or something such as that.
388 * In OS X, the System Configuration framework can apparently return
389 * names in 10.4 and later.
391 * It also appears that freedesktop.org's HAL offers an "info.product"
392 * string, but the HAL specification says it "should not be used in any
393 * UI" and "subsystem/capability specific properties" should be used
394 * instead and, in any case, I think HAL is being deprecated in
395 * favor of other stuff such as DeviceKit. DeviceKit doesn't appear
396 * to have any obvious product information for devices, but maybe
397 * I haven't looked hard enough.
399 * Using the System Configuration framework, or HAL, or DeviceKit, or
400 * whatever, would require that libpcap applications be linked with
401 * the frameworks/libraries in question. That shouldn't be a problem
402 * for programs linking with the shared version of libpcap (unless
403 * you're running on AIX - which I think is the only UN*X that doesn't
404 * support linking a shared library with other libraries on which it
405 * depends, and having an executable linked only with the first shared
406 * library automatically pick up the other libraries when started -
407 * and using HAL or whatever). Programs linked with the static
408 * version of libpcap would have to use pcap-config with the --static
409 * flag in order to get the right linker flags in order to pick up
410 * the additional libraries/frameworks; those programs need that anyway
411 * for libpcap 1.1 and beyond on Linux, as, by default, it requires
414 * Do any other UN*Xes, or desktop environments support getting a
418 add_addr_to_iflist(pcap_if_t
**alldevs
, const char *name
, u_int flags
,
419 struct sockaddr
*addr
, size_t addr_size
,
420 struct sockaddr
*netmask
, size_t netmask_size
,
421 struct sockaddr
*broadaddr
, size_t broadaddr_size
,
422 struct sockaddr
*dstaddr
, size_t dstaddr_size
,
426 char *description
= NULL
;
427 pcap_addr_t
*curaddr
, *prevaddr
, *nextaddr
;
430 struct ifreq ifrdesc
;
432 size_t descrlen
= 64;
434 size_t descrlen
= IFDESCRSIZE
;
435 #endif /* IFDESCRSIZE */
436 #endif /* SIOCGIFDESCR */
440 * Get the description for the interface.
442 memset(&ifrdesc
, 0, sizeof ifrdesc
);
443 strlcpy(ifrdesc
.ifr_name
, name
, sizeof ifrdesc
.ifr_name
);
444 s
= socket(AF_INET
, SOCK_DGRAM
, 0);
448 * On FreeBSD, if the buffer isn't big enough for the
449 * description, the ioctl succeeds, but the description
450 * isn't copied, ifr_buffer.length is set to the description
451 * length, and ifr_buffer.buffer is set to NULL.
455 if ((description
= malloc(descrlen
)) != NULL
) {
456 ifrdesc
.ifr_buffer
.buffer
= description
;
457 ifrdesc
.ifr_buffer
.length
= descrlen
;
458 if (ioctl(s
, SIOCGIFDESCR
, &ifrdesc
) == 0) {
459 if (ifrdesc
.ifr_buffer
.buffer
==
463 descrlen
= ifrdesc
.ifr_buffer
.length
;
466 * Failed to get interface description.
475 #else /* __FreeBSD__ */
477 * The only other OS that currently supports
478 * SIOCGIFDESCR is OpenBSD, and it has no way
479 * to get the description length - it's clamped
480 * to a maximum of IFDESCRSIZE.
482 if ((description
= malloc(descrlen
)) != NULL
) {
483 ifrdesc
.ifr_data
= (caddr_t
)description
;
484 if (ioctl(s
, SIOCGIFDESCR
, &ifrdesc
) != 0) {
486 * Failed to get interface description.
492 #endif /* __FreeBSD__ */
494 if (description
!= NULL
&& strlen(description
) == 0) {
499 #endif /* SIOCGIFDESCR */
501 if (add_or_find_if(&curdev
, alldevs
, name
, flags
, description
,
510 if (curdev
== NULL
) {
512 * Device wasn't added because it can't be opened.
519 * "curdev" is an entry for this interface; add an entry for this
520 * address to its list of addresses.
522 * Allocate the new entry and fill it in.
524 curaddr
= malloc(sizeof(pcap_addr_t
));
525 if (curaddr
== NULL
) {
526 (void)snprintf(errbuf
, PCAP_ERRBUF_SIZE
,
527 "malloc: %s", pcap_strerror(errno
));
531 curaddr
->next
= NULL
;
533 curaddr
->addr
= dup_sockaddr(addr
, addr_size
);
534 if (curaddr
->addr
== NULL
) {
535 (void)snprintf(errbuf
, PCAP_ERRBUF_SIZE
,
536 "malloc: %s", pcap_strerror(errno
));
541 curaddr
->addr
= NULL
;
543 if (netmask
!= NULL
) {
544 curaddr
->netmask
= dup_sockaddr(netmask
, netmask_size
);
545 if (curaddr
->netmask
== NULL
) {
546 (void)snprintf(errbuf
, PCAP_ERRBUF_SIZE
,
547 "malloc: %s", pcap_strerror(errno
));
548 if (curaddr
->addr
!= NULL
)
554 curaddr
->netmask
= NULL
;
556 if (broadaddr
!= NULL
) {
557 curaddr
->broadaddr
= dup_sockaddr(broadaddr
, broadaddr_size
);
558 if (curaddr
->broadaddr
== NULL
) {
559 (void)snprintf(errbuf
, PCAP_ERRBUF_SIZE
,
560 "malloc: %s", pcap_strerror(errno
));
561 if (curaddr
->netmask
!= NULL
)
562 free(curaddr
->netmask
);
563 if (curaddr
->addr
!= NULL
)
569 curaddr
->broadaddr
= NULL
;
571 if (dstaddr
!= NULL
) {
572 curaddr
->dstaddr
= dup_sockaddr(dstaddr
, dstaddr_size
);
573 if (curaddr
->dstaddr
== NULL
) {
574 (void)snprintf(errbuf
, PCAP_ERRBUF_SIZE
,
575 "malloc: %s", pcap_strerror(errno
));
576 if (curaddr
->broadaddr
!= NULL
)
577 free(curaddr
->broadaddr
);
578 if (curaddr
->netmask
!= NULL
)
579 free(curaddr
->netmask
);
580 if (curaddr
->addr
!= NULL
)
586 curaddr
->dstaddr
= NULL
;
589 * Find the end of the list of addresses.
591 for (prevaddr
= curdev
->addresses
; prevaddr
!= NULL
; prevaddr
= nextaddr
) {
592 nextaddr
= prevaddr
->next
;
593 if (nextaddr
== NULL
) {
595 * This is the end of the list.
601 if (prevaddr
== NULL
) {
603 * The list was empty; this is the first member.
605 curdev
->addresses
= curaddr
;
608 * "prevaddr" is the last member of the list; append
611 prevaddr
->next
= curaddr
;
618 pcap_add_if(pcap_if_t
**devlist
, const char *name
, u_int flags
,
619 const char *description
, char *errbuf
)
623 return (add_or_find_if(&curdev
, devlist
, name
, flags
, description
,
629 * Free a list of interfaces.
632 pcap_freealldevs(pcap_if_t
*alldevs
)
634 pcap_if_t
*curdev
, *nextdev
;
635 pcap_addr_t
*curaddr
, *nextaddr
;
637 for (curdev
= alldevs
; curdev
!= NULL
; curdev
= nextdev
) {
638 nextdev
= curdev
->next
;
641 * Free all addresses.
643 for (curaddr
= curdev
->addresses
; curaddr
!= NULL
; curaddr
= nextaddr
) {
644 nextaddr
= curaddr
->next
;
647 if (curaddr
->netmask
)
648 free(curaddr
->netmask
);
649 if (curaddr
->broadaddr
)
650 free(curaddr
->broadaddr
);
651 if (curaddr
->dstaddr
)
652 free(curaddr
->dstaddr
);
657 * Free the name string.
662 * Free the description string, if any.
664 if (curdev
->description
!= NULL
)
665 free(curdev
->description
);
668 * Free the interface.
674 #if !defined(WIN32) && !defined(MSDOS)
677 * Return the name of a network interface attached to the system, or NULL
678 * if none can be found. The interface must be configured up; the
679 * lowest unit number is preferred; loopback is ignored.
682 pcap_lookupdev(errbuf
)
683 register char *errbuf
;
686 /* for old BSD systems, including bsdi3 */
688 #define IF_NAMESIZE IFNAMSIZ
690 static char device
[IF_NAMESIZE
+ 1];
693 if (pcap_findalldevs(&alldevs
, errbuf
) == -1)
696 if (alldevs
== NULL
|| (alldevs
->flags
& PCAP_IF_LOOPBACK
)) {
698 * There are no devices on the list, or the first device
699 * on the list is a loopback device, which means there
700 * are no non-loopback devices on the list. This means
701 * we can't return any device.
703 * XXX - why not return a loopback device? If we can't
704 * capture on it, it won't be on the list, and if it's
705 * on the list, there aren't any non-loopback devices,
706 * so why not just supply it as the default device?
708 (void)strlcpy(errbuf
, "no suitable device found",
713 * Return the name of the first device on the list.
715 (void)strlcpy(device
, alldevs
->name
, sizeof(device
));
719 pcap_freealldevs(alldevs
);
724 pcap_lookupnet(device
, netp
, maskp
, errbuf
)
725 register const char *device
;
726 register bpf_u_int32
*netp
, *maskp
;
727 register char *errbuf
;
730 register struct sockaddr_in
*sin4
;
734 * The pseudo-device "any" listens on all interfaces and therefore
735 * has the network address and -mask "0.0.0.0" therefore catching
736 * all traffic. Using NULL for the interface is the same as "any".
738 if (!device
|| strcmp(device
, "any") == 0
740 || strstr(device
, "dag") != NULL
742 #ifdef HAVE_SEPTEL_API
743 || strstr(device
, "septel") != NULL
745 #ifdef PCAP_SUPPORT_BT
746 || strstr(device
, "bluetooth") != NULL
748 #ifdef PCAP_SUPPORT_USB
749 || strstr(device
, "usbmon") != NULL
752 || strstr(device
, "snf") != NULL
759 fd
= socket(AF_INET
, SOCK_DGRAM
, 0);
761 (void)snprintf(errbuf
, PCAP_ERRBUF_SIZE
, "socket: %s",
762 pcap_strerror(errno
));
765 memset(&ifr
, 0, sizeof(ifr
));
767 /* XXX Work around Linux kernel bug */
768 ifr
.ifr_addr
.sa_family
= AF_INET
;
770 (void)strncpy(ifr
.ifr_name
, device
, sizeof(ifr
.ifr_name
));
771 if (ioctl(fd
, SIOCGIFADDR
, (char *)&ifr
) < 0) {
772 if (errno
== EADDRNOTAVAIL
) {
773 (void)snprintf(errbuf
, PCAP_ERRBUF_SIZE
,
774 "%s: no IPv4 address assigned", device
);
776 (void)snprintf(errbuf
, PCAP_ERRBUF_SIZE
,
777 "SIOCGIFADDR: %s: %s",
778 device
, pcap_strerror(errno
));
783 sin4
= (struct sockaddr_in
*)&ifr
.ifr_addr
;
784 *netp
= sin4
->sin_addr
.s_addr
;
785 memset(&ifr
, 0, sizeof(ifr
));
787 /* XXX Work around Linux kernel bug */
788 ifr
.ifr_addr
.sa_family
= AF_INET
;
790 (void)strncpy(ifr
.ifr_name
, device
, sizeof(ifr
.ifr_name
));
791 if (ioctl(fd
, SIOCGIFNETMASK
, (char *)&ifr
) < 0) {
792 (void)snprintf(errbuf
, PCAP_ERRBUF_SIZE
,
793 "SIOCGIFNETMASK: %s: %s", device
, pcap_strerror(errno
));
798 *maskp
= sin4
->sin_addr
.s_addr
;
800 if (IN_CLASSA(*netp
))
801 *maskp
= IN_CLASSA_NET
;
802 else if (IN_CLASSB(*netp
))
803 *maskp
= IN_CLASSB_NET
;
804 else if (IN_CLASSC(*netp
))
805 *maskp
= IN_CLASSC_NET
;
807 (void)snprintf(errbuf
, PCAP_ERRBUF_SIZE
,
808 "inet class for 0x%x unknown", *netp
);
819 * Return the name of a network interface attached to the system, or NULL
820 * if none can be found. The interface must be configured up; the
821 * lowest unit number is preferred; loopback is ignored.
824 pcap_lookupdev(errbuf
)
825 register char *errbuf
;
828 DWORD dwWindowsMajorVersion
;
829 dwVersion
= GetVersion(); /* get the OS version */
830 dwWindowsMajorVersion
= (DWORD
)(LOBYTE(LOWORD(dwVersion
)));
832 if (dwVersion
>= 0x80000000 && dwWindowsMajorVersion
>= 4) {
834 * Windows 95, 98, ME.
836 ULONG NameLength
= 8192;
837 static char AdaptersName
[8192];
839 if (PacketGetAdapterNames(AdaptersName
,&NameLength
) )
840 return (AdaptersName
);
845 * Windows NT (NT 4.0, W2K, WXP). Convert the names to UNICODE for backward compatibility
847 ULONG NameLength
= 8192;
848 static WCHAR AdaptersName
[8192];
851 WCHAR
*TAdaptersName
= (WCHAR
*)malloc(8192 * sizeof(WCHAR
));
854 if(TAdaptersName
== NULL
)
856 (void)snprintf(errbuf
, PCAP_ERRBUF_SIZE
, "memory allocation failure");
860 if ( !PacketGetAdapterNames((PTSTR
)TAdaptersName
,&NameLength
) )
862 (void)snprintf(errbuf
, PCAP_ERRBUF_SIZE
,
863 "PacketGetAdapterNames: %s",
864 pcap_win32strerror());
870 tAstr
= (char*)TAdaptersName
;
871 tUstr
= (WCHAR
*)AdaptersName
;
874 * Convert and copy the device names
876 while(sscanf(tAstr
, "%S", tUstr
) > 0)
878 tAstr
+= strlen(tAstr
) + 1;
879 tUstr
+= wcslen(tUstr
) + 1;
888 * Copy the descriptions
892 char* tmp
= (char*)tUstr
;
894 tmp
+= strlen(tAstr
) + 1;
896 tAstr
+= strlen(tAstr
) + 1;
900 return (char *)(AdaptersName
);
906 pcap_lookupnet(device
, netp
, maskp
, errbuf
)
907 register const char *device
;
908 register bpf_u_int32
*netp
, *maskp
;
909 register char *errbuf
;
912 * We need only the first IPv4 address, so we must scan the array returned by PacketGetNetInfo()
913 * in order to skip non IPv4 (i.e. IPv6 addresses)
915 npf_if_addr if_addrs
[MAX_NETWORK_ADDRESSES
];
916 LONG if_addr_size
= 1;
917 struct sockaddr_in
*t_addr
;
920 if (!PacketGetNetInfoEx((void *)device
, if_addrs
, &if_addr_size
)) {
925 for(i
=0; i
<MAX_NETWORK_ADDRESSES
; i
++)
927 if(if_addrs
[i
].IPAddress
.ss_family
== AF_INET
)
929 t_addr
= (struct sockaddr_in
*) &(if_addrs
[i
].IPAddress
);
930 *netp
= t_addr
->sin_addr
.S_un
.S_addr
;
931 t_addr
= (struct sockaddr_in
*) &(if_addrs
[i
].SubnetMask
);
932 *maskp
= t_addr
->sin_addr
.S_un
.S_addr
;
944 #endif /* !WIN32 && !MSDOS */