From: Ben Pfaff Date: Wed, 30 Jul 2008 22:45:33 +0000 (-0700) Subject: netdev: Let netdev_get_in4(), netdev_get_in6() take null pointer argument. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d4b692ecd5aa17d023f233c8b62dacd0bcf8351;p=openvswitch netdev: Let netdev_get_in4(), netdev_get_in6() take null pointer argument. Some callers want to just test whether the device has an address assigned and don't care about the particular address, so this simplifies those callers slightly. --- diff --git a/lib/netdev.c b/lib/netdev.c index 0bcef671..0cd3e6d4 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -530,13 +530,15 @@ netdev_get_features(const struct netdev *netdev) return netdev->features; } -/* If 'netdev' has an assigned IPv4 address, sets '*in4' to that address and - * returns true. Otherwise, returns false. */ +/* If 'netdev' has an assigned IPv4 address, sets '*in4' to that address (if + * 'in4' is non-null) and returns true. Otherwise, returns false. */ bool netdev_get_in4(const struct netdev *netdev, struct in_addr *in4) { - *in4 = netdev->in4; - return in4->s_addr != INADDR_ANY; + if (in4) { + *in4 = netdev->in4; + } + return netdev->in4.s_addr != INADDR_ANY; } static void @@ -608,13 +610,15 @@ netdev_add_router(struct netdev *netdev, struct in_addr router) return error; } -/* If 'netdev' has an assigned IPv6 address, sets '*in6' to that address and - * returns true. Otherwise, returns false. */ +/* If 'netdev' has an assigned IPv6 address, sets '*in6' to that address (if + * 'in6' is non-null) and returns true. Otherwise, returns false. */ bool netdev_get_in6(const struct netdev *netdev, struct in6_addr *in6) { - *in6 = netdev->in6; - return memcmp(in6, &in6addr_any, sizeof *in6) != 0; + if (in6) { + *in6 = netdev->in6; + } + return memcmp(&netdev->in6, &in6addr_any, sizeof netdev->in6) != 0; } /* Obtains the current flags for 'netdev' and stores them into '*flagsp'.