Deleted Added
sdiff udiff text old ( 147894 ) new ( 172677 )
full compact
1/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
2/*
3 * Copyright (c) 1994, 1995, 1996, 1997, 1998
4 * The Regents of the University of California. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 20 unchanged lines hidden (view full) ---

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
32 * SUCH DAMAGE.
33 */
34
35#ifndef lint
36static const char rcsid[] _U_ =
37 "@(#) $Header: /tcpdump/master/libpcap/inet.c,v 1.66.2.1 2005/06/20 21:30:17 guy Exp $ (LBL)";
38#endif
39
40#ifdef HAVE_CONFIG_H
41#include "config.h"
42#endif
43
44#ifdef WIN32
45#include <pcap-stdinc.h>

--- 84 unchanged lines hidden (view full) ---

130add_or_find_if(pcap_if_t **curdev_ret, pcap_if_t **alldevs, const char *name,
131 u_int flags, const char *description, char *errbuf)
132{
133 pcap_t *p;
134 pcap_if_t *curdev, *prevdev, *nextdev;
135 int this_instance;
136
137 /*
138 * Can we open this interface for live capture?
139 *
140 * We do this check so that interfaces that ae supplied
141 * by the interface enumeration mechanism we're using
142 * but that don't support packet capture aren't included
143 * in the list. An example of this is loopback interfaces
144 * on Solaris; we don't just omit loopback interfaces
145 * becaue you *can* capture on loopback interfaces on some
146 * OSes.
147 */
148 p = pcap_open_live(name, 68, 0, 0, errbuf);
149 if (p == NULL) {
150 /*
151 * No. Don't bother including it.
152 * Don't treat this as an error, though.
153 */
154 *curdev_ret = NULL;
155 return (0);
156 }
157 pcap_close(p);
158
159 /*
160 * Is there already an entry in the list for this interface?
161 */
162 for (curdev = *alldevs; curdev != NULL; curdev = curdev->next) {
163 if (strcmp(name, curdev->name) == 0)
164 break; /* yes, we found it */
165 }
166 if (curdev == NULL) {
167 /*
168 * No, we didn't find it.
169 * Allocate a new entry.
170 */
171 curdev = malloc(sizeof(pcap_if_t));
172 if (curdev == NULL) {
173 (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
174 "malloc: %s", pcap_strerror(errno));
175 return (-1);
176 }
177
178 /*
179 * Fill in the entry.
180 */
181 curdev->next = NULL;
182 curdev->name = malloc(strlen(name) + 1);
183 strcpy(curdev->name, name);
184 if (description != NULL) {
185 /*
186 * We have a description for this interface.
187 */
188 curdev->description = malloc(strlen(description) + 1);
189 strcpy(curdev->description, description);
190 } else {
191 /*
192 * We don't.
193 */
194 curdev->description = NULL;
195 }
196 curdev->addresses = NULL; /* list starts out as empty */
197 curdev->flags = 0;

--- 154 unchanged lines hidden (view full) ---

352 } else
353 curaddr->addr = NULL;
354
355 if (netmask != NULL) {
356 curaddr->netmask = dup_sockaddr(netmask, netmask_size);
357 if (curaddr->netmask == NULL) {
358 (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
359 "malloc: %s", pcap_strerror(errno));
360 free(curaddr);
361 return (-1);
362 }
363 } else
364 curaddr->netmask = NULL;
365
366 if (broadaddr != NULL) {
367 curaddr->broadaddr = dup_sockaddr(broadaddr, broadaddr_size);
368 if (curaddr->broadaddr == NULL) {
369 (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
370 "malloc: %s", pcap_strerror(errno));
371 free(curaddr);
372 return (-1);
373 }
374 } else
375 curaddr->broadaddr = NULL;
376
377 if (dstaddr != NULL) {
378 curaddr->dstaddr = dup_sockaddr(dstaddr, dstaddr_size);
379 if (curaddr->dstaddr == NULL) {
380 (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
381 "malloc: %s", pcap_strerror(errno));
382 free(curaddr);
383 return (-1);
384 }
385 } else
386 curaddr->dstaddr = NULL;
387
388 /*
389 * Find the end of the list of addresses.

--- 132 unchanged lines hidden (view full) ---

522
523int
524pcap_lookupnet(device, netp, maskp, errbuf)
525 register const char *device;
526 register bpf_u_int32 *netp, *maskp;
527 register char *errbuf;
528{
529 register int fd;
530 register struct sockaddr_in *sin;
531 struct ifreq ifr;
532
533 /*
534 * The pseudo-device "any" listens on all interfaces and therefore
535 * has the network address and -mask "0.0.0.0" therefore catching
536 * all traffic. Using NULL for the interface is the same as "any".
537 */
538 if (!device || strcmp(device, "any") == 0

--- 27 unchanged lines hidden (view full) ---

566 } else {
567 (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
568 "SIOCGIFADDR: %s: %s",
569 device, pcap_strerror(errno));
570 }
571 (void)close(fd);
572 return (-1);
573 }
574 sin = (struct sockaddr_in *)&ifr.ifr_addr;
575 *netp = sin->sin_addr.s_addr;
576 if (ioctl(fd, SIOCGIFNETMASK, (char *)&ifr) < 0) {
577 (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
578 "SIOCGIFNETMASK: %s: %s", device, pcap_strerror(errno));
579 (void)close(fd);
580 return (-1);
581 }
582 (void)close(fd);
583 *maskp = sin->sin_addr.s_addr;
584 if (*maskp == 0) {
585 if (IN_CLASSA(*netp))
586 *maskp = IN_CLASSA_NET;
587 else if (IN_CLASSB(*netp))
588 *maskp = IN_CLASSB_NET;
589 else if (IN_CLASSC(*netp))
590 *maskp = IN_CLASSC_NET;
591 else {

--- 136 unchanged lines hidden ---