summaryrefslogtreecommitdiffstats
path: root/src/include/ipxe/in.h
diff options
context:
space:
mode:
authorMichael Brown2015-07-21 16:26:52 +0200
committerMichael Brown2015-07-28 14:48:29 +0200
commit6efcabd4151538781053716bec1c7eccd759df26 (patch)
tree44d56878eb316b864d172d228c80aa1bf3596e40 /src/include/ipxe/in.h
parent[netdevice] Avoid using zero as a network device index (diff)
downloadipxe-6efcabd4151538781053716bec1c7eccd759df26.tar.gz
ipxe-6efcabd4151538781053716bec1c7eccd759df26.tar.xz
ipxe-6efcabd4151538781053716bec1c7eccd759df26.zip
[ipv4] Redefine IP address constants to avoid unnecessary byte swapping
Redefine various IPv4 address constants and testing macros to avoid unnecessary byte swapping at runtime, and slightly rename the macros to prevent code from accidentally using the old definitions. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe/in.h')
-rw-r--r--src/include/ipxe/in.h24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/include/ipxe/in.h b/src/include/ipxe/in.h
index b29c2d74..2a49b00b 100644
--- a/src/include/ipxe/in.h
+++ b/src/include/ipxe/in.h
@@ -4,6 +4,7 @@
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
+#include <byteswap.h>
#include <ipxe/socket.h>
/* Protocol numbers */
@@ -15,17 +16,22 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/* IP address constants */
-#define INADDR_NONE 0xffffffff
+#define INADDR_NONE htonl ( 0xffffffff )
-#define INADDR_BROADCAST 0xffffffff
+#define INADDR_BROADCAST htonl ( 0xffffffff )
-#define IN_CLASSA(addr) ( ( (addr) & 0x80000000 ) == 0x00000000 )
-#define IN_CLASSA_NET 0xff000000
-#define IN_CLASSB(addr) ( ( (addr) & 0xc0000000 ) == 0x80000000 )
-#define IN_CLASSB_NET 0xffff0000
-#define IN_CLASSC(addr) ( ( (addr) & 0xe0000000 ) == 0xc0000000 )
-#define IN_CLASSC_NET 0xffffff00
-#define IN_MULTICAST(addr) ( ( (addr) & 0xf0000000 ) == 0xe0000000 )
+#define INADDR_NET_CLASSA htonl ( 0xff000000 )
+#define INADDR_NET_CLASSB htonl ( 0xffff0000 )
+#define INADDR_NET_CLASSC htonl ( 0xffffff00 )
+
+#define IN_IS_CLASSA( addr ) \
+ ( ( (addr) & htonl ( 0x80000000 ) ) == htonl ( 0x00000000 ) )
+#define IN_IS_CLASSB( addr ) \
+ ( ( (addr) & htonl ( 0xc0000000 ) ) == htonl ( 0x80000000 ) )
+#define IN_IS_CLASSC( addr ) \
+ ( ( (addr) & htonl ( 0xe0000000 ) ) == htonl ( 0xc0000000 ) )
+#define IN_IS_MULTICAST( addr ) \
+ ( ( (addr) & htonl ( 0xf0000000 ) ) == htonl ( 0xe0000000 ) )
/**
* IP address structure