See:
https://web.archive.org/web/
20231206084513/http://www.faqs.org/docs/Linux-HOWTO/GCC-HOWTO.html#INDEX.25
"Use __linux__ for this purpose, not linux. Although the latter is
defined, it is not POSIX compliant."
In fact, linux is not always defined:
TinyCC does not define linux, but __linux__.
* we end up including both the OS's <net/bpf.h> and our <pcap/bpf.h>,
* and their definitions of some data structures collide.
*/
-#if (defined(linux) || defined(__Lynx__)) && defined(AF_PACKET)
+#if (defined(__linux__) || defined(__Lynx__)) && defined(AF_PACKET)
# ifdef HAVE_NETPACKET_PACKET_H
/* Linux distributions with newer glibc */
# include <netpacket/packet.h>
# include <linux/if_packet.h>
# endif /* __Lynx__ */
# endif /* HAVE_NETPACKET_PACKET_H */
-#endif /* (defined(linux) || defined(__Lynx__)) && defined(AF_PACKET) */
+#endif /* (defined(__linux__) || defined(__Lynx__)) && defined(AF_PACKET) */
/*
* This is fun.
return (sizeof (struct sockaddr_in6));
#endif
-#if (defined(linux) || defined(__Lynx__)) && defined(AF_PACKET)
+#if (defined(__linux__) || defined(__Lynx__)) && defined(AF_PACKET)
case AF_PACKET:
return (sizeof (struct sockaddr_ll));
#endif
#include "scanner.h"
-#if defined(linux)
+#if defined(__linux__)
#include <linux/types.h>
#include <linux/if_packet.h>
#include <linux/filter.h>
b0 = gen_cmp(cstate, OR_LINKHDR, 4, BPF_W, ifindex);
break;
default:
-#if defined(linux)
+#if defined(__linux__)
/*
* This is Linux; we require PF_PACKET support.
* If this is a *live* capture, we can look at
/* match ifindex */
b0 = gen_cmp(cstate, OR_LINKHDR, SKF_AD_OFF + SKF_AD_IFINDEX, BPF_W,
ifindex);
-#else /* defined(linux) */
+#else /* defined(__linux__) */
bpf_error(cstate, "ifindex not supported on %s",
pcap_datalink_val_to_description_or_dlt(cstate->linktype));
/*NOTREACHED*/
-#endif /* defined(linux) */
+#endif /* defined(__linux__) */
}
return (b0);
}
* with newer capture APIs, allowing it to be saved
* in pcapng files.
*/
-#if defined(linux)
+#if defined(__linux__)
/*
* This is Linux; we require PF_PACKET support.
* If this is a *live* capture, we can look at
/* to filter on inbound traffic, invert the match */
gen_not(b0);
}
-#else /* defined(linux) */
+#else /* defined(__linux__) */
bpf_error(cstate, "inbound/outbound not supported on %s",
pcap_datalink_val_to_description_or_dlt(cstate->linktype));
/*NOTREACHED*/
-#endif /* defined(linux) */
+#endif /* defined(__linux__) */
}
return (b0);
}
struct ifreq ifr;
int error, fd = d->fd;
-#ifdef linux
+#ifdef __linux__
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
fprintf(stderr, "Error: cannot get device control socket.\n");
return -1;
}
-#endif /* linux */
+#endif /* __linux__ */
bzero(&ifr, sizeof(ifr));
strncpy(ifr.ifr_name, d->req.nr_name, sizeof(ifr.ifr_name));
switch (what) {
#endif /* __FreeBSD__ */
}
}
-#ifdef linux
+#ifdef __linux__
close(fd);
-#endif /* linux */
+#endif /* __linux__ */
return error ? -1 : 0;
}
return (-1);
}
memset(&ifr, 0, sizeof(ifr));
-#ifdef linux
+#ifdef __linux__
/* XXX Work around Linux kernel bug */
ifr.ifr_addr.sa_family = AF_INET;
#endif
sin4 = (struct sockaddr_in *)&ifr.ifr_addr;
*netp = sin4->sin_addr.s_addr;
memset(&ifr, 0, sizeof(ifr));
-#ifdef linux
+#ifdef __linux__
/* XXX Work around Linux kernel bug */
ifr.ifr_addr.sa_family = AF_INET;
#endif
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(_AIX) || defined(sun)
/* OS with BPF - use BPF */
#define USE_BPF
-#elif defined(linux)
+#elif defined(__linux__)
/* Linux - use socket filters */
#define USE_SOCKET_FILTERS
#else