From: guy Date: Thu, 18 Jan 2001 03:58:22 +0000 (+0000) Subject: Some platforms that lack define PF_PACKET but don't X-Git-Tag: libpcap-0.7.1~103 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/952a563412910b1846ad53c40b56a9cc1dc29045 Some platforms that lack define PF_PACKET but don't support PF_PACKET sockets, and, in particular, don't define in any of the stuff needed by the code to handle PF_PACKET sockets. Define HAVE_PF_PACKET_SOCKETS if either 1) we have or 2) PF_PACKET is defined *and* PACKET_HOST is defined by and use HAVE_PF_PACKET_SOCKETS, not PF_PACKET, be what we use in #ifdefs to conditionally compile in support for PF_PACKET sockets. Not all platforms define ARPHRD_SIT, either; #define it if it's not already defined. --- diff --git a/pcap-linux.c b/pcap-linux.c index ec07ef5a..ff0eef69 100644 --- a/pcap-linux.c +++ b/pcap-linux.c @@ -26,7 +26,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.53 2001-01-17 07:42:37 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.54 2001-01-18 03:58:22 guy Exp $ (LBL)"; #endif /* @@ -76,6 +76,11 @@ static const char rcsid[] = #ifdef HAVE_NETPACKET_PACKET_H # include + + /* + * We assume this means we really do have PF_PACKET sockets. + */ +# define HAVE_PF_PACKET_SOCKETS #else /* * Oh, joy. Some Linux distributions have 2.2 or later kernels and @@ -95,6 +100,20 @@ static const char rcsid[] = */ # ifdef PF_PACKET # include + + /* + * However, on at least some Linux distributions (for example, Red Hat + * 5.2), there's no file, but PF_PACKET is defined + * if you include , but doesn't define + * any of the PF_PACKET stuff such as "struct sockaddr_ll" or any of + * the PACKET_xxx stuff. + * + * So we check whether PACKET_HOST is defined, and assume that we have + * PF_PACKET sockets only if it is defined. + */ +# ifdef PACKET_HOST +# define HAVE_PF_PACKET_SOCKETS +# endif /* PACKET_HOST */ # endif /* PF_PACKET */ #endif /* HAVE_NETPACKET_PACKET_H */ @@ -131,12 +150,12 @@ static int pcap_read_packet(pcap_t *, pcap_handler, u_char *); /* * Wrap some ioctl calls */ -#ifdef PF_PACKET +#ifdef HAVE_PF_PACKET_SOCKETS static int iface_get_id(int fd, const char *device, char *ebuf); #endif static int iface_get_mtu(int fd, const char *device, char *ebuf); static int iface_get_arptype(int fd, const char *device, char *ebuf); -#ifdef PF_PACKET +#ifdef HAVE_PF_PACKET_SOCKETS static int iface_bind(int fd, int ifindex, char *ebuf); #endif static int iface_bind_old(int fd, const char *device, char *ebuf); @@ -242,7 +261,7 @@ static int pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata) { int offset; -#ifdef PF_PACKET +#ifdef HAVE_PF_PACKET_SOCKETS struct sockaddr_ll from; struct sll_header *hdrp; #else @@ -252,7 +271,7 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata) int packet_len, caplen; struct pcap_pkthdr pcap_header; -#ifdef PF_PACKET +#ifdef HAVE_PF_PACKET_SOCKETS /* * If this is a cooked device, leave extra room for a * fake packet header. @@ -291,7 +310,7 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata) } } -#ifdef PF_PACKET +#ifdef HAVE_PF_PACKET_SOCKETS /* * If this is from the loopback device, reject outgoing packets; * we'll see the packet as an incoming packet as well, and @@ -307,7 +326,7 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata) return 0; #endif -#ifdef PF_PACKET +#ifdef HAVE_PF_PACKET_SOCKETS /* * If this is a cooked device, fill in the fake packet header. */ @@ -606,6 +625,9 @@ static int map_arphrd_to_dlt(int arptype) /* Not sure if this is correct for all tunnels, but it * works for CIPE */ case ARPHRD_TUNNEL: +#ifndef ARPHRD_SIT +#define ARPHRD_SIT 776 /* From Linux 2.2.14 */ +#endif case ARPHRD_SIT: case ARPHRD_CSLIP: case ARPHRD_SLIP6: @@ -627,7 +649,7 @@ static int live_open_new(pcap_t *handle, char *device, int promisc, int to_ms, char *ebuf) { -#ifdef PF_PACKET +#ifdef HAVE_PF_PACKET_SOCKETS int sock_fd = -1, device_id, mtu, arptype; struct packet_mreq mr; @@ -814,7 +836,7 @@ live_open_new(pcap_t *handle, char *device, int promisc, #endif } -#ifdef PF_PACKET +#ifdef HAVE_PF_PACKET_SOCKETS /* * Return the index of the given device name. Fill ebuf and return * -1 on failure. @@ -1217,7 +1239,7 @@ iface_get_arptype(int fd, const char *device, char *ebuf) return ifr.ifr_hwaddr.sa_family; } -#ifdef PF_PACKET +#ifdef HAVE_PF_PACKET_SOCKETS static int fix_program(pcap_t *handle, struct sock_fprog *fcode) {