aboutsummaryrefslogtreecommitdiff
path: root/lib/packets.h
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2012-12-12 15:26:21 -0800
committerBen Pfaff <blp@nicira.com>2012-12-12 15:26:21 -0800
commited36537ebf48108accf21a8aa073279eceeafa98 (patch)
treee5e11cd63c50f7fe16437609d72914502ee29aad /lib/packets.h
parent401d5a6d16438ceb2e09c19677b97504593b4b51 (diff)
packets: Change IP_ARGS interface to take an ovs_be32 instead of a pointer.
An ovs_be32 is a more obvious way to represent an IP address than a pointer to one. It is also more type-safe, especially since "sparse" is able to check that the argument is in network byte order. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
Diffstat (limited to 'lib/packets.h')
-rw-r--r--lib/packets.h14
1 files changed, 5 insertions, 9 deletions
diff --git a/lib/packets.h b/lib/packets.h
index 5f9be01e..7e2d4e99 100644
--- a/lib/packets.h
+++ b/lib/packets.h
@@ -272,16 +272,12 @@ struct vlan_eth_header {
} __attribute__((packed));
BUILD_ASSERT_DECL(VLAN_ETH_HEADER_LEN == sizeof(struct vlan_eth_header));
-/* The "(void) (ip)[0]" below has no effect on the value, since it's the first
- * argument of a comma expression, but it makes sure that 'ip' is a pointer.
- * This is useful since a common mistake is to pass an integer instead of a
- * pointer to IP_ARGS. */
-#define IP_FMT "%"PRIu8".%"PRIu8".%"PRIu8".%"PRIu8
+#define IP_FMT "%"PRIu32".%"PRIu32".%"PRIu32".%"PRIu32
#define IP_ARGS(ip) \
- ((void) (ip)[0], ((uint8_t *) ip)[0]), \
- ((uint8_t *) ip)[1], \
- ((uint8_t *) ip)[2], \
- ((uint8_t *) ip)[3]
+ ntohl(ip) >> 24, \
+ (ntohl(ip) >> 16) & 0xff, \
+ (ntohl(ip) >> 8) & 0xff, \
+ ntohl(ip) & 0xff
/* Example:
*