/* * Copyright 2006-2010, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: * Axel Dörfler, axeld@pinc-software.de */ #include #include #include #include #include #include #include #include #include #include #include #include #include extern const char* __progname; const char* kProgramName = __progname; enum modes { RTM_LIST = 0, RTM_DELETE, RTM_ADD, RTM_GET, // TODO: RTM_CHANGE, 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]; preferred_output_format preferred_format; 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); }; static const address_family kFamilies[] = { { AF_INET, "inet", {"AF_INET", "inet", "ipv4", NULL}, PREFER_OUTPUT_MASK, }, { AF_INET6, "inet6", {"AF_INET6", "inet6", "ipv6", NULL}, PREFER_OUTPUT_PREFIX_LENGTH, }, { -1, NULL, {NULL}, PREFER_OUTPUT_MASK, NULL, NULL, NULL, NULL } }; void usage(int status) { printf("usage: %s [command] [] [
] " " [