summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen2001-04-19 16:55:27 +0000
committerEric Andersen2001-04-19 16:55:27 +0000
commit46cd74b9e3bf0ed842f4e6f2e5a8b8f364e3ad4c (patch)
tree8262e023a17fdaf0dc5982d7d49d801c6596a2d4
parent3ce79338e66d37e9313c0a4bde78d21822402c09 (diff)
downloadbusybox-46cd74b9e3bf0ed842f4e6f2e5a8b8f364e3ad4c.zip
busybox-46cd74b9e3bf0ed842f4e6f2e5a8b8f364e3ad4c.tar.gz
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 bf477f6..8c80f8e 100644
--- a/Config.h
+++ b/Config.h
@@ -396,14 +396,6 @@
#define BB_NFSMOUNT
#endif
//
-#if defined BB_IFCONFIG
- #ifdef BB_FEATURE_IFCONFIG_STATUS
- #define BB_INTERFACE
- #endif
-#else
- #undef BB_INTERFACE
-#endif
-//
#if defined BB_FEATURE_AUTOWIDTH
#ifndef BB_FEATURE_USE_TERMIOS
#define BB_FEATURE_USE_TERMIOS
diff --git a/Config.h.Hurd b/Config.h.Hurd
index 369e376..43d59e0 100644
--- a/Config.h.Hurd
+++ b/Config.h.Hurd
@@ -345,14 +345,6 @@
#define BB_NFSMOUNT
#endif
//
-#if defined BB_IFCONFIG
- #ifdef BB_FEATURE_IFCONFIG_STATUS
- #define BB_INTERFACE
- #endif
-#else
- #undef BB_INTERFACE
-#endif
-//
#if defined BB_FEATURE_AUTOWIDTH
#ifndef BB_FEATURE_USE_TERMIOS
#define BB_FEATURE_USE_TERMIOS
diff --git a/Makefile b/Makefile
index 18c174f..1fefecd 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 \
process_escape_sequence.c read_package_field.c read_text_file_to_buffer.c \
recursive_action.c safe_read.c safe_strncpy.c seek_ared_file.c syscalls.c \
syslog_msg_with_name.c time_string.c trim.c untar.c unzip.c vdprintf.c \
-verror_msg.c vperror_msg.c wfopen.c xfuncs.c xgetcwd.c xregcomp.c
+verror_msg.c vperror_msg.c wfopen.c xfuncs.c xgetcwd.c xregcomp.c interface.c
LIBBB_OBJS=$(patsubst %.c,$(LIBBB)/%.o, $(LIBBB_CSRC))
LIBBB_CFLAGS = -I$(LIBBB)
diff --git a/debian/Config.h-deb b/debian/Config.h-deb
index 7737804..44046aa 100644
--- a/debian/Config.h-deb
+++ b/debian/Config.h-deb
@@ -413,14 +413,6 @@
#define BB_NFSMOUNT
#endif
//
-#if defined BB_IFCONFIG
- #ifdef BB_FEATURE_IFCONFIG_STATUS
- #define BB_INTERFACE
- #endif
-#else
- #undef BB_INTERFACE
-#endif
-//
#if defined BB_FEATURE_AUTOWIDTH
#ifndef BB_FEATURE_USE_TERMIOS
#define BB_FEATURE_USE_TERMIOS
diff --git a/debian/Config.h-static b/debian/Config.h-static
index c811b2b..79dfbc8 100644
--- a/debian/Config.h-static
+++ b/debian/Config.h-static
@@ -413,14 +413,6 @@
#define BB_NFSMOUNT
#endif
//
-#if defined BB_IFCONFIG
- #ifdef BB_FEATURE_IFCONFIG_STATUS
- #define BB_INTERFACE
- #endif
-#else
- #undef BB_INTERFACE
-#endif
-//
#if defined BB_FEATURE_AUTOWIDTH
#ifndef BB_FEATURE_USE_TERMIOS
#define BB_FEATURE_USE_TERMIOS
diff --git a/debian/Config.h-udeb b/debian/Config.h-udeb
index 14901ed..beb7d81 100644
--- a/debian/Config.h-udeb
+++ b/debian/Config.h-udeb
@@ -413,14 +413,6 @@
#define BB_NFSMOUNT
#endif
//
-#if defined BB_IFCONFIG
- #ifdef BB_FEATURE_IFCONFIG_STATUS
- #define BB_INTERFACE
- #endif
-#else
- #undef BB_INTERFACE
-#endif
-//
#if defined BB_FEATURE_AUTOWIDTH
#ifndef BB_FEATURE_USE_TERMIOS
#define BB_FEATURE_USE_TERMIOS
diff --git a/interface.c b/libbb/interface.c
index a043d72..b453b6f 100644
--- a/interface.c
+++ b/libbb/interface.c
@@ -3,7 +3,7 @@
* that either displays or sets the characteristics of
* one or more of the system's networking interfaces.
*
- * Version: $Id: interface.c,v 1.6 2001/04/09 23:52:18 andersen Exp $
+ * Version: $Id: interface.c,v 1.1 2001/04/19 16:55:27 andersen Exp $
*
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
* and others. Copyright 1993 MicroWalt Corporation
@@ -37,7 +37,7 @@
/* #define KEEP_UNUSED */
-#include "busybox.h"
+#include "libbb.h"
/*
*
@@ -353,7 +353,7 @@ static int INET_resolve(char *name, struct sockaddr_in *sin, int hostfirst)
* & 0x4000: host instead of net,
* & 0x0fff: don't resolve
*/
-static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin,
+static int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in,
int numeric, unsigned int netmask)
{
struct hostent *ent;
@@ -363,14 +363,14 @@ static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin,
int host = 0;
/* Grmpf. -FvK */
- if (sin->sin_family != AF_INET) {
+ if (s_in->sin_family != AF_INET) {
#ifdef DEBUG
- fprintf(stderr, _("rresolve: unsupport address family %d !\n"), sin->sin_family);
+ fprintf(stderr, _("rresolve: unsupport address family %d !\n"), s_in->sin_family);
#endif
errno = EAFNOSUPPORT;
return (-1);
}
- ad = (unsigned long) sin->sin_addr.s_addr;
+ ad = (unsigned long) s_in->sin_addr.s_addr;
#ifdef DEBUG
fprintf (stderr, "rresolve: %08lx, mask %08x, num %08x \n", ad, netmask, numeric);
#endif
@@ -384,7 +384,7 @@ static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin,
}
}
if (numeric & 0x0FFF) {
- safe_strncpy(name, inet_ntoa(sin->sin_addr), len);
+ safe_strncpy(name, inet_ntoa(s_in->sin_addr), len);
return (0);
}
@@ -424,9 +424,9 @@ static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin,
safe_strncpy(name, np->n_name, len);
}
if ((ent == NULL) && (np == NULL))
- safe_strncpy(name, inet_ntoa(sin->sin_addr), len);
+ safe_strncpy(name, inet_ntoa(s_in->sin_addr), len);
pn = (struct addr *) xmalloc(sizeof(struct addr));
- pn->addr = *sin;
+ pn->addr = *s_in;
pn->next = INET_nn;
pn->host = host;
pn->name = (char *) xmalloc(strlen(name) + 1);
@@ -570,15 +570,18 @@ static struct aftype inet_aftype =
/* Display an UNSPEC address. */
static char *UNSPEC_print(unsigned char *ptr)
{
- static char buff[64];
+ static char buff[sizeof(struct sockaddr)*3+1];
char *pos;
unsigned int i;
pos = buff;
for (i = 0; i < sizeof(struct sockaddr); i++) {
- pos += sprintf(pos, "%02X-", (*ptr++ & 0377));
+ /* careful -- not every libc's sprintf returns # bytes written */
+ sprintf(pos, "%02X-", (*ptr++ & 0377));
+ pos += 3;
}
- buff[strlen(buff) - 1] = '\0';
+ /* Erase trailing "-". Works as long as sizeof(struct sockaddr) != 0 */
+ *--pos = '\0';
return (buff);
}
@@ -1029,17 +1032,18 @@ static int if_readconf(void)
struct ifconf ifc;
struct ifreq *ifr;
int n, err = -1;
- int skfd;
+ /* XXX Should this re-use the global skfd? */
+ int skfd2;
/* SIOCGIFCONF currently seems to only work properly on AF_INET sockets
(as of 2.1.128) */
- skfd = get_socket_for_af(AF_INET);
- if (skfd < 0) {
+ skfd2 = get_socket_for_af(AF_INET);
+ if (skfd2 < 0) {
fprintf(stderr, _("warning: no inet socket available: %s\n"),
strerror(errno));
/* Try to soldier on with whatever socket we can get hold of. */
- skfd = sockets_open(0);
- if (skfd < 0)
+ skfd2 = sockets_open(0);
+ if (skfd2 < 0)
return -1;
}
@@ -1048,7 +1052,7 @@ static int if_readconf(void)
ifc.ifc_len = sizeof(struct ifreq) * numreqs;
ifc.ifc_buf = xrealloc(ifc.ifc_buf, ifc.ifc_len);
- if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) {
+ if (ioctl(skfd2, SIOCGIFCONF, &ifc) < 0) {
perror("SIOCGIFCONF");
goto out;
}
@@ -1466,25 +1470,10 @@ struct hwtype {
int suppress_null_addr;
};
-/* Display an UNSPEC address. */
-static char *pr_unspec(unsigned char *ptr)
-{
- static char buff[64];
- char *pos;
- unsigned int i;
-
- pos = buff;
- for (i = 0; i < sizeof(struct sockaddr); i++) {
- pos += sprintf(pos, "%02X-", (*ptr++ & 0377));
- }
- buff[strlen(buff) - 1] = '\0';
- return (buff);
-}
-
static struct hwtype unspec_hwtype =
{
"unspec", "UNSPEC", -1, 0,
- pr_unspec, NULL, NULL
+ UNSPEC_print, NULL, NULL
};
static struct hwtype loop_hwtype =