/* * Copyright 2006-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: * Axel Dörfler, axeld@pinc-software.de * Oliver Tappe, zooey@hirschkaefer.de */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include extern const char* __progname; const char* kProgramName = __progname; struct address_family { int family; const char* name; const char* identifiers[4]; bool (*parse_address)(const char* string, sockaddr* _address); void (*print_address)(sockaddr* address); }; // AF_INET family static bool inet_parse_address(const char* string, sockaddr* address); static void inet_print_address(sockaddr* address); static const address_family kFamilies[] = { { AF_INET, "inet", {"AF_INET", "inet", "ipv4", NULL}, inet_parse_address, inet_print_address }, { -1, NULL, {NULL}, NULL, NULL } }; static bool inet_parse_address(const char* string, sockaddr* _address) { in_addr inetAddress; if (inet_aton(string, &inetAddress) != 1) return false; sockaddr_in& address = *(sockaddr_in *)_address; address.sin_family = AF_INET; address.sin_len = sizeof(struct sockaddr_in); address.sin_port = 0; address.sin_addr = inetAddress; memset(&address.sin_zero[0], 0, sizeof(address.sin_zero)); return true; } static void inet_print_address(sockaddr* _address) { sockaddr_in& address = *(sockaddr_in *)_address; if (address.sin_family != AF_INET) return; printf("%s", inet_ntoa(address.sin_addr)); } // #pragma mark - void usage(int status) { printf("usage: %s [ [
] [
[]] [