reduce namespace pollution in netinet/udp.h
authorRich Felker <dalias@aerifal.cx>
Wed, 5 Feb 2014 22:25:39 +0000 (17:25 -0500)
committerRich Felker <dalias@aerifal.cx>
Wed, 5 Feb 2014 22:25:39 +0000 (17:25 -0500)
the affected part of the header is responsible for providing both GNU
and BSD versions of the udphdr structure. previously, the
namespace-polluting GNU names were always used for the actual struct
members, and the BSD names, which are named in a manner resembling a
sane namespace, were always macros defined to expand to the GNU names.
now, unless _GNU_SOURCE is defined, the BSD names are used as the
actual structure members, and the macros and GNU names only come into
play when the application requests them.

include/netinet/udp.h

index 15b91454fe5872266e6a14b49f8b0710dbdfbc71..b1b0eb819af5d2843103311b00eee2b137ca6600 100644 (file)
@@ -5,19 +5,22 @@
 extern "C" {
 #endif
 
+#include <features.h>
 #include <stdint.h>
 
-struct udphdr {
-       uint16_t source;
-       uint16_t dest;
-       uint16_t len;
-       uint16_t check;
-};
-
+#ifdef _GNU_SOURCE
 #define uh_sport source
 #define uh_dport dest
 #define uh_ulen len
 #define uh_sum check
+#endif
+
+struct udphdr {
+       uint16_t uh_sport;
+       uint16_t uh_dport;
+       uint16_t uh_ulen;
+       uint16_t uh_sum;
+};
 
 #define UDP_CORK       1
 #define UDP_ENCAP      100