diff options
author | Phil Blundell <philb@gnu.org> | 1999-03-03 19:40:28 +0000 |
---|---|---|
committer | Phil Blundell <philb@gnu.org> | 1999-03-03 19:40:28 +0000 |
commit | 5d4b86020046745eb907bca5d72c7c88aecdff2d (patch) | |
tree | d325404fb424eb785c9e9dc631b7ef866b099901 /lib | |
parent | Add support for -V flag to ipmaddr. Arbitrarily say that this (diff) | |
download | net-tools-5d4b86020046745eb907bca5d72c7c88aecdff2d.tar.gz net-tools-5d4b86020046745eb907bca5d72c7c88aecdff2d.tar.bz2 net-tools-5d4b86020046745eb907bca5d72c7c88aecdff2d.zip |
Crusade against bogus AF specifics. Make it work (mostly)
to build without AF_INET.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/hw.c | 13 | ||||
-rw-r--r-- | lib/inet.c | 12 | ||||
-rw-r--r-- | lib/interface.c | 50 | ||||
-rw-r--r-- | lib/net-support.h | 1 |
4 files changed, 49 insertions, 27 deletions
@@ -2,7 +2,7 @@ * lib/hw.c This file contains the top-level part of the hardware * support functions module. * - * Version: $Id: hw.c,v 1.10 1999/01/05 20:53:31 philip Exp $ + * Version: $Id: hw.c,v 1.11 1999/03/03 19:40:38 philip Exp $ * * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de> * @@ -237,3 +237,14 @@ void print_hwlist(int type) { } fprintf(stderr,"\n"); } + +/* return 1 if address is all zeros */ +int hw_null_address(struct hwtype *hw, void *ap) +{ + unsigned int i; + unsigned char *address = (unsigned char *)ap; + for (i = 0; i < hw->alen; i++) + if (address[i]) + return 0; + return 1; +} @@ -3,7 +3,7 @@ * support functions for the net-tools. * (NET-3 base distribution). * - * Version: $Id: inet.c,v 1.9 1999/03/02 21:09:14 philip Exp $ + * Version: $Id: inet.c,v 1.10 1999/03/03 19:40:41 philip Exp $ * * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> * Copyright 1993 MicroWalt Corporation @@ -26,10 +26,13 @@ */ #include "config.h" -#if HAVE_AFINET +/* FIXME. Split this file into inet4.c for the IPv4 specific parts + and inet.c for those shared between IPv4 and IPv6. */ + +#if HAVE_AFINET || HAVE_AFINET6 +#include <netinet/in.h> #include <sys/types.h> #include <sys/socket.h> -#include <netinet/in.h> #include <arpa/inet.h> #include <arpa/nameser.h> #include <ctype.h> @@ -45,6 +48,7 @@ #include "pathnames.h" #include "intl.h" #include "util.h" +#endif extern int h_errno; /* some netdb.h versions don't export this */ @@ -63,6 +67,8 @@ struct service { static struct service *tcp_name = NULL, *udp_name = NULL, *raw_name = NULL; +#if HAVE_AFINET + static struct addr *INET_nn = NULL; /* addr-to-name cache */ diff --git a/lib/interface.c b/lib/interface.c index ad0037f..e3091e4 100644 --- a/lib/interface.c +++ b/lib/interface.c @@ -4,7 +4,7 @@ 10/1998 partly rewriten by Andi Kleen to support an interface list. I don't claim that the list operations are efficient @). - $Id: interface.c,v 1.1 1999/01/09 14:36:36 philip Exp $ + $Id: interface.c,v 1.2 1999/03/03 19:40:42 philip Exp $ */ #include "config.h" @@ -113,7 +113,10 @@ static int if_readconf(void) if (skfd < 0) { fprintf(stderr, _("warning: no inet socket available: %s\n"), strerror(errno)); - return -1; + /* Try to soldier on with whatever socket we can get hold of. */ + skfd = sockets_open(0); + if (skfd < 0) + return -1; } ifc.ifc_buf = NULL; @@ -394,31 +397,32 @@ int if_fetch(struct interface *ife) #endif #if HAVE_AFINET + /* IPv4 address? */ fd = get_socket_for_af(AF_INET); if (fd >= 0) { strcpy(ifr.ifr_name, ifname); - if (ioctl(fd, SIOCGIFDSTADDR, &ifr) < 0) - memset(&ife->dstaddr, 0, sizeof(struct sockaddr)); - else - ife->dstaddr = ifr.ifr_dstaddr; - - strcpy(ifr.ifr_name, ifname); - if (ioctl(fd, SIOCGIFBRDADDR, &ifr) < 0) - memset(&ife->broadaddr, 0, sizeof(struct sockaddr)); - else - ife->broadaddr = ifr.ifr_broadaddr; - - strcpy(ifr.ifr_name, ifname); - if (ioctl(fd, SIOCGIFNETMASK, &ifr) < 0) - memset(&ife->netmask, 0, sizeof(struct sockaddr)); - else - ife->netmask = ifr.ifr_netmask; - - strcpy(ifr.ifr_name, ifname); - if (ioctl(fd, SIOCGIFADDR, &ifr) < 0) - memset(&ife->addr, 0, sizeof(struct sockaddr)); - else + if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { + ife->has_ip = 1; ife->addr = ifr.ifr_addr; + strcpy(ifr.ifr_name, ifname); + if (ioctl(fd, SIOCGIFDSTADDR, &ifr) < 0) + memset(&ife->dstaddr, 0, sizeof(struct sockaddr)); + else + ife->dstaddr = ifr.ifr_dstaddr; + + strcpy(ifr.ifr_name, ifname); + if (ioctl(fd, SIOCGIFBRDADDR, &ifr) < 0) + memset(&ife->broadaddr, 0, sizeof(struct sockaddr)); + else + ife->broadaddr = ifr.ifr_broadaddr; + + strcpy(ifr.ifr_name, ifname); + if (ioctl(fd, SIOCGIFNETMASK, &ifr) < 0) + memset(&ife->netmask, 0, sizeof(struct sockaddr)); + else + ife->netmask = ifr.ifr_netmask; + } else + memset(&ife->addr, 0, sizeof(struct sockaddr)); } #endif diff --git a/lib/net-support.h b/lib/net-support.h index 254b0b9..a675100 100644 --- a/lib/net-support.h +++ b/lib/net-support.h @@ -73,6 +73,7 @@ extern void print_hwlist(int type); extern struct aftype *get_aftype(const char *name); extern struct aftype *get_afntype(int type); extern void print_aflist(int type); +extern int hw_null_address(struct hwtype *hw, void *addr); extern int getargs(char *string, char *arguments[]); |