aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-04-19 16:55:27 +0000
committerEric Andersen <andersen@codepoet.org>2001-04-19 16:55:27 +0000
commit46cd74b9e3bf0ed842f4e6f2e5a8b8f364e3ad4c (patch)
tree8262e023a17fdaf0dc5982d7d49d801c6596a2d4
parent3ce79338e66d37e9313c0a4bde78d21822402c09 (diff)
downloadbusybox-w32-46cd74b9e3bf0ed842f4e6f2e5a8b8f364e3ad4c.tar.gz
busybox-w32-46cd74b9e3bf0ed842f4e6f2e5a8b8f364e3ad4c.tar.bz2
busybox-w32-46cd74b9e3bf0ed842f4e6f2e5a8b8f364e3ad4c.zip
This has two patches. First it moves interface.c to libbb (it is
support code after all). It also contains a patch from Larry Doolittle that removes two instances of "strlen([^)]*) *- *1", un-shadows two variables, relaxes requirement for a sprintf(3) that returns number of bytes written, and eliminates a duplicate subroutine.
-rw-r--r--Config.h8
-rw-r--r--Config.h.Hurd8
-rw-r--r--Makefile2
-rw-r--r--debian/Config.h-deb8
-rw-r--r--debian/Config.h-static8
-rw-r--r--debian/Config.h-udeb8
-rw-r--r--libbb/interface.c (renamed from interface.c)57
7 files changed, 24 insertions, 75 deletions
diff --git a/Config.h b/Config.h
index bf477f600..8c80f8e87 100644
--- a/Config.h
+++ b/Config.h
@@ -396,14 +396,6 @@
396 #define BB_NFSMOUNT 396 #define BB_NFSMOUNT
397#endif 397#endif
398// 398//
399#if defined BB_IFCONFIG
400 #ifdef BB_FEATURE_IFCONFIG_STATUS
401 #define BB_INTERFACE
402 #endif
403#else
404 #undef BB_INTERFACE
405#endif
406//
407#if defined BB_FEATURE_AUTOWIDTH 399#if defined BB_FEATURE_AUTOWIDTH
408 #ifndef BB_FEATURE_USE_TERMIOS 400 #ifndef BB_FEATURE_USE_TERMIOS
409 #define BB_FEATURE_USE_TERMIOS 401 #define BB_FEATURE_USE_TERMIOS
diff --git a/Config.h.Hurd b/Config.h.Hurd
index 369e376cd..43d59e069 100644
--- a/Config.h.Hurd
+++ b/Config.h.Hurd
@@ -345,14 +345,6 @@
345 #define BB_NFSMOUNT 345 #define BB_NFSMOUNT
346#endif 346#endif
347// 347//
348#if defined BB_IFCONFIG
349 #ifdef BB_FEATURE_IFCONFIG_STATUS
350 #define BB_INTERFACE
351 #endif
352#else
353 #undef BB_INTERFACE
354#endif
355//
356#if defined BB_FEATURE_AUTOWIDTH 348#if defined BB_FEATURE_AUTOWIDTH
357 #ifndef BB_FEATURE_USE_TERMIOS 349 #ifndef BB_FEATURE_USE_TERMIOS
358 #define BB_FEATURE_USE_TERMIOS 350 #define BB_FEATURE_USE_TERMIOS
diff --git a/Makefile b/Makefile
index 18c174f70..1fefecd10 100644
--- a/Makefile
+++ b/Makefile
@@ -247,7 +247,7 @@ parse_mode.c parse_number.c perror_msg.c perror_msg_and_die.c print_file.c \
247process_escape_sequence.c read_package_field.c read_text_file_to_buffer.c \ 247process_escape_sequence.c read_package_field.c read_text_file_to_buffer.c \
248recursive_action.c safe_read.c safe_strncpy.c seek_ared_file.c syscalls.c \ 248recursive_action.c safe_read.c safe_strncpy.c seek_ared_file.c syscalls.c \
249syslog_msg_with_name.c time_string.c trim.c untar.c unzip.c vdprintf.c \ 249syslog_msg_with_name.c time_string.c trim.c untar.c unzip.c vdprintf.c \
250verror_msg.c vperror_msg.c wfopen.c xfuncs.c xgetcwd.c xregcomp.c 250verror_msg.c vperror_msg.c wfopen.c xfuncs.c xgetcwd.c xregcomp.c interface.c
251 251
252LIBBB_OBJS=$(patsubst %.c,$(LIBBB)/%.o, $(LIBBB_CSRC)) 252LIBBB_OBJS=$(patsubst %.c,$(LIBBB)/%.o, $(LIBBB_CSRC))
253LIBBB_CFLAGS = -I$(LIBBB) 253LIBBB_CFLAGS = -I$(LIBBB)
diff --git a/debian/Config.h-deb b/debian/Config.h-deb
index 7737804c8..44046aa5d 100644
--- a/debian/Config.h-deb
+++ b/debian/Config.h-deb
@@ -413,14 +413,6 @@
413 #define BB_NFSMOUNT 413 #define BB_NFSMOUNT
414#endif 414#endif
415// 415//
416#if defined BB_IFCONFIG
417 #ifdef BB_FEATURE_IFCONFIG_STATUS
418 #define BB_INTERFACE
419 #endif
420#else
421 #undef BB_INTERFACE
422#endif
423//
424#if defined BB_FEATURE_AUTOWIDTH 416#if defined BB_FEATURE_AUTOWIDTH
425 #ifndef BB_FEATURE_USE_TERMIOS 417 #ifndef BB_FEATURE_USE_TERMIOS
426 #define BB_FEATURE_USE_TERMIOS 418 #define BB_FEATURE_USE_TERMIOS
diff --git a/debian/Config.h-static b/debian/Config.h-static
index c811b2b87..79dfbc8dd 100644
--- a/debian/Config.h-static
+++ b/debian/Config.h-static
@@ -413,14 +413,6 @@
413 #define BB_NFSMOUNT 413 #define BB_NFSMOUNT
414#endif 414#endif
415// 415//
416#if defined BB_IFCONFIG
417 #ifdef BB_FEATURE_IFCONFIG_STATUS
418 #define BB_INTERFACE
419 #endif
420#else
421 #undef BB_INTERFACE
422#endif
423//
424#if defined BB_FEATURE_AUTOWIDTH 416#if defined BB_FEATURE_AUTOWIDTH
425 #ifndef BB_FEATURE_USE_TERMIOS 417 #ifndef BB_FEATURE_USE_TERMIOS
426 #define BB_FEATURE_USE_TERMIOS 418 #define BB_FEATURE_USE_TERMIOS
diff --git a/debian/Config.h-udeb b/debian/Config.h-udeb
index 14901ed02..beb7d8176 100644
--- a/debian/Config.h-udeb
+++ b/debian/Config.h-udeb
@@ -413,14 +413,6 @@
413 #define BB_NFSMOUNT 413 #define BB_NFSMOUNT
414#endif 414#endif
415// 415//
416#if defined BB_IFCONFIG
417 #ifdef BB_FEATURE_IFCONFIG_STATUS
418 #define BB_INTERFACE
419 #endif
420#else
421 #undef BB_INTERFACE
422#endif
423//
424#if defined BB_FEATURE_AUTOWIDTH 416#if defined BB_FEATURE_AUTOWIDTH
425 #ifndef BB_FEATURE_USE_TERMIOS 417 #ifndef BB_FEATURE_USE_TERMIOS
426 #define BB_FEATURE_USE_TERMIOS 418 #define BB_FEATURE_USE_TERMIOS
diff --git a/interface.c b/libbb/interface.c
index a043d7223..b453b6f67 100644
--- a/interface.c
+++ b/libbb/interface.c
@@ -3,7 +3,7 @@
3 * that either displays or sets the characteristics of 3 * that either displays or sets the characteristics of
4 * one or more of the system's networking interfaces. 4 * one or more of the system's networking interfaces.
5 * 5 *
6 * Version: $Id: interface.c,v 1.6 2001/04/09 23:52:18 andersen Exp $ 6 * Version: $Id: interface.c,v 1.1 2001/04/19 16:55:27 andersen Exp $
7 * 7 *
8 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> 8 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
9 * and others. Copyright 1993 MicroWalt Corporation 9 * and others. Copyright 1993 MicroWalt Corporation
@@ -37,7 +37,7 @@
37 37
38/* #define KEEP_UNUSED */ 38/* #define KEEP_UNUSED */
39 39
40#include "busybox.h" 40#include "libbb.h"
41 41
42/* 42/*
43 * 43 *
@@ -353,7 +353,7 @@ static int INET_resolve(char *name, struct sockaddr_in *sin, int hostfirst)
353 * & 0x4000: host instead of net, 353 * & 0x4000: host instead of net,
354 * & 0x0fff: don't resolve 354 * & 0x0fff: don't resolve
355 */ 355 */
356static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin, 356static int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in,
357 int numeric, unsigned int netmask) 357 int numeric, unsigned int netmask)
358{ 358{
359 struct hostent *ent; 359 struct hostent *ent;
@@ -363,14 +363,14 @@ static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin,
363 int host = 0; 363 int host = 0;
364 364
365 /* Grmpf. -FvK */ 365 /* Grmpf. -FvK */
366 if (sin->sin_family != AF_INET) { 366 if (s_in->sin_family != AF_INET) {
367#ifdef DEBUG 367#ifdef DEBUG
368 fprintf(stderr, _("rresolve: unsupport address family %d !\n"), sin->sin_family); 368 fprintf(stderr, _("rresolve: unsupport address family %d !\n"), s_in->sin_family);
369#endif 369#endif
370 errno = EAFNOSUPPORT; 370 errno = EAFNOSUPPORT;
371 return (-1); 371 return (-1);
372 } 372 }
373 ad = (unsigned long) sin->sin_addr.s_addr; 373 ad = (unsigned long) s_in->sin_addr.s_addr;
374#ifdef DEBUG 374#ifdef DEBUG
375 fprintf (stderr, "rresolve: %08lx, mask %08x, num %08x \n", ad, netmask, numeric); 375 fprintf (stderr, "rresolve: %08lx, mask %08x, num %08x \n", ad, netmask, numeric);
376#endif 376#endif
@@ -384,7 +384,7 @@ static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin,
384 } 384 }
385 } 385 }
386 if (numeric & 0x0FFF) { 386 if (numeric & 0x0FFF) {
387 safe_strncpy(name, inet_ntoa(sin->sin_addr), len); 387 safe_strncpy(name, inet_ntoa(s_in->sin_addr), len);
388 return (0); 388 return (0);
389 } 389 }
390 390
@@ -424,9 +424,9 @@ static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin,
424 safe_strncpy(name, np->n_name, len); 424 safe_strncpy(name, np->n_name, len);
425 } 425 }
426 if ((ent == NULL) && (np == NULL)) 426 if ((ent == NULL) && (np == NULL))
427 safe_strncpy(name, inet_ntoa(sin->sin_addr), len); 427 safe_strncpy(name, inet_ntoa(s_in->sin_addr), len);
428 pn = (struct addr *) xmalloc(sizeof(struct addr)); 428 pn = (struct addr *) xmalloc(sizeof(struct addr));
429 pn->addr = *sin; 429 pn->addr = *s_in;
430 pn->next = INET_nn; 430 pn->next = INET_nn;
431 pn->host = host; 431 pn->host = host;
432 pn->name = (char *) xmalloc(strlen(name) + 1); 432 pn->name = (char *) xmalloc(strlen(name) + 1);
@@ -570,15 +570,18 @@ static struct aftype inet_aftype =
570/* Display an UNSPEC address. */ 570/* Display an UNSPEC address. */
571static char *UNSPEC_print(unsigned char *ptr) 571static char *UNSPEC_print(unsigned char *ptr)
572{ 572{
573 static char buff[64]; 573 static char buff[sizeof(struct sockaddr)*3+1];
574 char *pos; 574 char *pos;
575 unsigned int i; 575 unsigned int i;
576 576
577 pos = buff; 577 pos = buff;
578 for (i = 0; i < sizeof(struct sockaddr); i++) { 578 for (i = 0; i < sizeof(struct sockaddr); i++) {
579 pos += sprintf(pos, "%02X-", (*ptr++ & 0377)); 579 /* careful -- not every libc's sprintf returns # bytes written */
580 sprintf(pos, "%02X-", (*ptr++ & 0377));
581 pos += 3;
580 } 582 }
581 buff[strlen(buff) - 1] = '\0'; 583 /* Erase trailing "-". Works as long as sizeof(struct sockaddr) != 0 */
584 *--pos = '\0';
582 return (buff); 585 return (buff);
583} 586}
584 587
@@ -1029,17 +1032,18 @@ static int if_readconf(void)
1029 struct ifconf ifc; 1032 struct ifconf ifc;
1030 struct ifreq *ifr; 1033 struct ifreq *ifr;
1031 int n, err = -1; 1034 int n, err = -1;
1032 int skfd; 1035 /* XXX Should this re-use the global skfd? */
1036 int skfd2;
1033 1037
1034 /* SIOCGIFCONF currently seems to only work properly on AF_INET sockets 1038 /* SIOCGIFCONF currently seems to only work properly on AF_INET sockets
1035 (as of 2.1.128) */ 1039 (as of 2.1.128) */
1036 skfd = get_socket_for_af(AF_INET); 1040 skfd2 = get_socket_for_af(AF_INET);
1037 if (skfd < 0) { 1041 if (skfd2 < 0) {
1038 fprintf(stderr, _("warning: no inet socket available: %s\n"), 1042 fprintf(stderr, _("warning: no inet socket available: %s\n"),
1039 strerror(errno)); 1043 strerror(errno));
1040 /* Try to soldier on with whatever socket we can get hold of. */ 1044 /* Try to soldier on with whatever socket we can get hold of. */
1041 skfd = sockets_open(0); 1045 skfd2 = sockets_open(0);
1042 if (skfd < 0) 1046 if (skfd2 < 0)
1043 return -1; 1047 return -1;
1044 } 1048 }
1045 1049
@@ -1048,7 +1052,7 @@ static int if_readconf(void)
1048 ifc.ifc_len = sizeof(struct ifreq) * numreqs; 1052 ifc.ifc_len = sizeof(struct ifreq) * numreqs;
1049 ifc.ifc_buf = xrealloc(ifc.ifc_buf, ifc.ifc_len); 1053 ifc.ifc_buf = xrealloc(ifc.ifc_buf, ifc.ifc_len);
1050 1054
1051 if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) { 1055 if (ioctl(skfd2, SIOCGIFCONF, &ifc) < 0) {
1052 perror("SIOCGIFCONF"); 1056 perror("SIOCGIFCONF");
1053 goto out; 1057 goto out;
1054 } 1058 }
@@ -1466,25 +1470,10 @@ struct hwtype {
1466 int suppress_null_addr; 1470 int suppress_null_addr;
1467}; 1471};
1468 1472
1469/* Display an UNSPEC address. */
1470static char *pr_unspec(unsigned char *ptr)
1471{
1472 static char buff[64];
1473 char *pos;
1474 unsigned int i;
1475
1476 pos = buff;
1477 for (i = 0; i < sizeof(struct sockaddr); i++) {
1478 pos += sprintf(pos, "%02X-", (*ptr++ & 0377));
1479 }
1480 buff[strlen(buff) - 1] = '\0';
1481 return (buff);
1482}
1483
1484static struct hwtype unspec_hwtype = 1473static struct hwtype unspec_hwtype =
1485{ 1474{
1486 "unspec", "UNSPEC", -1, 0, 1475 "unspec", "UNSPEC", -1, 0,
1487 pr_unspec, NULL, NULL 1476 UNSPEC_print, NULL, NULL
1488}; 1477};
1489 1478
1490static struct hwtype loop_hwtype = 1479static struct hwtype loop_hwtype =