diff options
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/Makefile | 4 | ||||
-rw-r--r-- | libbb/interface.c | 197 |
2 files changed, 8 insertions, 193 deletions
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 | ||
66 | clean: | 66 | clean: |
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 | ||
92 | static int procnetdev_vsn = 1; | 83 | static 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 | ||
317 | extern int h_errno; /* some netdb.h versions don't export this */ | ||
318 | #endif | ||
319 | |||
320 | /* cache */ | ||
321 | struct addr { | ||
322 | struct sockaddr_in addr; | ||
323 | char *name; | ||
324 | int host; | ||
325 | struct addr *next; | ||
326 | }; | ||
327 | |||
328 | static struct addr *INET_nn = NULL; /* addr-to-name cache */ | ||
329 | |||
330 | #ifdef KEEP_UNUSED | ||
331 | static 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 | */ | ||
395 | static 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 |
481 | static void INET_reserror(char *text) | 298 | static void INET_reserror(char *text) |
482 | { | 299 | { |