pcap-bpf.c (167035) | pcap-bpf.c (172680) |
---|---|
1/* 2 * Copyright (c) 1993, 1994, 1995, 1996, 1998 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and --- 4 unchanged lines hidden (view full) --- 13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 * the University nor the names of its contributors may be used to endorse 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * | 1/* 2 * Copyright (c) 1993, 1994, 1995, 1996, 1998 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and --- 4 unchanged lines hidden (view full) --- 13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 * the University nor the names of its contributors may be used to endorse 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * |
21 * $FreeBSD: head/contrib/libpcap/pcap-bpf.c 167035 2007-02-26 22:24:14Z jkim $ | 21 * $FreeBSD: head/contrib/libpcap/pcap-bpf.c 172680 2007-10-16 02:07:55Z mlaier $ |
22 */ 23#ifndef lint 24static const char rcsid[] _U_ = | 22 */ 23#ifndef lint 24static const char rcsid[] _U_ = |
25 "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.86.2.8 2005/07/10 10:55:31 guy Exp $ (LBL)"; | 25 "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.86.2.12 2007/06/15 17:57:27 guy Exp $ (LBL)"; |
26#endif 27 28#ifdef HAVE_CONFIG_H 29#include "config.h" 30#endif 31 32#include <sys/param.h> /* optionally get BSD define */ 33#include <sys/time.h> --- 486 unchanged lines hidden (view full) --- 520 return (0); 521} 522#endif 523 524static inline int 525bpf_open(pcap_t *p, char *errbuf) 526{ 527 int fd; | 26#endif 27 28#ifdef HAVE_CONFIG_H 29#include "config.h" 30#endif 31 32#include <sys/param.h> /* optionally get BSD define */ 33#include <sys/time.h> --- 486 unchanged lines hidden (view full) --- 520 return (0); 521} 522#endif 523 524static inline int 525bpf_open(pcap_t *p, char *errbuf) 526{ 527 int fd; |
528#ifdef HAVE_CLONING_BPF 529 static const char device[] = "/dev/bpf"; 530#else |
|
528 int n = 0; 529 char device[sizeof "/dev/bpf0000000000"]; | 531 int n = 0; 532 char device[sizeof "/dev/bpf0000000000"]; |
533#endif |
|
530 531#ifdef _AIX 532 /* 533 * Load the bpf driver, if it isn't already loaded, 534 * and create the BPF device entries, if they don't 535 * already exist. 536 */ 537 if (bpf_load(errbuf) == -1) 538 return (-1); 539#endif 540 | 534 535#ifdef _AIX 536 /* 537 * Load the bpf driver, if it isn't already loaded, 538 * and create the BPF device entries, if they don't 539 * already exist. 540 */ 541 if (bpf_load(errbuf) == -1) 542 return (-1); 543#endif 544 |
545#ifdef HAVE_CLONING_BPF 546 if ((fd = open(device, O_RDWR)) == -1 && 547 (errno != EACCES || (fd = open(device, O_RDONLY)) == -1)) 548 snprintf(errbuf, PCAP_ERRBUF_SIZE, 549 "(cannot open device) %s: %s", device, pcap_strerror(errno)); 550#else |
|
541 /* 542 * Go through all the minors and find one that isn't in use. 543 */ 544 do { 545 (void)snprintf(device, sizeof(device), "/dev/bpf%d", n++); 546 /* 547 * Initially try a read/write open (to allow the inject 548 * method to work). If that fails due to permission --- 14 unchanged lines hidden (view full) --- 563 } while (fd < 0 && errno == EBUSY); 564 565 /* 566 * XXX better message for all minors used 567 */ 568 if (fd < 0) 569 snprintf(errbuf, PCAP_ERRBUF_SIZE, "(no devices found) %s: %s", 570 device, pcap_strerror(errno)); | 551 /* 552 * Go through all the minors and find one that isn't in use. 553 */ 554 do { 555 (void)snprintf(device, sizeof(device), "/dev/bpf%d", n++); 556 /* 557 * Initially try a read/write open (to allow the inject 558 * method to work). If that fails due to permission --- 14 unchanged lines hidden (view full) --- 573 } while (fd < 0 && errno == EBUSY); 574 575 /* 576 * XXX better message for all minors used 577 */ 578 if (fd < 0) 579 snprintf(errbuf, PCAP_ERRBUF_SIZE, "(no devices found) %s: %s", 580 device, pcap_strerror(errno)); |
581#endif |
|
571 572 return (fd); 573} 574 575/* 576 * We include the OS's <net/bpf.h>, not our "pcap-bpf.h", so we probably 577 * don't get DLT_DOCSIS defined. 578 */ --- 571 unchanged lines hidden --- | 582 583 return (fd); 584} 585 586/* 587 * We include the OS's <net/bpf.h>, not our "pcap-bpf.h", so we probably 588 * don't get DLT_DOCSIS defined. 589 */ --- 571 unchanged lines hidden --- |