summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-11-10 11:22:46 +0000
committerEric Andersen <andersen@codepoet.org>2001-11-10 11:22:46 +0000
commitcd8c436d811a5a077a0b61a6616c900173e2dcfb (patch)
tree94163bfef63fec4c2638d5f56be310b7176464d7
parent94f19a838518293810a0fc0c4dca926ca8caff57 (diff)
downloadbusybox-w32-cd8c436d811a5a077a0b61a6616c900173e2dcfb.tar.gz
busybox-w32-cd8c436d811a5a077a0b61a6616c900173e2dcfb.tar.bz2
busybox-w32-cd8c436d811a5a077a0b61a6616c900173e2dcfb.zip
Latest patch from vodz:
-- reverse resolve network name and cache in route and ifconfig applets, fix print nslookup server name if compile without uClibc, fix route crashe 'route add', fix warnings compile networking and pwd_grp applets
-rw-r--r--Changelog6
-rw-r--r--INSTALL15
-rw-r--r--libbb/Makefile4
-rw-r--r--libbb/interface.c197
-rw-r--r--networking/ifconfig.c12
-rw-r--r--networking/netstat.c33
-rw-r--r--networking/nslookup.c10
-rw-r--r--networking/route.c69
-rw-r--r--networking/telnet.c38
-rw-r--r--networking/traceroute.c15
10 files changed, 94 insertions, 305 deletions
diff --git a/Changelog b/Changelog
index 2a778d65d..568852a46 100644
--- a/Changelog
+++ b/Changelog
@@ -26,7 +26,11 @@
26 * Magick 26 * Magick
27 -- made init run inittab command's in the order they show up 27 -- made init run inittab command's in the order they show up
28 in the inittab file (FIFO instead of LIFO). 28 in the inittab file (FIFO instead of LIFO).
29 29 * Vladimir Oleynik
30 -- reverse resolve network name and cache in route and ifconfig
31 applets, fix print nslookup server name if compile without
32 uClibc, fix route crashe 'route add', fix warnings compile
33 networking and pwd_grp applets
30 34
31 -Erik Andersen, --not yet released-- 35 -Erik Andersen, --not yet released--
32 36
diff --git a/INSTALL b/INSTALL
index e17bd80d3..796ef23cc 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,8 +1,13 @@
11) Check Config.h and adjust if you need a different functionality than 11) Run 'make config' or 'make menuconfig' and select the
2 defined by default. 2 functionality that you wish to enable.
3 3
42) Check the Makefile 42) make dep
5 5
63) make 63) Check the Makefile for any Makefile setting you wish
7 to adjust for your system (things like like setting
8 your cross compiler, adjusting optimizations, etc)
7 9
84) make install 104) make
11
125) Run 'make install' or 'make PREFIX=/target install' to
13 install busybox and all the needed links.
diff --git a/libbb/Makefile b/libbb/Makefile
index f4f2d857f..ef8fef4b7 100644
--- a/libbb/Makefile
+++ b/libbb/Makefile
@@ -45,7 +45,7 @@ obj-y += ask_confirmation.o chomp.o concat_path_file.o copy_file.o \
45 xgetcwd.o xreadlink.o xregcomp.o interface.o remove_file.o last_char_is.o \ 45 xgetcwd.o xreadlink.o xregcomp.o interface.o remove_file.o last_char_is.o \
46 copyfd.o vherror_msg.o herror_msg.o herror_msg_and_die.o xgethostbyname.o \ 46 copyfd.o vherror_msg.o herror_msg.o herror_msg_and_die.o xgethostbyname.o \
47 dirname.o make_directory.o create_icmp_socket.o u_signal_names.o arith.o \ 47 dirname.o make_directory.o create_icmp_socket.o u_signal_names.o arith.o \
48 simplify_path.o $(LIBBB_MOBJS) $(LIBBB_AROBJS) 48 simplify_path.o inet_common.o $(LIBBB_MOBJS) $(LIBBB_AROBJS)
49 49
50 50
51# Hand off to toplevel Rules.mak 51# Hand off to toplevel Rules.mak
@@ -65,5 +65,3 @@ loop.h: mk_loop_h.sh
65 65
66clean: 66clean:
67 rm -f $(L_TARGET) *.o core 67 rm -f $(L_TARGET) *.o core
68
69
diff --git a/libbb/interface.c b/libbb/interface.c
index 680216a57..9ecb81b9f 100644
--- a/libbb/interface.c
+++ b/libbb/interface.c
@@ -15,7 +15,7 @@
15 * that either displays or sets the characteristics of 15 * that either displays or sets the characteristics of
16 * one or more of the system's networking interfaces. 16 * one or more of the system's networking interfaces.
17 * 17 *
18 * Version: $Id: interface.c,v 1.6 2001/10/27 03:28:19 andersen Exp $ 18 * Version: $Id: interface.c,v 1.7 2001/11/10 11:22:46 andersen Exp $
19 * 19 *
20 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> 20 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
21 * and others. Copyright 1993 MicroWalt Corporation 21 * and others. Copyright 1993 MicroWalt Corporation
@@ -62,26 +62,17 @@
62#undef HAVE_HWSLIP 62#undef HAVE_HWSLIP
63 63
64 64
65#include <features.h> 65#include "inet_common.h"
66#include <sys/types.h>
67#include <sys/socket.h>
68#include <sys/ioctl.h>
69#include <netinet/in.h>
70#include <net/if.h>
71#include <net/if_arp.h>
72#include <stdio.h> 66#include <stdio.h>
73#include <errno.h> 67#include <errno.h>
74#include <fcntl.h>
75#include <ctype.h>
76#include <stdlib.h> 68#include <stdlib.h>
77#include <string.h> 69#include <string.h>
78#include <unistd.h> 70#include <unistd.h>
79#include <netdb.h> 71#include <fcntl.h>
80#include <netinet/in.h> 72#include <ctype.h>
81#include <arpa/inet.h> 73#include <sys/ioctl.h>
82#if 0 74#include <net/if.h>
83#include <arpa/nameser.h> 75#include <net/if_arp.h>
84#endif
85#include "libbb.h" 76#include "libbb.h"
86 77
87#define _(x) x 78#define _(x) x
@@ -91,7 +82,6 @@
91 82
92static int procnetdev_vsn = 1; 83static int procnetdev_vsn = 1;
93 84
94
95/* Ugh. But libc5 doesn't provide POSIX types. */ 85/* Ugh. But libc5 doesn't provide POSIX types. */
96#include <asm/types.h> 86#include <asm/types.h>
97 87
@@ -124,15 +114,6 @@ struct in6_ifreq {
124#include "ipx.h" 114#include "ipx.h"
125#endif 115#endif
126#endif 116#endif
127#if 0
128#include "net-support.h"
129#include "pathnames.h"
130#include "version.h"
131#include "../intl.h"
132#include "interface.h"
133#include "sockets.h"
134#include "util.h"
135#endif
136 117
137/* Defines for glibc2.0 users. */ 118/* Defines for glibc2.0 users. */
138#ifndef SIOCSIFTXQLEN 119#ifndef SIOCSIFTXQLEN
@@ -313,170 +294,6 @@ static struct aftype unix_aftype =
313 294
314#if HAVE_AFINET 295#if HAVE_AFINET
315 296
316#if 0
317extern int h_errno; /* some netdb.h versions don't export this */
318#endif
319
320/* cache */
321struct addr {
322 struct sockaddr_in addr;
323 char *name;
324 int host;
325 struct addr *next;
326};
327
328static struct addr *INET_nn = NULL; /* addr-to-name cache */
329
330#ifdef KEEP_UNUSED
331static int INET_resolve(char *name, struct sockaddr_in *sin, int hostfirst)
332{
333 struct hostent *hp;
334 struct netent *np;
335
336 /* Grmpf. -FvK */
337 sin->sin_family = AF_INET;
338 sin->sin_port = 0;
339
340 /* Default is special, meaning 0.0.0.0. */
341 if (!strcmp(name, "default")) {
342 sin->sin_addr.s_addr = INADDR_ANY;
343 return (1);
344 }
345 /* Look to see if it's a dotted quad. */
346 if (inet_aton(name, &sin->sin_addr)) {
347 return 0;
348 }
349 /* If we expect this to be a hostname, try hostname database first */
350#ifdef DEBUG
351 if (hostfirst) fprintf (stderr, "gethostbyname (%s)\n", name);
352#endif
353 if (hostfirst &&
354 (hp = gethostbyname(name)) != (struct hostent *) NULL) {
355 memcpy((char *) &sin->sin_addr, (char *) hp->h_addr_list[0],
356 sizeof(struct in_addr));
357 return 0;
358 }
359 /* Try the NETWORKS database to see if this is a known network. */
360#ifdef DEBUG
361 fprintf (stderr, "getnetbyname (%s)\n", name);
362#endif
363 if ((np = getnetbyname(name)) != (struct netent *) NULL) {
364 sin->sin_addr.s_addr = htonl(np->n_net);
365 return 1;
366 }
367 if (hostfirst) {
368 /* Don't try again */
369 errno = h_errno;
370 return -1;
371 }
372#ifdef DEBUG
373 res_init();
374 _res.options |= RES_DEBUG;
375#endif
376
377#ifdef DEBUG
378 fprintf (stderr, "gethostbyname (%s)\n", name);
379#endif
380 if ((hp = gethostbyname(name)) == (struct hostent *) NULL) {
381 errno = h_errno;
382 return -1;
383 }
384 memcpy((char *) &sin->sin_addr, (char *) hp->h_addr_list[0],
385 sizeof(struct in_addr));
386
387 return 0;
388}
389#endif /* KEEP_UNUSED */
390
391/* numeric: & 0x8000: default instead of *,
392 * & 0x4000: host instead of net,
393 * & 0x0fff: don't resolve
394 */
395static int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in,
396 int numeric, unsigned int netmask)
397{
398 struct hostent *ent;
399 struct netent *np;
400 struct addr *pn;
401 unsigned long ad, host_ad;
402 int host = 0;
403
404 /* Grmpf. -FvK */
405 if (s_in->sin_family != AF_INET) {
406#ifdef DEBUG
407 fprintf(stderr, _("rresolve: unsupport address family %d !\n"), s_in->sin_family);
408#endif
409 errno = EAFNOSUPPORT;
410 return (-1);
411 }
412 ad = (unsigned long) s_in->sin_addr.s_addr;
413#ifdef DEBUG
414 fprintf (stderr, "rresolve: %08lx, mask %08x, num %08x \n", ad, netmask, numeric);
415#endif
416 if (ad == INADDR_ANY) {
417 if ((numeric & 0x0FFF) == 0) {
418 if (numeric & 0x8000)
419 safe_strncpy(name, "default", len);
420 else
421 safe_strncpy(name, "*", len);
422 return (0);
423 }
424 }
425 if (numeric & 0x0FFF) {
426 safe_strncpy(name, inet_ntoa(s_in->sin_addr), len);
427 return (0);
428 }
429
430 if ((ad & (~netmask)) != 0 || (numeric & 0x4000))
431 host = 1;
432#if 0
433 INET_nn = NULL;
434#endif
435 pn = INET_nn;
436 while (pn != NULL) {
437 if (pn->addr.sin_addr.s_addr == ad && pn->host == host) {
438 safe_strncpy(name, pn->name, len);
439#ifdef DEBUG
440 fprintf (stderr, "rresolve: found %s %08lx in cache\n", (host? "host": "net"), ad);
441#endif
442 return (0);
443 }
444 pn = pn->next;
445 }
446
447 host_ad = ntohl(ad);
448 np = NULL;
449 ent = NULL;
450 if (host) {
451#ifdef DEBUG
452 fprintf (stderr, "gethostbyaddr (%08lx)\n", ad);
453#endif
454 ent = gethostbyaddr((char *) &ad, 4, AF_INET);
455 if (ent != NULL)
456 safe_strncpy(name, ent->h_name, len);
457 } else {
458#ifdef DEBUG
459 fprintf (stderr, "getnetbyaddr (%08lx)\n", host_ad);
460#endif
461#if 0
462 np = getnetbyaddr(host_ad, AF_INET);
463 if (np != NULL)
464 safe_strncpy(name, np->n_name, len);
465#endif
466 }
467 if ((ent == NULL) && (np == NULL))
468 safe_strncpy(name, inet_ntoa(s_in->sin_addr), len);
469 pn = (struct addr *) xmalloc(sizeof(struct addr));
470 pn->addr = *s_in;
471 pn->next = INET_nn;
472 pn->host = host;
473 pn->name = (char *) xmalloc(strlen(name) + 1);
474 strcpy(pn->name, name);
475 INET_nn = pn;
476
477 return (0);
478}
479
480#ifdef KEEP_UNUSED 297#ifdef KEEP_UNUSED
481static void INET_reserror(char *text) 298static void INET_reserror(char *text)
482{ 299{
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 @@
15 * Foundation; either version 2 of the License, or (at 15 * Foundation; either version 2 of the License, or (at
16 * your option) any later version. 16 * your option) any later version.
17 * 17 *
18 * $Id: ifconfig.c,v 1.15 2001/10/28 09:36:48 andersen Exp $ 18 * $Id: ifconfig.c,v 1.16 2001/11/10 11:22:43 andersen Exp $
19 * 19 *
20 */ 20 */
21 21
@@ -34,14 +34,12 @@
34#include <string.h> // strcmp and friends 34#include <string.h> // strcmp and friends
35#include <ctype.h> // isdigit and friends 35#include <ctype.h> // isdigit and friends
36#include <stddef.h> /* offsetof */ 36#include <stddef.h> /* offsetof */
37#include <sys/types.h>
38#include <sys/socket.h>
39#include <sys/ioctl.h> 37#include <sys/ioctl.h>
40#include <netinet/in.h>
41#include <arpa/inet.h>
42#include <net/if.h>
43#include <net/if_arp.h> 38#include <net/if_arp.h>
39#include <netinet/in.h>
44#include <linux/if_ether.h> 40#include <linux/if_ether.h>
41#include <net/if.h>
42#include "inet_common.h"
45#include "busybox.h" 43#include "busybox.h"
46 44
47#ifdef CONFIG_FEATURE_IFCONFIG_SLIP 45#ifdef CONFIG_FEATURE_IFCONFIG_SLIP
@@ -339,7 +337,7 @@ int ifconfig_main(int argc, char **argv)
339 safe_strncpy(host, *argv, (sizeof host)); 337 safe_strncpy(host, *argv, (sizeof host));
340 sai.sin_family = AF_INET; 338 sai.sin_family = AF_INET;
341 sai.sin_port = 0; 339 sai.sin_port = 0;
342 if (!strcmp(host, "default")) { 340 if (!strcmp(host, bb_INET_default)) {
343 /* Default is special, meaning 0.0.0.0. */ 341 /* Default is special, meaning 0.0.0.0. */
344 sai.sin_addr.s_addr = INADDR_ANY; 342 sai.sin_addr.s_addr = INADDR_ANY;
345 } else if (inet_aton(host, &sai.sin_addr) == 0) { 343 } 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 @@
30#include <dirent.h> 30#include <dirent.h>
31#include <unistd.h> 31#include <unistd.h>
32#include <pwd.h> 32#include <pwd.h>
33#include <sys/socket.h> 33#include "inet_common.h"
34#include <netinet/in.h>
35#include <arpa/inet.h>
36
37#include "busybox.h" 34#include "busybox.h"
38 35
39#define NETSTAT_CONNECTED 0x01 36#define NETSTAT_CONNECTED 0x01
@@ -95,7 +92,7 @@ typedef enum {
95#define SO_WAITDATA (1<<17) /* wait data to read */ 92#define SO_WAITDATA (1<<17) /* wait data to read */
96#define SO_NOSPACE (1<<18) /* no space to write */ 93#define SO_NOSPACE (1<<18) /* no space to write */
97 94
98char *itoa(unsigned int i) 95static char *itoa(unsigned int i)
99{ 96{
100 /* 21 digits plus null terminator, good for 64-bit or smaller ints */ 97 /* 21 digits plus null terminator, good for 64-bit or smaller ints */
101 static char local[22]; 98 static char local[22];
@@ -108,24 +105,7 @@ char *itoa(unsigned int i)
108 return p + 1; 105 return p + 1;
109} 106}
110 107
111char *inet_sprint(struct sockaddr* addr, int num) 108static char *get_sname(int port, const char *proto, int num)
112{
113 char *str;
114 str=inet_ntoa(((struct sockaddr_in*)addr)->sin_addr);
115 if (!strcmp(str,"0.0.0.0")) {
116 str="*";
117 }
118 if (num)
119 {
120 } else {
121 struct hostent *he=gethostbyaddr(&((struct sockaddr_in*)addr)->sin_addr,4,AF_INET);
122 if (he)
123 str=he->h_name;
124 }
125 return str;
126}
127
128char *get_sname(int port, const char *proto, int num)
129{ 109{
130 char *str=itoa(ntohs(port)); 110 char *str=itoa(ntohs(port));
131 if (num) { 111 if (num) {
@@ -140,10 +120,13 @@ char *get_sname(int port, const char *proto, int num)
140 return str; 120 return str;
141} 121}
142 122
143void snprint_ip_port(char *ip_port, int size, struct sockaddr *addr, int port, char *proto, int numeric) 123static void snprint_ip_port(char *ip_port, int size, struct sockaddr *addr, int port, char *proto, int numeric)
144{ 124{
145 char *port_name; 125 char *port_name;
146 safe_strncpy(ip_port, inet_sprint(addr, numeric), size); 126
127 INET_rresolve(ip_port, size, (struct sockaddr_in *)addr,
128 0x4000 | ((numeric&NETSTAT_NUMERIC) ? 0x0fff : 0),
129 0xffffffff);
147 port_name=get_sname(htons(port), proto, numeric); 130 port_name=get_sname(htons(port), proto, numeric);
148 if ((strlen(ip_port) + strlen(port_name)) > 22) 131 if ((strlen(ip_port) + strlen(port_name)) > 22)
149 ip_port[22 - strlen(port_name)] = '\0'; 132 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)
90} 90}
91 91
92/* print the results as nslookup would */ 92/* print the results as nslookup would */
93static struct hostent *hostent_fprint(struct hostent *host) 93static struct hostent *hostent_fprint(struct hostent *host, const char *server_host)
94{ 94{
95 if (host) { 95 if (host) {
96 printf("Name: %s\n", host->h_name); 96 printf("%s %s\n", server_host, host->h_name);
97 addr_list_fprint(host->h_addr_list); 97 addr_list_fprint(host->h_addr_list);
98 } else { 98 } else {
99 printf("*** Unknown host\n"); 99 printf("*** Unknown host\n");
@@ -142,7 +142,7 @@ static inline void server_print(void)
142 struct sockaddr_in def = _res.nsaddr_list[0]; 142 struct sockaddr_in def = _res.nsaddr_list[0];
143 char *ip = inet_ntoa(def.sin_addr); 143 char *ip = inet_ntoa(def.sin_addr);
144 144
145 hostent_fprint(gethostbyaddr_wrapper(ip)); 145 hostent_fprint(gethostbyaddr_wrapper(ip), "Server:");
146 printf("\n"); 146 printf("\n");
147} 147}
148#endif 148#endif
@@ -176,8 +176,8 @@ int nslookup_main(int argc, char **argv)
176 } else { 176 } else {
177 host = xgethostbyname(argv[1]); 177 host = xgethostbyname(argv[1]);
178 } 178 }
179 hostent_fprint(host); 179 hostent_fprint(host, "Name: ");
180 return EXIT_SUCCESS; 180 return EXIT_SUCCESS;
181} 181}
182 182
183/* $Id: nslookup.c,v 1.26 2001/10/24 04:59:56 andersen Exp $ */ 183/* $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 @@
15 * Foundation; either version 2 of the License, or (at 15 * Foundation; either version 2 of the License, or (at
16 * your option) any later version. 16 * your option) any later version.
17 * 17 *
18 * $Id: route.c,v 1.13 2001/09/05 19:32:00 andersen Exp $ 18 * $Id: route.c,v 1.14 2001/11/10 11:22:43 andersen Exp $
19 * 19 *
20 * displayroute() code added by Vladimir N. Oleynik <dzo@simtreas.ru> 20 * displayroute() code added by Vladimir N. Oleynik <dzo@simtreas.ru>
21 * adjustments by Larry Doolittle <LRDoolittle@lbl.gov> 21 * adjustments by Larry Doolittle <LRDoolittle@lbl.gov>
@@ -23,11 +23,9 @@
23 23
24#include <sys/types.h> 24#include <sys/types.h>
25#include <sys/ioctl.h> 25#include <sys/ioctl.h>
26#include <sys/socket.h> 26#include "inet_common.h"
27#include <net/route.h> 27#include <net/route.h>
28#include <linux/param.h> // HZ 28#include <linux/param.h> // HZ
29#include <netinet/in.h>
30#include <arpa/inet.h>
31#include <stdio.h> 29#include <stdio.h>
32#include <errno.h> 30#include <errno.h>
33#include <fcntl.h> 31#include <fcntl.h>
@@ -55,29 +53,6 @@
55#define E_INTERN 2 53#define E_INTERN 2
56#define E_NOSUPP 1 54#define E_NOSUPP 1
57 55
58/* resolve XXX.YYY.ZZZ.QQQ -> binary */
59
60static int
61INET_resolve(char *name, struct sockaddr *sa)
62{
63 struct sockaddr_in *s_in = (struct sockaddr_in *)sa;
64
65 s_in->sin_family = AF_INET;
66 s_in->sin_port = 0;
67
68 /* Default is special, meaning 0.0.0.0. */
69 if (strcmp(name, "default")==0) {
70 s_in->sin_addr.s_addr = INADDR_ANY;
71 return 1;
72 }
73 /* Look to see if it's a dotted quad. */
74 if (inet_aton(name, &s_in->sin_addr)) {
75 return 0;
76 }
77 /* guess not.. */
78 return -1;
79}
80
81#if defined (SIOCADDRTOLD) || defined (RTF_IRTT) /* route */ 56#if defined (SIOCADDRTOLD) || defined (RTF_IRTT) /* route */
82#define HAVE_NEW_ADDRT 1 57#define HAVE_NEW_ADDRT 1
83#endif 58#endif
@@ -96,13 +71,16 @@ INET_resolve(char *name, struct sockaddr *sa)
96#define full_mask(x) (((struct sockaddr_in *)&(x))->sin_addr.s_addr) 71#define full_mask(x) (((struct sockaddr_in *)&(x))->sin_addr.s_addr)
97#endif 72#endif
98 73
74
75
99/* add or delete a route depending on action */ 76/* add or delete a route depending on action */
100 77
101static int 78static int
102INET_setroute(int action, int options, char **args) 79INET_setroute(int action, int options, char **args)
103{ 80{
104 struct rtentry rt; 81 struct rtentry rt;
105 char target[128], gateway[128] = "NONE", netmask[128] = "default"; 82 char target[128], gateway[128] = "NONE";
83 const char *netmask = bb_INET_default;
106 int xflag, isnet; 84 int xflag, isnet;
107 int skfd; 85 int skfd;
108 86
@@ -117,13 +95,15 @@ INET_setroute(int action, int options, char **args)
117 xflag = 2; 95 xflag = 2;
118 args++; 96 args++;
119 } 97 }
98 if (*args == NULL)
99 show_usage();
120 safe_strncpy(target, *args++, (sizeof target)); 100 safe_strncpy(target, *args++, (sizeof target));
121 101
122 /* Clean out the RTREQ structure. */ 102 /* Clean out the RTREQ structure. */
123 memset((char *) &rt, 0, sizeof(struct rtentry)); 103 memset((char *) &rt, 0, sizeof(struct rtentry));
124 104
125 105
126 if ((isnet = INET_resolve(target, &rt.rt_dst)) < 0) { 106 if ((isnet = INET_resolve(target, (struct sockaddr_in *)&rt.rt_dst, xflag!=1)) < 0) {
127 error_msg(_("can't resolve %s"), target); 107 error_msg(_("can't resolve %s"), target);
128 return EXIT_FAILURE; /* XXX change to E_something */ 108 return EXIT_FAILURE; /* XXX change to E_something */
129 } 109 }
@@ -169,8 +149,8 @@ INET_setroute(int action, int options, char **args)
169 args++; 149 args++;
170 if (!*args || mask_in_addr(rt)) 150 if (!*args || mask_in_addr(rt))
171 show_usage(); 151 show_usage();
172 safe_strncpy(netmask, *args, (sizeof netmask)); 152 netmask = *args;
173 if ((isnet = INET_resolve(netmask, &mask)) < 0) { 153 if ((isnet = INET_resolve(netmask, (struct sockaddr_in *)&mask, 0)) < 0) {
174 error_msg(_("can't resolve netmask %s"), netmask); 154 error_msg(_("can't resolve netmask %s"), netmask);
175 return E_LOOKUP; 155 return E_LOOKUP;
176 } 156 }
@@ -186,7 +166,7 @@ INET_setroute(int action, int options, char **args)
186 if (rt.rt_flags & RTF_GATEWAY) 166 if (rt.rt_flags & RTF_GATEWAY)
187 show_usage(); 167 show_usage();
188 safe_strncpy(gateway, *args, (sizeof gateway)); 168 safe_strncpy(gateway, *args, (sizeof gateway));
189 if ((isnet = INET_resolve(gateway, &rt.rt_gateway)) < 0) { 169 if ((isnet = INET_resolve(gateway, (struct sockaddr_in *)&rt.rt_gateway, 1)) < 0) {
190 error_msg(_("can't resolve gw %s"), gateway); 170 error_msg(_("can't resolve gw %s"), gateway);
191 return E_LOOKUP; 171 return E_LOOKUP;
192 } 172 }
@@ -362,7 +342,7 @@ INET_setroute(int action, int options, char **args)
362#define RTF_REJECT 0x0200 /* Reject route */ 342#define RTF_REJECT 0x0200 /* Reject route */
363#endif 343#endif
364 344
365static void displayroutes(void) 345static void displayroutes(int noresolve)
366{ 346{
367 char buff[256]; 347 char buff[256];
368 int nl = 0 ; 348 int nl = 0 ;
@@ -375,12 +355,17 @@ static void displayroutes(void)
375 355
376 char sdest[16], sgw[16]; 356 char sdest[16], sgw[16];
377 357
378
379 FILE *fp = xfopen("/proc/net/route", "r"); 358 FILE *fp = xfopen("/proc/net/route", "r");
380 359
360 if(noresolve)
361 noresolve = 0x0fff;
362
381 while( fgets(buff, sizeof(buff), fp) != NULL ) { 363 while( fgets(buff, sizeof(buff), fp) != NULL ) {
382 if(nl) { 364 if(nl) {
383 int ifl = 0; 365 int ifl = 0;
366 int numeric;
367 struct sockaddr_in s_addr;
368
384 while(buff[ifl]!=' ' && buff[ifl]!='\t' && buff[ifl]!='\0') 369 while(buff[ifl]!=' ' && buff[ifl]!='\t' && buff[ifl]!='\0')
385 ifl++; 370 ifl++;
386 buff[ifl]=0; /* interface */ 371 buff[ifl]=0; /* interface */
@@ -412,10 +397,14 @@ static void displayroutes(void)
412 dest.s_addr = d; 397 dest.s_addr = d;
413 gw.s_addr = g; 398 gw.s_addr = g;
414 mask.s_addr = m; 399 mask.s_addr = m;
415 strcpy(sdest, (dest.s_addr==0 ? "default" : 400 memset(&s_addr, 0, sizeof(struct sockaddr_in));
416 inet_ntoa(dest))); 401 s_addr.sin_family = AF_INET;
417 strcpy(sgw, (gw.s_addr==0 ? "*" : 402 s_addr.sin_addr = dest;
418 inet_ntoa(gw))); 403 numeric = noresolve | 0x8000; /* default instead of * */
404 INET_rresolve(sdest, sizeof(sdest), &s_addr, numeric, m);
405 numeric = noresolve | 0x4000; /* host instead of net */
406 s_addr.sin_addr = gw;
407 INET_rresolve(sgw, sizeof(sgw), &s_addr, numeric, m);
419 printf("%-16s%-16s%-16s%-6s%-6d %-2d %7d %s\n", 408 printf("%-16s%-16s%-16s%-6s%-6d %-2d %7d %s\n",
420 sdest, sgw, 409 sdest, sgw,
421 inet_ntoa(mask), 410 inet_ntoa(mask),
@@ -433,8 +422,8 @@ int route_main(int argc, char **argv)
433 argc--; 422 argc--;
434 argv++; 423 argv++;
435 424
436 if (*argv == NULL) { 425 if (*argv == NULL || (*(argv+1)==NULL && strcmp(*argv, "-n")==0)) {
437 displayroutes(); 426 displayroutes(*argv != NULL);
438 return EXIT_SUCCESS; 427 return EXIT_SUCCESS;
439 } else { 428 } else {
440 /* check verb */ 429 /* 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;
112static struct Globalvars G; 112static struct Globalvars G;
113#endif 113#endif
114 114
115static inline void iacflush() 115static inline void iacflush(void)
116{ 116{
117 write(G.netfd, G.iacbuf, G.iaclen); 117 write(G.netfd, G.iacbuf, G.iaclen);
118 G.iaclen = 0; 118 G.iaclen = 0;
@@ -121,13 +121,12 @@ static inline void iacflush()
121/* Function prototypes */ 121/* Function prototypes */
122static int getport(char * p); 122static int getport(char * p);
123static struct in_addr getserver(char * p); 123static struct in_addr getserver(char * p);
124static int create_socket();
125static void setup_sockaddr_in(struct sockaddr_in * addr, int port); 124static void setup_sockaddr_in(struct sockaddr_in * addr, int port);
126static int remote_connect(struct in_addr addr, int port); 125static int remote_connect(struct in_addr addr, int port);
127static void rawmode(); 126static void rawmode(void);
128static void cookmode(); 127static void cookmode(void);
129static void do_linemode(); 128static void do_linemode(void);
130static void will_charmode(); 129static void will_charmode(void);
131static void telopt(byte c); 130static void telopt(byte c);
132static int subneg(byte c); 131static int subneg(byte c);
133#if 0 132#if 0
@@ -147,7 +146,7 @@ static void doexit(int ev)
147 exit(ev); 146 exit(ev);
148} 147}
149 148
150static void conescape() 149static void conescape(void)
151{ 150{
152 char b; 151 char b;
153 152
@@ -353,7 +352,7 @@ static void putiac_subopt(byte c, char *str)
353 352
354static char const escapecharis[] = "\r\nEscape character is "; 353static char const escapecharis[] = "\r\nEscape character is ";
355 354
356static void setConMode() 355static void setConMode(void)
357{ 356{
358 if (G.telflags & UF_ECHO) 357 if (G.telflags & UF_ECHO)
359 { 358 {
@@ -375,7 +374,7 @@ static void setConMode()
375 374
376/* ******************************* */ 375/* ******************************* */
377 376
378static void will_charmode() 377static void will_charmode(void)
379{ 378{
380 G.charmode = CHM_TRY; 379 G.charmode = CHM_TRY;
381 G.telflags |= (UF_ECHO | UF_SGA); 380 G.telflags |= (UF_ECHO | UF_SGA);
@@ -386,7 +385,7 @@ static void will_charmode()
386 iacflush(); 385 iacflush();
387} 386}
388 387
389static void do_linemode() 388static void do_linemode(void)
390{ 389{
391 G.charmode = CHM_TRY; 390 G.charmode = CHM_TRY;
392 G.telflags &= ~(UF_ECHO | UF_SGA); 391 G.telflags &= ~(UF_ECHO | UF_SGA);
@@ -405,7 +404,7 @@ static inline void to_notsup(char c)
405 else if (G.telwish == DO) putiac2(WONT, c); 404 else if (G.telwish == DO) putiac2(WONT, c);
406} 405}
407 406
408static inline void to_echo() 407static inline void to_echo(void)
409{ 408{
410 /* if server requests ECHO, don't agree */ 409 /* if server requests ECHO, don't agree */
411 if (G.telwish == DO) { putiac2(WONT, TELOPT_ECHO); return; } 410 if (G.telwish == DO) { putiac2(WONT, TELOPT_ECHO); return; }
@@ -432,7 +431,7 @@ static inline void to_echo()
432 WriteCS(1, "\r\n"); /* sudden modec */ 431 WriteCS(1, "\r\n"); /* sudden modec */
433} 432}
434 433
435static inline void to_sga() 434static inline void to_sga(void)
436{ 435{
437 /* daemon always sends will/wont, client do/dont */ 436 /* daemon always sends will/wont, client do/dont */
438 437
@@ -454,7 +453,7 @@ static inline void to_sga()
454} 453}
455 454
456#ifdef CONFIG_FEATURE_TELNET_TTYPE 455#ifdef CONFIG_FEATURE_TELNET_TTYPE
457static inline void to_ttype() 456static inline void to_ttype(void)
458{ 457{
459 /* Tell server we will (or won't) do TTYPE */ 458 /* Tell server we will (or won't) do TTYPE */
460 459
@@ -471,10 +470,10 @@ static void telopt(byte c)
471{ 470{
472 switch (c) 471 switch (c)
473 { 472 {
474 case TELOPT_ECHO: to_echo(c); break; 473 case TELOPT_ECHO: to_echo(); break;
475 case TELOPT_SGA: to_sga(c); break; 474 case TELOPT_SGA: to_sga(); break;
476#ifdef CONFIG_FEATURE_TELNET_TTYPE 475#ifdef CONFIG_FEATURE_TELNET_TTYPE
477 case TELOPT_TTYPE: to_ttype(c); break; 476 case TELOPT_TTYPE: to_ttype(); break;
478#endif 477#endif
479 default: to_notsup(c); break; 478 default: to_notsup(c); break;
480 } 479 }
@@ -515,12 +514,12 @@ static void fgotsig(int sig)
515} 514}
516 515
517 516
518static void rawmode() 517static void rawmode(void)
519{ 518{
520 tcsetattr(0, TCSADRAIN, &G.termios_raw); 519 tcsetattr(0, TCSADRAIN, &G.termios_raw);
521} 520}
522 521
523static void cookmode() 522static void cookmode(void)
524{ 523{
525 tcsetattr(0, TCSADRAIN, &G.termios_def); 524 tcsetattr(0, TCSADRAIN, &G.termios_def);
526} 525}
@@ -650,7 +649,7 @@ static struct in_addr getserver(char * host)
650 return addr; 649 return addr;
651} 650}
652 651
653static int create_socket() 652static int create_socket(void)
654{ 653{
655 return socket(AF_INET, SOCK_STREAM, 0); 654 return socket(AF_INET, SOCK_STREAM, 0);
656} 655}
@@ -708,4 +707,3 @@ c-basic-offset: 4
708tab-width: 4 707tab-width: 4
709End: 708End:
710*/ 709*/
711
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 @@
72#include <string.h> 72#include <string.h>
73#include <unistd.h> 73#include <unistd.h>
74#include <sys/time.h> 74#include <sys/time.h>
75#include <sys/types.h> 75#include "inet_common.h"
76#include <sys/socket.h>
77#include <netdb.h> 76#include <netdb.h>
78#include <endian.h> 77#include <endian.h>
79#include <arpa/inet.h>
80#include <netinet/udp.h> 78#include <netinet/udp.h>
81#include <netinet/ip.h> 79#include <netinet/ip.h>
82#include <netinet/ip_icmp.h> 80#include <netinet/ip_icmp.h>
@@ -228,8 +226,8 @@ static inline void
228inetname(struct sockaddr_in *from) 226inetname(struct sockaddr_in *from)
229{ 227{
230 char *cp; 228 char *cp;
231 struct hostent *hp;
232 static char domain[MAXHOSTNAMELEN + 1]; 229 static char domain[MAXHOSTNAMELEN + 1];
230 char name[MAXHOSTNAMELEN + 1];
233 static int first = 1; 231 static int first = 1;
234 const char *ina; 232 const char *ina;
235 233
@@ -243,12 +241,11 @@ inetname(struct sockaddr_in *from)
243 } 241 }
244 cp = 0; 242 cp = 0;
245 if (!nflag && from->sin_addr.s_addr != INADDR_ANY) { 243 if (!nflag && from->sin_addr.s_addr != INADDR_ANY) {
246 hp = gethostbyaddr((char *)&(from->sin_addr), sizeof (from->sin_addr), AF_INET); 244 if(INET_rresolve(name, sizeof(name), from, 0, 0xffffffff) >= 0) {
247 if (hp) { 245 if ((cp = strchr(name, '.')) &&
248 if ((cp = strchr(hp->h_name, '.')) &&
249 !strcmp(cp + 1, domain)) 246 !strcmp(cp + 1, domain))
250 *cp = 0; 247 *cp = 0;
251 cp = (char *)hp->h_name; 248 cp = (char *)name;
252 } 249 }
253 } 250 }
254 ina = inet_ntoa(from->sin_addr); 251 ina = inet_ntoa(from->sin_addr);
@@ -645,7 +642,7 @@ traceroute_main(argc, argv)
645 } 642 }
646 putchar('\n'); 643 putchar('\n');
647 if (got_there || unreachable >= nprobes-1) 644 if (got_there || unreachable >= nprobes-1)
648 exit(0); 645 return 0;
649 } 646 }
650 647
651 return 0; 648 return 0;