# HG changeset patch # User Rob Landley # Date 1365125228 18000 # Node ID 1b36ac92e2ccba80223b76db5f62bcdd2adc0f63 # Parent af5aab6e667871d519989179fbfe2836dd2162c4 Drive-by cleanup on ifconfig. diff -r af5aab6e6678 -r 1b36ac92e2cc toys/pending/ifconfig.c --- a/toys/pending/ifconfig.c Thu Apr 04 19:39:44 2013 -0500 +++ b/toys/pending/ifconfig.c Thu Apr 04 20:27:08 2013 -0500 @@ -37,14 +37,6 @@ #include #include -#define TRUE ((int) 1) -#define HTTP_DEFAULT_PORT 80 -#define FTP_DEFAULT_PORT 21 - -#ifndef MAX_PORT_VALUE -#define MAX_PORT_VALUE 65535 -#endif - typedef struct sockaddr_with_len { union { struct sockaddr sock; @@ -59,9 +51,7 @@ int get_addrinfo(const char *, struct sockaddr_in6 *); void get_flag_value(char **, int); void display_routes(int, int); -unsigned getport(const char *, const char *, unsigned); void setport(struct sockaddr *, unsigned); -int connect_to_stream(const sockaddr_with_len *); unsigned get_strtou(const char *, char **, int); char *address_to_name(const struct sockaddr *); sockaddr_with_len *get_sockaddr(const char *, int, sa_family_t); @@ -406,7 +396,7 @@ } ch_ptr++; //skip ':' to get the port number. *port = get_strtou(ch_ptr, NULL, 10); - if(errno || (unsigned)*port > MAX_PORT_VALUE) + if(errno || (unsigned)*port > 65535) error_exit("bad port spec '%s'", org_host); } return; @@ -522,60 +512,6 @@ } /* - * used to get the port number for ftp and http. - */ -unsigned getport(const char *port, const char *protocol, unsigned defport) -{ -#define RANGE_STR "Port Number should be in [1-65535] range" - long v; - char *endptr = NULL; - - unsigned portnum = defport; - if(port) { - errno = 0; - v = strtol(port, &endptr, 10); - if((v > 0) && (!*endptr)) {//for numeric like 123 - portnum = v; - if(portnum > MAX_PORT_VALUE) error_exit("Invalid Port Number '%s' "RANGE_STR, port); - } - else if((v == 0) && (endptr != NULL)) { - switch(defport) { - case FTP_DEFAULT_PORT: - if(strcmp(endptr, "ftp") == 0) portnum = defport; //for "ftp" string. - else goto ERROR_EXIT; - break; - case HTTP_DEFAULT_PORT: - if(strcmp(endptr, "http") == 0) portnum = defport;//for "HTTP" string. - else goto ERROR_EXIT; - break; - default: -ERROR_EXIT: - error_exit("Invalid Port"); - break; - } - } - else perror_exit("Invalid Port Number: '%s' "RANGE_STR, port); - } -#undef RANGE_STR - return (uint16_t)portnum; -} - -/* - * used to connect with the socket. - */ -int connect_to_stream(const sockaddr_with_len *swl) -{ - int sockfd; - if((sockfd = socket(swl->sock_u.sock.sa_family, SOCK_STREAM, 0)) < 0) - perror_exit("cannot open control socket"); - if(connect(sockfd, &swl->sock_u.sock, swl->socklen) < 0) { - close(sockfd); - perror_exit("can't connect to remote host"); - } - return sockfd; -} - -/* * used to converts string into int and validate the input str for invalid int value or out-of-range. */ unsigned get_strtou(const char *str, char **endp, int base) @@ -1483,7 +1419,7 @@ perror_msg("error: no inet socket available"); return -1; } - while(TRUE) { + for (;;) { ifcon.ifc_len = sizeof(struct ifreq) * num_of_req; //Size of buffer. ifcon.ifc_buf = xrealloc(ifcon.ifc_buf, ifcon.ifc_len);