Route: Don't call null function pointers
* Regression from hrev38233 (2010 baby!) * If no netmask, don't print anything vs showing uninitialized data. * Introduce "worst case address length" information per network family. * Fixes #9821
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2010, Haiku, Inc. All Rights Reserved.
|
* Copyright 2006-2013, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Axel Dörfler, [email protected]
|
* Axel Dörfler, [email protected]
|
||||||
|
* Alexander von Gluck <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -48,11 +49,7 @@ struct address_family {
|
|||||||
int family;
|
int family;
|
||||||
const char* name;
|
const char* name;
|
||||||
const char* identifiers[4];
|
const char* identifiers[4];
|
||||||
preferred_output_format preferred_format;
|
uint32 maxLength;
|
||||||
bool (*parse_address)(const char* string, sockaddr* _address);
|
|
||||||
bool (*prefix_length_to_mask)(uint8 prefixLength, sockaddr* mask);
|
|
||||||
uint8 (*mask_to_prefix_length)(sockaddr* mask);
|
|
||||||
const char* (*address_to_string)(sockaddr* address);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -61,15 +58,15 @@ static const address_family kFamilies[] = {
|
|||||||
AF_INET,
|
AF_INET,
|
||||||
"inet",
|
"inet",
|
||||||
{"AF_INET", "inet", "ipv4", NULL},
|
{"AF_INET", "inet", "ipv4", NULL},
|
||||||
PREFER_OUTPUT_MASK,
|
15,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
AF_INET6,
|
AF_INET6,
|
||||||
"inet6",
|
"inet6",
|
||||||
{"AF_INET6", "inet6", "ipv6", NULL},
|
{"AF_INET6", "inet6", "ipv6", NULL},
|
||||||
PREFER_OUTPUT_PREFIX_LENGTH,
|
39,
|
||||||
},
|
},
|
||||||
{ -1, NULL, {NULL}, PREFER_OUTPUT_MASK, NULL, NULL, NULL, NULL }
|
{ -1, NULL, {NULL} }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -204,20 +201,16 @@ list_routes(int socket, const char *interfaceName, route_entry &route)
|
|||||||
|
|
||||||
if (family != NULL) {
|
if (family != NULL) {
|
||||||
BNetworkAddress destination(*route.destination);
|
BNetworkAddress destination(*route.destination);
|
||||||
BNetworkAddress mask;
|
|
||||||
if (route.mask != NULL)
|
|
||||||
mask.SetTo(*route.mask);
|
|
||||||
|
|
||||||
// TODO: is the %15s format OK for IPv6?
|
|
||||||
printf("%15s", destination.ToString().String());
|
printf("%15s", destination.ToString().String());
|
||||||
switch (family->preferred_format) {
|
|
||||||
case PREFER_OUTPUT_MASK:
|
if (route.mask != NULL) {
|
||||||
printf(" mask %-15s ", mask.ToString().String());
|
BNetworkAddress mask;
|
||||||
break;
|
mask.SetTo(*route.mask);
|
||||||
case PREFER_OUTPUT_PREFIX_LENGTH:
|
printf("/%zd\t", mask.PrefixLength());
|
||||||
printf("/%zd ", mask.PrefixLength());
|
} else
|
||||||
break;
|
printf(" \t");
|
||||||
}
|
|
||||||
if ((route.flags & RTF_GATEWAY) != 0) {
|
if ((route.flags & RTF_GATEWAY) != 0) {
|
||||||
BNetworkAddress gateway;
|
BNetworkAddress gateway;
|
||||||
if (route.gateway != NULL)
|
if (route.gateway != NULL)
|
||||||
@@ -334,22 +327,17 @@ get_route(int socket, route_entry &route)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (family != NULL) {
|
if (family != NULL) {
|
||||||
printf("%s", family->address_to_string(request.destination));
|
BNetworkAddress destination(*request.destination);
|
||||||
switch (family->preferred_format) {
|
BNetworkAddress mask(*request.mask);
|
||||||
case PREFER_OUTPUT_MASK:
|
printf("%s", destination.ToString().String());
|
||||||
printf(" mask %s ",
|
printf("/%zd ", mask.PrefixLength());
|
||||||
family->address_to_string(request.mask));
|
|
||||||
break;
|
|
||||||
case PREFER_OUTPUT_PREFIX_LENGTH:
|
|
||||||
printf("/%u ",
|
|
||||||
family->mask_to_prefix_length(request.mask));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
BNetworkAddress gateway(*request.gateway);
|
||||||
if (request.flags & RTF_GATEWAY)
|
if (request.flags & RTF_GATEWAY)
|
||||||
printf("gateway %s ", family->address_to_string(request.gateway));
|
printf("gateway %s ", gateway.ToString().String());
|
||||||
|
|
||||||
printf("source %s\n", family->address_to_string(request.source));
|
BNetworkAddress source(*request.source);
|
||||||
|
printf("source %s\n", source.ToString().String());
|
||||||
} else {
|
} else {
|
||||||
printf("unknown family ");
|
printf("unknown family ");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user