[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
ifconfig and some minor fixes.
From: |
Sergey Poznyakoff |
Subject: |
ifconfig and some minor fixes. |
Date: |
Mon, 04 Jun 2001 14:47:35 +0300 |
Here are some minor fixes for the package. I have finally made
ifconfig work on Solaris. It was tested on following platforms:
SunOS <> 5.8 Generic sun4u sparc SUNW,Ultra-5_10
SunOS <> 5.7 Generic i86pc i386 i86pc
Some notes: I had to unconditionally add if_index.c to the build
since the generic if_nameindex function does not return any
information about interface aliases, e.g. elxl2:0. I can't propose
any reliable way to check for this in configure.in, so maybe we'd
be better off providing the replacement unconditionally...
By the way, what's <stdint.h>? It wasn't found on any system I have
access to (Solaris, SunOS, GNU/Linux, FreeBSD). Was it a typo?
Another question regarding ifconfig: is it planned to add the up/down
functionality? For example, the standard way to put an interface down
was:
ifconfig en0 down
In case of GNU ifconfig it would be something like
ifconfig --interface en0 --flags down
I suppose it would be very useful.
OK, so here goes the patch:
ChangeLog:
* configure.in, headers/acconfig.h: check for declarations of
sa_family_t and struct if_nameindex.
* ftpd/ftpd.c: MAP_FAILED is not defined on some systems
(e.g. Solaris, SunOS)
* headers/paths.h: Added missing _PATH_LOGCONF, _PATH_LOGPID,
_PATH_LOG
* ifconfig/Makefile.am: Added if_index.c to build. It seems better
to use it instead of system if_nameindex (even if available).
Solaris if_nameindex does not return interface aliases, e.g
elxl2:0, whereas the version in if_index.c always returns all
interfaces.
* ifconfig/changeif.c, ifconfig/flags.c: #include <sys/socket.h>
* ifconfig/if_index.c: fixed map_interfaces(), implemented
if_nametoindex.
* ifconfig/ifconfig.c: include <sys/socket.h>
* ifconfig/ifconfig.h, ifconfig/printif.h: removed #include <config.h>,
it caused multiple inclusions. Moved #include to *.c files.
* ifconfig/options.c: include <sys/socket.h>. Added defaults for
SYSTEM_SHORT_OPTIONS, SYSTEM_LONG_OPTIONS.
* ifconfig/options.h: Definition of struct if_nameindex for systems
lacking it.
* ifconfig/printif.c: removed include <stdint.h>,
added include <sys/socket.h>. Use ifr->ifr_addr instead of
ifr->ifr_netmask in fh_netmask(). The netmask gets returned in
both fields, but ifr_netmask is absent on some systems.
* ifconfig/system.c, ifconfig/system.h: added ifdef __sun__ clause
* ifconfig/system/generic.c: placeholder for system_configure()
* ifconfig/system/linux.c: removed include <stdint.h>
* ifconfig/system/solaris.c: fixed includes, and some minor errors.
Added system_configure().
* ifconfig/system/solaris.h: fixed includes.
* libls/print.c: Provided defaults for major() and minor() macros
for systems lacking them.
Index: configure.in
===================================================================
RCS file: /cvs/inetutils/configure.in,v
retrieving revision 1.88
diff -p -u -w -b -r1.88 configure.in
--- configure.in 2001/05/08 06:06:52 1.88
+++ configure.in 2001/06/04 11:05:30
@@ -525,6 +525,16 @@ IU_CHECK_TYPE(sig_atomic_t,
#include <signal.h> ],
:, AC_DEFINE(sig_atomic_t, int))
+IU_CHECK_TYPE(sa_family_t,
+ [ #include <sys/types.h>
+ #include <sys/socket.h> ],
+ :, AC_DEFINE(sa_family_t, unsigned int))
+
+IU_CHECK_TYPE(struct if_nameindex,
+ [ #include <net/if.h> ],
+ AC_DEFINE(HAVE_STRUCT_IF_NAMEINDEX),
+ :)
+
# See if the __PROGNAME variable is defined, otherwise use our own.
AC_CHECK_FUNC(__progname,
AC_DEFINE(HAVE___PROGNAME),
Index: ftpd/ftpd.c
===================================================================
RCS file: /cvs/inetutils/ftpd/ftpd.c,v
retrieving revision 1.46
diff -p -u -w -b -r1.46 ftpd.c
--- ftpd/ftpd.c 2000/10/31 00:52:26 1.46
+++ ftpd/ftpd.c 2001/06/04 11:05:31
@@ -125,6 +125,10 @@ static char sccsid[] = "@(#)ftpd.c 8.5 (
# define LOG_FTP LOG_DAEMON /* Use generic facility. */
#endif
+#ifndef MAP_FAILED
+# define MAP_FAILED (void*)-1
+#endif
+
#ifndef HAVE_FCLOSE_DECL
/* Some systems don't declare fclose in <stdio.h>, so do it ourselves. */
extern int fclose __P ((FILE *));
Index: headers/acconfig.h
===================================================================
RCS file: /cvs/inetutils/headers/acconfig.h,v
retrieving revision 1.30
diff -p -u -w -b -r1.30 acconfig.h
--- headers/acconfig.h 2001/06/02 15:27:14 1.30
+++ headers/acconfig.h 2001/06/04 11:05:32
@@ -261,6 +261,12 @@
<sys/types.h> & <signal.h> */
#undef sigset_t
+/* Define this to be unsigned int if sa_family_t isn't declared in
+ <sys/socket.h> */
+#undef sa_family_t
+
+#undef HAVE_STRUCT_IF_NAMEINDEX
+
/* Define this if weak references of any sort are supported. */
#undef HAVE_WEAK_REFS
/* Define this if gcc-style weak references work: ... __attribute__ ((weak)) */
Index: headers/paths.h
===================================================================
RCS file: /cvs/inetutils/headers/paths.h,v
retrieving revision 1.4
diff -p -u -w -b -r1.4 paths.h
--- headers/paths.h 2000/07/06 04:21:07 1.4
+++ headers/paths.h 2001/06/04 11:05:32
@@ -62,4 +62,8 @@
#define _PATH_VARRUN "/var/run/"
#define _PATH_VARTMP "/var/tmp/"
+#define _PATH_LOGCONF "/etc"
+#define _PATH_LOGPID "/var/run"
+#define _PATH_LOG "/var/log"
+
#endif /* !_PATHS_H_ */
Index: ifconfig/Makefile.am
===================================================================
RCS file: /cvs/inetutils/ifconfig/Makefile.am,v
retrieving revision 1.3
diff -p -u -w -b -r1.3 Makefile.am
--- ifconfig/Makefile.am 2001/05/08 06:06:52 1.3
+++ ifconfig/Makefile.am 2001/06/04 11:05:32
@@ -6,7 +6,7 @@ bin_PROGRAMS = @BUILD_IFCONFIG@
EXTRA_PROGRAMS = ifconfig
-ifconfig_SOURCES = ifconfig.c flags.c changeif.c options.c printif.c system.c
+ifconfig_SOURCES = ifconfig.c flags.c changeif.c options.c printif.c system.c
if_index.c
noinst_HEADERS = ifconfig.h flags.h options.h printif.h system.h
Index: ifconfig/changeif.c
===================================================================
RCS file: /cvs/inetutils/ifconfig/changeif.c,v
retrieving revision 1.1
diff -p -u -w -b -r1.1 changeif.c
--- ifconfig/changeif.c 2001/02/21 23:38:37 1.1
+++ ifconfig/changeif.c 2001/06/04 11:05:32
@@ -33,6 +33,7 @@
#endif
+#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <arpa/inet.h>
Index: ifconfig/flags.c
===================================================================
RCS file: /cvs/inetutils/ifconfig/flags.c,v
retrieving revision 1.2
diff -p -u -w -b -r1.2 flags.c
--- ifconfig/flags.c 2001/02/22 19:32:24 1.2
+++ ifconfig/flags.c 2001/06/04 11:05:32
@@ -31,6 +31,7 @@
# include <strings.h>
#endif
+#include <sys/socket.h>
#include <net/if.h>
#include "ifconfig.h"
Index: ifconfig/if_index.c
===================================================================
RCS file: /cvs/inetutils/ifconfig/if_index.c,v
retrieving revision 1.2
diff -p -u -w -b -r1.2 if_index.c
--- ifconfig/if_index.c 2001/02/27 03:10:48 1.2
+++ ifconfig/if_index.c 2001/06/04 11:05:32
@@ -1,4 +1,4 @@
-/* if_index.c -- an implementation of the if_* functions using SIOCGIFCONF
+/* if_nameindex.c -- an implementation of the if_* functions using SIOCGIFCONF
Copyright (C) 2001 Free Software Foundation, Inc.
@@ -23,6 +23,7 @@
#include <config.h>
#endif
#include <version.h>
+#include <assert.h>
#include <sys/stat.h>
#include <stdio.h>
@@ -48,26 +49,33 @@
#endif
#include <sys/ioctl.h>
+#include <sys/socket.h>
#include <net/if.h>
+#include <netinet/in.h>
+#include "options.h"
+#include "system.h"
+#ifndef SA_LEN
+# define SA_LEN(s) sizeof(*(s))
+/*# define SA_LEN(s) (int) (((struct sockaddr *)(s))->sa_len)*/
+#endif
+#define ifrpsize(x) \
+ ((SA_LEN(&(x)->ifr_addr) > sizeof((x)->ifr_addr)) ? \
+ sizeof(*(x)) + SA_LEN(&(x)->ifr_addr) - sizeof((x)->ifr_addr) : \
+ sizeof(*(x)))
+
#ifndef HAVE_IF_NAMEINDEX
extern char *xrealloc __P ((void *p, size_t s));
-
-struct ifmap
-{
- char name[IFNAMSIZ];
- int index;
-};
-static struct ifmap *iflist;
+static struct if_nameindex *iflist;
static int iflist_size;
static int
map_interfaces()
{
int sfd;
- struct ifmap *newlist;
+ struct if_nameindex *newlist;
struct ifconf ifc = { 0, NULL };
int last_nr = -1, nr = 0;
int bufsize, i;
@@ -113,8 +121,9 @@ map_interfaces()
buflen -= IFNAMSIZ + SA_LEN(&ifr->ifr_addr);
}
}
+ nr++;
- newlist = malloc (nr * sizeof (struct ifmap));
+ newlist = malloc (nr * sizeof (struct if_nameindex));
if (!newlist)
goto fail;
@@ -122,19 +131,21 @@ map_interfaces()
ifr = (struct ifreq *) ifc.ifc_buf;
while (ifc.ifc_len > 0)
{
- strncpy (newlist[i].name, ifr->ifr_name, IFNAMSIZ);
- newlist[i].name[IFNAMSIZ-1] = '\0';
+ newlist[i].if_name = strdup(ifr->ifr_name);
#ifdef SIOCGIFINDEX
- if (ioctl (sfd, SIOCGIFINDEX, ifr) < 0)
- goto fail;
- newlist[i].index = ifr->ifr_index;
-#else
- newlist[i].index = i + 1;
+ if (ioctl (sfd, SIOCGIFINDEX, ifr) >= 0)
+ newlist[i].if_index = ifr->ifr_index;
+ else
#endif
+ newlist[i].if_index = i + 1;
+
i++;
ifc.ifc_len -= IFNAMSIZ + SA_LEN(&ifr->ifr_addr);
+ ifr = (struct ifreq *) ((caddr_t) ifr + ifrpsize(ifr));
}
assert (i == nr - 1);
+ newlist[i].if_index = 0;
+ newlist[i].if_name = NULL;
if (iflist)
free (iflist);
@@ -155,13 +166,26 @@ map_interfaces()
unsigned int
if_nametoindex (const char *ifname)
{
- /* XXX */
-#ifdef SIOCGIFNAME
-#endif
+ static struct if_nameindex *ifnp;
+
+ if (!iflist)
+ map_interfaces();
+ for (ifnp = iflist; ifnp < iflist + iflist_size - 1; ifnp++)
+ if (strcmp(ifnp->if_name, ifname) == 0)
+ break;
+ return ifnp->if_index;
+}
+
+struct if_nameindex *
+if_nameindex()
+{
+ if (!iflist)
+ map_interfaces();
+ return iflist;
}
-#endif /* HAVE_IF_NAMEINDEX
+#endif /* HAVE_IF_NAMEINDEX */
Index: ifconfig/ifconfig.c
===================================================================
RCS file: /cvs/inetutils/ifconfig/ifconfig.c,v
retrieving revision 1.1
diff -p -u -w -b -r1.1 ifconfig.c
--- ifconfig/ifconfig.c 2001/02/21 23:38:37 1.1
+++ ifconfig/ifconfig.c 2001/06/04 11:05:32
@@ -47,6 +47,8 @@
# endif
#endif
+#include <sys/types.h>
+#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <arpa/inet.h>
Index: ifconfig/ifconfig.h
===================================================================
RCS file: /cvs/inetutils/ifconfig/ifconfig.h,v
retrieving revision 1.1
diff -p -u -w -b -r1.1 ifconfig.h
--- ifconfig/ifconfig.h 2001/02/21 23:38:37 1.1
+++ ifconfig/ifconfig.h 2001/06/04 11:05:32
@@ -22,10 +22,6 @@
#ifndef IFCONFIG_IFCONFIG_H
#define IFCONFIG_IFCONFIG_H
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
#include "flags.h"
#include "options.h"
#include "printif.h"
Index: ifconfig/options.c
===================================================================
RCS file: /cvs/inetutils/ifconfig/options.c,v
retrieving revision 1.1
diff -p -u -w -b -r1.1 options.c
--- ifconfig/options.c 2001/02/21 23:38:37 1.1
+++ ifconfig/options.c 2001/06/04 11:05:33
@@ -43,9 +43,17 @@
# include <strings.h>
#endif
+#include <sys/socket.h>
#include <net/if.h>
#include "ifconfig.h"
+#ifndef SYSTEM_SHORT_OPTIONS
+# define SYSTEM_SHORT_OPTIONS
+#endif
+#ifndef SYSTEM_LONG_OPTIONS
+# define SYSTEM_LONG_OPTIONS
+#endif
+
/* Be verbose about actions. */
int verbose;
@@ -430,7 +438,6 @@ parse_opt (int argc, char *argv[])
usage (EXIT_FAILURE);
parse_opt_finalize (ifp);
}
-
if (!ifs)
{
/* No interfaces specified. Get a list of all interfaces. */
Index: ifconfig/options.h
===================================================================
RCS file: /cvs/inetutils/ifconfig/options.h,v
retrieving revision 1.1
diff -p -u -w -b -r1.1 options.h
--- ifconfig/options.h 2001/02/21 23:38:37 1.1
+++ ifconfig/options.h 2001/06/04 11:05:33
@@ -81,4 +81,12 @@ void parse_opt_finalize (struct ifconfig
void parse_opt (int argc, char *argv[]);
+#ifndef HAVE_STRUCT_IF_NAMEINDEX
+struct if_nameindex
+{
+ char *if_name;
+ int if_index;
+};
+#endif
+
#endif
Index: ifconfig/printif.c
===================================================================
RCS file: /cvs/inetutils/ifconfig/printif.c,v
retrieving revision 1.2
diff -p -u -w -b -r1.2 printif.c
--- ifconfig/printif.c 2001/02/27 03:10:48 1.2
+++ ifconfig/printif.c 2001/06/04 11:05:34
@@ -26,7 +26,6 @@
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>
-#include <stdint.h>
#if HAVE_UNISTD_H
#include <unistd.h>
@@ -49,6 +48,7 @@
#include <ctype.h>
#include <sys/ioctl.h>
+#include <sys/socket.h>
#include <net/if.h>
#include <arpa/inet.h>
#include "ifconfig.h"
@@ -510,7 +510,7 @@ fh_netmask (format_data_t form, int argc
exit (EXIT_FAILURE);
}
else
- put_addr (form, argc, argv, &form->ifr->ifr_netmask);
+ put_addr (form, argc, argv, &form->ifr->ifr_addr);
#else
*column += printf ("(not available)");
had_output = 1;
Index: ifconfig/printif.h
===================================================================
RCS file: /cvs/inetutils/ifconfig/printif.h,v
retrieving revision 1.2
diff -p -u -w -b -r1.2 printif.h
--- ifconfig/printif.h 2001/02/27 03:10:48 1.2
+++ ifconfig/printif.h 2001/06/04 11:05:34
@@ -22,10 +22,6 @@
#ifndef IFCONFIG_PRINTIF_H
#define IFCONFIG_PRINTIF_H
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
#include <net/if.h>
#include <arpa/inet.h>
#include "ifconfig.h"
Index: ifconfig/system.c
===================================================================
RCS file: /cvs/inetutils/ifconfig/system.c,v
retrieving revision 1.1
diff -p -u -w -b -r1.1 system.c
--- ifconfig/system.c 2001/02/21 23:38:37 1.1
+++ ifconfig/system.c 2001/06/04 11:05:34
@@ -4,10 +4,14 @@
#ifdef __solaris__
#include "system/solaris.c"
#else
+#ifdef __sun__
+#include "system/solaris.c"
+#else
#ifdef __hpux__
#include "system/hpux.c"
#else
#include "system/generic.c"
+#endif
#endif
#endif
#endif
Index: ifconfig/system.h
===================================================================
RCS file: /cvs/inetutils/ifconfig/system.h,v
retrieving revision 1.1
diff -p -u -w -b -r1.1 system.h
--- ifconfig/system.h 2001/02/21 23:38:37 1.1
+++ ifconfig/system.h 2001/06/04 11:05:34
@@ -79,12 +79,15 @@ int system_configure (int sfd, struct if
#ifdef __solaris__
#include "system/solaris.h"
#else
+#ifdef __sun__
+#include "system/solaris.h"
+#else
#ifdef __hpux__
#include "system/hpux.h"
#else
#include "system/generic.h"
#endif
#endif
+#endif
#endif
-
#endif
Index: ifconfig/system/generic.c
===================================================================
RCS file: /cvs/inetutils/ifconfig/system/generic.c,v
retrieving revision 1.1
diff -p -u -w -b -r1.1 generic.c
--- ifconfig/system/generic.c 2001/02/21 23:38:37 1.1
+++ ifconfig/system/generic.c 2001/06/04 11:05:34
@@ -49,3 +49,10 @@ system_parse_opt_rest (struct ifconfig *
{
return 0;
}
+
+int
+system_configure (int sfd, struct ifreq *ifr, struct system_ifconfig *ifs)
+{
+ return 0;
+}
+
Index: ifconfig/system/linux.c
===================================================================
RCS file: /cvs/inetutils/ifconfig/system/linux.c,v
retrieving revision 1.2
diff -p -u -w -b -r1.2 linux.c
--- ifconfig/system/linux.c 2001/02/27 03:10:48 1.2
+++ ifconfig/system/linux.c 2001/06/04 11:05:35
@@ -27,7 +27,6 @@
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>
-#include <stdint.h>
#if HAVE_UNISTD_H
#include <unistd.h>
Index: ifconfig/system/solaris.c
===================================================================
RCS file: /cvs/inetutils/ifconfig/system/solaris.c,v
retrieving revision 1.1
diff -p -u -w -b -r1.1 solaris.c
--- ifconfig/system/solaris.c 2001/02/21 23:38:37 1.1
+++ ifconfig/system/solaris.c 2001/06/04 11:05:35
@@ -27,8 +27,6 @@
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>
-#include <stdint.h>
-
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
@@ -48,17 +46,19 @@
# endif
#endif
+#include <sys/socket.h>
#include <sys/ioctl.h>
+#include <netinet/in.h>
#include <net/if.h>
#include <net/if_arp.h>
-#include <linux/if_ether.h>
+#include <netinet/if_ether.h>
#include "../ifconfig.h"
/* Output format stuff. */
-char *system_default_format "unix"
+char *system_default_format = "unix";
/* Argument parsing stuff. */
@@ -130,9 +130,9 @@ system_parse_opt_rest (struct ifconfig *
/* Recognize up/down. */
/* Also auto-revarp, trailers, -trailers,
private, -private, arp, -arp, plumb, unplumb. */
- if (! (*ifp->valid & IF_VALID_ADDR))
+ if (! ((*ifp)->valid & IF_VALID_ADDR))
parse_opt_set_address (*ifp, argv[i]);
- else if (! (*ifp->valid & IF_VALID_DSTADDR))
+ else if (! ((*ifp)->valid & IF_VALID_DSTADDR))
parse_opt_set_dstaddr (*ifp, argv[i]);
}
}
@@ -166,4 +166,34 @@ system_parse_opt_rest (struct ifconfig *
usage (EXIT_FAILURE);
return 1;
+}
+
+int
+system_configure (int sfd, struct ifreq *ifr, struct system_ifconfig *ifs)
+{
+#ifdef IF_VALID_TXQLEN /*FIXME*/
+ if (ifs->valid & IF_VALID_TXQLEN)
+ {
+#ifndef SIOCSIFTXQLEN
+ printf ("%s: Don't know how to set the txqlen on this system.\n",
+ __progname);
+ return -1;
+#else
+ int err = 0;
+
+ ifr->ifr_qlen = ifs->txqlen;
+ err = ioctl (sfd, SIOCSIFTXQLEN, ifr);
+ if (err < 0)
+ {
+ fprintf (stderr, "%s: SIOCSIFTXQLEN failed: %s\n",
+ __progname, strerror (errno));
+ return -1;
+ }
+ if (verbose)
+ printf ("Set txqlen value of `%s' to `%i'.\n",
+ ifr->ifr_name, ifr->ifr_qlen);
+#endif
+ }
+ return 0;
+#endif
}
Index: ifconfig/system/solaris.h
===================================================================
RCS file: /cvs/inetutils/ifconfig/system/solaris.h,v
retrieving revision 1.1
diff -p -u -w -b -r1.1 solaris.h
--- ifconfig/system/solaris.h 2001/02/21 23:38:37 1.1
+++ ifconfig/system/solaris.h 2001/06/04 11:05:35
@@ -24,6 +24,7 @@
#include "../printif.h"
#include "../options.h"
+#include <sys/sockio.h>
/* XXX: Gross. Have autoconf check and put in system.h or so.
Index: libls/print.c
===================================================================
RCS file: /cvs/inetutils/libls/print.c,v
retrieving revision 1.10
diff -p -u -w -b -r1.10 print.c
--- libls/print.c 2000/08/15 04:29:27 1.10
+++ libls/print.c 2001/06/04 11:05:36
@@ -71,6 +71,14 @@ static char rcsid[] = "$OpenBSD: print.c
#define howmany(x, y) (((x)+((y)-1))/(y))
#endif
+#ifndef major
+# define major(x) ((int)(((unsigned)(x)>>8)&0377))
+#endif
+
+#ifndef minor
+# define minor(x) ((int)((x)&0377))
+#endif
+
static int printaname __P((FTSENT *, u_long, u_long));
static void printlink __P((FTSENT *));
static void printtime __P((time_t));
Cheers,
Sergey
- ifconfig and some minor fixes.,
Sergey Poznyakoff <=