From 47f91726cdf48669d20c53612c1b4981e6474c2a Mon Sep 17 00:00:00 2001 From: Alexander von Gluck IV Date: Sun, 16 Jun 2013 12:04:10 -0500 Subject: [PATCH] Route: Group together printer families. * Only check th family of the first incoming route entry as the list_routes function is called with the family pre-determined on the socket. --- src/bin/network/route/route.cpp | 35 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/bin/network/route/route.cpp b/src/bin/network/route/route.cpp index 7e37bcd8e7..e32939c745 100644 --- a/src/bin/network/route/route.cpp +++ b/src/bin/network/route/route.cpp @@ -40,29 +40,23 @@ enum modes { RTM_FLUSH, }; -enum preferred_output_format { - PREFER_OUTPUT_MASK, - PREFER_OUTPUT_PREFIX_LENGTH, -}; - struct address_family { int family; const char* name; const char* identifiers[4]; - uint32 maxLength; + uint32 maxAddressLength; }; - static const address_family kFamilies[] = { { AF_INET, - "inet", + "IPv4", {"AF_INET", "inet", "ipv4", NULL}, 15, }, { AF_INET6, - "inet6", + "IPv6", {"AF_INET6", "inet6", "ipv6", NULL}, 39, }, @@ -184,24 +178,28 @@ list_routes(int socket, const char *interfaceName, route_entry &route) ifreq *interface = (ifreq*)buffer; ifreq *end = (ifreq*)((uint8*)buffer + size); + // find family (we use the family of the first address as this is + // called on a socket for a single family) + const address_family *family = NULL; + for (int32 i = 0; kFamilies[i].family >= 0; i++) { + if (interface->ifr_route.destination->sa_family + == kFamilies[i].family) { + family = &kFamilies[i]; + break; + } + } + + printf("%s routing table:\n", family->name); + while (interface < end) { route_entry& route = interface->ifr_route; // apply filters if (interfaceName == NULL || !strcmp(interfaceName, interface->ifr_name)) { - // find family - const address_family *family = NULL; - for (int32 i = 0; kFamilies[i].family >= 0; i++) { - if (route.destination->sa_family == kFamilies[i].family) { - family = &kFamilies[i]; - break; - } - } if (family != NULL) { BNetworkAddress destination(*route.destination); - printf("%15s", destination.ToString().String()); if (route.mask != NULL) { @@ -264,6 +262,7 @@ list_routes(int socket, const char *interfaceName, route_entry &route) + sizeof(route_entry) + addressSize); } + putchar('\n'); free(buffer); }