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.
This commit is contained in:
1 parent
bb55cf014a
commit
2d4b692ecd
1 file changed
+12
-8
+12
-8
@@ -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'.
|
||||
|
||||
Reference in new issue
Block a user