diff options
Diffstat (limited to 'networking')
-rw-r--r-- | networking/ifconfig.c | 12 | ||||
-rw-r--r-- | networking/netstat.c | 33 | ||||
-rw-r--r-- | networking/nslookup.c | 10 | ||||
-rw-r--r-- | networking/route.c | 69 | ||||
-rw-r--r-- | networking/telnet.c | 38 | ||||
-rw-r--r-- | networking/traceroute.c | 15 |
6 files changed, 71 insertions, 106 deletions
diff --git a/networking/ifconfig.c b/networking/ifconfig.c index fe154cf13..0b834e7c7 100644 --- a/networking/ifconfig.c +++ b/networking/ifconfig.c @@ -15,7 +15,7 @@ * Foundation; either version 2 of the License, or (at * your option) any later version. * - * $Id: ifconfig.c,v 1.15 2001/10/28 09:36:48 andersen Exp $ + * $Id: ifconfig.c,v 1.16 2001/11/10 11:22:43 andersen Exp $ * */ @@ -34,14 +34,12 @@ #include <string.h> // strcmp and friends #include <ctype.h> // isdigit and friends #include <stddef.h> /* offsetof */ -#include <sys/types.h> -#include <sys/socket.h> #include <sys/ioctl.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <net/if.h> #include <net/if_arp.h> +#include <netinet/in.h> #include <linux/if_ether.h> +#include <net/if.h> +#include "inet_common.h" #include "busybox.h" #ifdef CONFIG_FEATURE_IFCONFIG_SLIP @@ -339,7 +337,7 @@ int ifconfig_main(int argc, char **argv) safe_strncpy(host, *argv, (sizeof host)); sai.sin_family = AF_INET; sai.sin_port = 0; - if (!strcmp(host, "default")) { + if (!strcmp(host, bb_INET_default)) { /* Default is special, meaning 0.0.0.0. */ sai.sin_addr.s_addr = INADDR_ANY; } else if (inet_aton(host, &sai.sin_addr) == 0) { diff --git a/networking/netstat.c b/networking/netstat.c index e33a89a64..28ae9bc32 100644 --- a/networking/netstat.c +++ b/networking/netstat.c @@ -30,10 +30,7 @@ #include <dirent.h> #include <unistd.h> #include <pwd.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> - +#include "inet_common.h" #include "busybox.h" #define NETSTAT_CONNECTED 0x01 @@ -95,7 +92,7 @@ typedef enum { #define SO_WAITDATA (1<<17) /* wait data to read */ #define SO_NOSPACE (1<<18) /* no space to write */ -char *itoa(unsigned int i) +static char *itoa(unsigned int i) { /* 21 digits plus null terminator, good for 64-bit or smaller ints */ static char local[22]; @@ -108,24 +105,7 @@ char *itoa(unsigned int i) return p + 1; } -char *inet_sprint(struct sockaddr* addr, int num) -{ - char *str; - str=inet_ntoa(((struct sockaddr_in*)addr)->sin_addr); - if (!strcmp(str,"0.0.0.0")) { - str="*"; - } - if (num) - { - } else { - struct hostent *he=gethostbyaddr(&((struct sockaddr_in*)addr)->sin_addr,4,AF_INET); - if (he) - str=he->h_name; - } - return str; -} - -char *get_sname(int port, const char *proto, int num) +static char *get_sname(int port, const char *proto, int num) { char *str=itoa(ntohs(port)); if (num) { @@ -140,10 +120,13 @@ char *get_sname(int port, const char *proto, int num) return str; } -void snprint_ip_port(char *ip_port, int size, struct sockaddr *addr, int port, char *proto, int numeric) +static void snprint_ip_port(char *ip_port, int size, struct sockaddr *addr, int port, char *proto, int numeric) { char *port_name; - safe_strncpy(ip_port, inet_sprint(addr, numeric), size); + + INET_rresolve(ip_port, size, (struct sockaddr_in *)addr, + 0x4000 | ((numeric&NETSTAT_NUMERIC) ? 0x0fff : 0), + 0xffffffff); port_name=get_sname(htons(port), proto, numeric); if ((strlen(ip_port) + strlen(port_name)) > 22) ip_port[22 - strlen(port_name)] = '\0'; diff --git a/networking/nslookup.c b/networking/nslookup.c index a1a12d992..81b57cccf 100644 --- a/networking/nslookup.c +++ b/networking/nslookup.c @@ -90,10 +90,10 @@ static int addr_list_fprint(char **h_addr_list) } /* print the results as nslookup would */ -static struct hostent *hostent_fprint(struct hostent *host) +static struct hostent *hostent_fprint(struct hostent *host, const char *server_host) { if (host) { - printf("Name: %s\n", host->h_name); + printf("%s %s\n", server_host, host->h_name); addr_list_fprint(host->h_addr_list); } else { printf("*** Unknown host\n"); @@ -142,7 +142,7 @@ static inline void server_print(void) struct sockaddr_in def = _res.nsaddr_list[0]; char *ip = inet_ntoa(def.sin_addr); - hostent_fprint(gethostbyaddr_wrapper(ip)); + hostent_fprint(gethostbyaddr_wrapper(ip), "Server:"); printf("\n"); } #endif @@ -176,8 +176,8 @@ int nslookup_main(int argc, char **argv) } else { host = xgethostbyname(argv[1]); } - hostent_fprint(host); + hostent_fprint(host, "Name: "); return EXIT_SUCCESS; } -/* $Id: nslookup.c,v 1.26 2001/10/24 04:59:56 andersen Exp $ */ +/* $Id: nslookup.c,v 1.27 2001/11/10 11:22:43 andersen Exp $ */ diff --git a/networking/route.c b/networking/route.c index ee3533100..43180296d 100644 --- a/networking/route.c +++ b/networking/route.c @@ -15,7 +15,7 @@ * Foundation; either version 2 of the License, or (at * your option) any later version. * - * $Id: route.c,v 1.13 2001/09/05 19:32:00 andersen Exp $ + * $Id: route.c,v 1.14 2001/11/10 11:22:43 andersen Exp $ * * displayroute() code added by Vladimir N. Oleynik <dzo@simtreas.ru> * adjustments by Larry Doolittle <LRDoolittle@lbl.gov> @@ -23,11 +23,9 @@ #include <sys/types.h> #include <sys/ioctl.h> -#include <sys/socket.h> +#include "inet_common.h" #include <net/route.h> #include <linux/param.h> // HZ -#include <netinet/in.h> -#include <arpa/inet.h> #include <stdio.h> #include <errno.h> #include <fcntl.h> @@ -55,29 +53,6 @@ #define E_INTERN 2 #define E_NOSUPP 1 -/* resolve XXX.YYY.ZZZ.QQQ -> binary */ - -static int -INET_resolve(char *name, struct sockaddr *sa) -{ - struct sockaddr_in *s_in = (struct sockaddr_in *)sa; - - s_in->sin_family = AF_INET; - s_in->sin_port = 0; - - /* Default is special, meaning 0.0.0.0. */ - if (strcmp(name, "default")==0) { - s_in->sin_addr.s_addr = INADDR_ANY; - return 1; - } - /* Look to see if it's a dotted quad. */ - if (inet_aton(name, &s_in->sin_addr)) { - return 0; - } - /* guess not.. */ - return -1; -} - #if defined (SIOCADDRTOLD) || defined (RTF_IRTT) /* route */ #define HAVE_NEW_ADDRT 1 #endif @@ -96,13 +71,16 @@ INET_resolve(char *name, struct sockaddr *sa) #define full_mask(x) (((struct sockaddr_in *)&(x))->sin_addr.s_addr) #endif + + /* add or delete a route depending on action */ static int INET_setroute(int action, int options, char **args) { struct rtentry rt; - char target[128], gateway[128] = "NONE", netmask[128] = "default"; + char target[128], gateway[128] = "NONE"; + const char *netmask = bb_INET_default; int xflag, isnet; int skfd; @@ -117,13 +95,15 @@ INET_setroute(int action, int options, char **args) xflag = 2; args++; } + if (*args == NULL) + show_usage(); safe_strncpy(target, *args++, (sizeof target)); /* Clean out the RTREQ structure. */ memset((char *) &rt, 0, sizeof(struct rtentry)); - if ((isnet = INET_resolve(target, &rt.rt_dst)) < 0) { + if ((isnet = INET_resolve(target, (struct sockaddr_in *)&rt.rt_dst, xflag!=1)) < 0) { error_msg(_("can't resolve %s"), target); return EXIT_FAILURE; /* XXX change to E_something */ } @@ -169,8 +149,8 @@ INET_setroute(int action, int options, char **args) args++; if (!*args || mask_in_addr(rt)) show_usage(); - safe_strncpy(netmask, *args, (sizeof netmask)); - if ((isnet = INET_resolve(netmask, &mask)) < 0) { + netmask = *args; + if ((isnet = INET_resolve(netmask, (struct sockaddr_in *)&mask, 0)) < 0) { error_msg(_("can't resolve netmask %s"), netmask); return E_LOOKUP; } @@ -186,7 +166,7 @@ INET_setroute(int action, int options, char **args) if (rt.rt_flags & RTF_GATEWAY) show_usage(); safe_strncpy(gateway, *args, (sizeof gateway)); - if ((isnet = INET_resolve(gateway, &rt.rt_gateway)) < 0) { + if ((isnet = INET_resolve(gateway, (struct sockaddr_in *)&rt.rt_gateway, 1)) < 0) { error_msg(_("can't resolve gw %s"), gateway); return E_LOOKUP; } @@ -362,7 +342,7 @@ INET_setroute(int action, int options, char **args) #define RTF_REJECT 0x0200 /* Reject route */ #endif -static void displayroutes(void) +static void displayroutes(int noresolve) { char buff[256]; int nl = 0 ; @@ -375,12 +355,17 @@ static void displayroutes(void) char sdest[16], sgw[16]; - FILE *fp = xfopen("/proc/net/route", "r"); + if(noresolve) + noresolve = 0x0fff; + while( fgets(buff, sizeof(buff), fp) != NULL ) { if(nl) { int ifl = 0; + int numeric; + struct sockaddr_in s_addr; + while(buff[ifl]!=' ' && buff[ifl]!='\t' && buff[ifl]!='\0') ifl++; buff[ifl]=0; /* interface */ @@ -412,10 +397,14 @@ static void displayroutes(void) dest.s_addr = d; gw.s_addr = g; mask.s_addr = m; - strcpy(sdest, (dest.s_addr==0 ? "default" : - inet_ntoa(dest))); - strcpy(sgw, (gw.s_addr==0 ? "*" : - inet_ntoa(gw))); + memset(&s_addr, 0, sizeof(struct sockaddr_in)); + s_addr.sin_family = AF_INET; + s_addr.sin_addr = dest; + numeric = noresolve | 0x8000; /* default instead of * */ + INET_rresolve(sdest, sizeof(sdest), &s_addr, numeric, m); + numeric = noresolve | 0x4000; /* host instead of net */ + s_addr.sin_addr = gw; + INET_rresolve(sgw, sizeof(sgw), &s_addr, numeric, m); printf("%-16s%-16s%-16s%-6s%-6d %-2d %7d %s\n", sdest, sgw, inet_ntoa(mask), @@ -433,8 +422,8 @@ int route_main(int argc, char **argv) argc--; argv++; - if (*argv == NULL) { - displayroutes(); + if (*argv == NULL || (*(argv+1)==NULL && strcmp(*argv, "-n")==0)) { + displayroutes(*argv != NULL); return EXIT_SUCCESS; } else { /* check verb */ diff --git a/networking/telnet.c b/networking/telnet.c index 57494089d..71479fce4 100644 --- a/networking/telnet.c +++ b/networking/telnet.c @@ -112,7 +112,7 @@ struct Globalvars * Gptr; static struct Globalvars G; #endif -static inline void iacflush() +static inline void iacflush(void) { write(G.netfd, G.iacbuf, G.iaclen); G.iaclen = 0; @@ -121,13 +121,12 @@ static inline void iacflush() /* Function prototypes */ static int getport(char * p); static struct in_addr getserver(char * p); -static int create_socket(); static void setup_sockaddr_in(struct sockaddr_in * addr, int port); static int remote_connect(struct in_addr addr, int port); -static void rawmode(); -static void cookmode(); -static void do_linemode(); -static void will_charmode(); +static void rawmode(void); +static void cookmode(void); +static void do_linemode(void); +static void will_charmode(void); static void telopt(byte c); static int subneg(byte c); #if 0 @@ -147,7 +146,7 @@ static void doexit(int ev) exit(ev); } -static void conescape() +static void conescape(void) { char b; @@ -353,7 +352,7 @@ static void putiac_subopt(byte c, char *str) static char const escapecharis[] = "\r\nEscape character is "; -static void setConMode() +static void setConMode(void) { if (G.telflags & UF_ECHO) { @@ -375,7 +374,7 @@ static void setConMode() /* ******************************* */ -static void will_charmode() +static void will_charmode(void) { G.charmode = CHM_TRY; G.telflags |= (UF_ECHO | UF_SGA); @@ -386,7 +385,7 @@ static void will_charmode() iacflush(); } -static void do_linemode() +static void do_linemode(void) { G.charmode = CHM_TRY; G.telflags &= ~(UF_ECHO | UF_SGA); @@ -405,7 +404,7 @@ static inline void to_notsup(char c) else if (G.telwish == DO) putiac2(WONT, c); } -static inline void to_echo() +static inline void to_echo(void) { /* if server requests ECHO, don't agree */ if (G.telwish == DO) { putiac2(WONT, TELOPT_ECHO); return; } @@ -432,7 +431,7 @@ static inline void to_echo() WriteCS(1, "\r\n"); /* sudden modec */ } -static inline void to_sga() +static inline void to_sga(void) { /* daemon always sends will/wont, client do/dont */ @@ -454,7 +453,7 @@ static inline void to_sga() } #ifdef CONFIG_FEATURE_TELNET_TTYPE -static inline void to_ttype() +static inline void to_ttype(void) { /* Tell server we will (or won't) do TTYPE */ @@ -471,10 +470,10 @@ static void telopt(byte c) { switch (c) { - case TELOPT_ECHO: to_echo(c); break; - case TELOPT_SGA: to_sga(c); break; + case TELOPT_ECHO: to_echo(); break; + case TELOPT_SGA: to_sga(); break; #ifdef CONFIG_FEATURE_TELNET_TTYPE - case TELOPT_TTYPE: to_ttype(c); break; + case TELOPT_TTYPE: to_ttype(); break; #endif default: to_notsup(c); break; } @@ -515,12 +514,12 @@ static void fgotsig(int sig) } -static void rawmode() +static void rawmode(void) { tcsetattr(0, TCSADRAIN, &G.termios_raw); } -static void cookmode() +static void cookmode(void) { tcsetattr(0, TCSADRAIN, &G.termios_def); } @@ -650,7 +649,7 @@ static struct in_addr getserver(char * host) return addr; } -static int create_socket() +static int create_socket(void) { return socket(AF_INET, SOCK_STREAM, 0); } @@ -708,4 +707,3 @@ c-basic-offset: 4 tab-width: 4 End: */ - diff --git a/networking/traceroute.c b/networking/traceroute.c index e7d9725af..5bd3ddb0e 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c @@ -72,11 +72,9 @@ #include <string.h> #include <unistd.h> #include <sys/time.h> -#include <sys/types.h> -#include <sys/socket.h> +#include "inet_common.h" #include <netdb.h> #include <endian.h> -#include <arpa/inet.h> #include <netinet/udp.h> #include <netinet/ip.h> #include <netinet/ip_icmp.h> @@ -228,8 +226,8 @@ static inline void inetname(struct sockaddr_in *from) { char *cp; - struct hostent *hp; static char domain[MAXHOSTNAMELEN + 1]; + char name[MAXHOSTNAMELEN + 1]; static int first = 1; const char *ina; @@ -243,12 +241,11 @@ inetname(struct sockaddr_in *from) } cp = 0; if (!nflag && from->sin_addr.s_addr != INADDR_ANY) { - hp = gethostbyaddr((char *)&(from->sin_addr), sizeof (from->sin_addr), AF_INET); - if (hp) { - if ((cp = strchr(hp->h_name, '.')) && + if(INET_rresolve(name, sizeof(name), from, 0, 0xffffffff) >= 0) { + if ((cp = strchr(name, '.')) && !strcmp(cp + 1, domain)) *cp = 0; - cp = (char *)hp->h_name; + cp = (char *)name; } } ina = inet_ntoa(from->sin_addr); @@ -645,7 +642,7 @@ traceroute_main(argc, argv) } putchar('\n'); if (got_there || unreachable >= nprobes-1) - exit(0); + return 0; } return 0; |