/* * Copyright 2006-2008, 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 - struct media_type { int type; const char* name; const char* pretty; struct { int subtype; const char* name; const char* pretty; } subtypes [6]; struct { int option; bool ro; const char* name; const char* pretty; } options [6]; }; static const media_type kMediaTypes[] = { { 0, // for generic options "all", "All", { { IFM_AUTO, "auto", "Auto-select" }, { -1, NULL, NULL } }, { { IFM_FULL_DUPLEX, true, "fullduplex", "Full Duplex" }, { IFM_HALF_DUPLEX, true, "halfduplex", "Half Duplex" }, { IFM_LOOP, true, "loop", "Loop" }, //{ IFM_ACTIVE, false, "active", "Active" }, { -1, false, NULL, NULL } } }, { IFM_ETHER, "ether", "Ethernet", { //{ IFM_AUTO, "auto", "Auto-select" }, //{ IFM_AUI, "AUI", "10 MBit, AUI" }, //{ IFM_10_2, "10base2", "10 MBit, 10BASE-2" }, { IFM_10_T, "10baseT", "10 MBit, 10BASE-T" }, { IFM_100_TX, "100baseTX", "100 MBit, 100BASE-TX" }, { IFM_1000_T, "1000baseT", "1 GBit, 1000BASE-T" }, { IFM_1000_SX, "1000baseSX", "1 GBit, 1000BASE-SX" }, { -1, NULL, NULL } }, { { -1, false, NULL, NULL } } }, { -1, NULL, NULL, {{ -1, NULL, NULL }}, {{ -1, false, NULL, NULL }} } }; static bool media_parse_subtype(const char* string, int media, int* type); static bool media_parse_subtype(const char* string, int media, int* type) { for (int32 i = 0; kMediaTypes[i].type >= 0; i++) { // only check for generic or correct subtypes if (kMediaTypes[i].type && kMediaTypes[i].type != media) continue; for (int32 j = 0; kMediaTypes[i].subtypes[j].subtype >= 0; j++) { if (strcmp(kMediaTypes[i].subtypes[j].name, string) == 0) { // found a match *type = kMediaTypes[i].subtypes[j].subtype; return true; } } } return false; } // #pragma mark - void usage(int status) { printf("usage: %s [ [
] [
[]] [