diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile | 3 | ||||
-rw-r--r-- | lib/activate.c | 83 | ||||
-rw-r--r-- | lib/af.c | 366 | ||||
-rw-r--r-- | lib/arcnet.c | 129 | ||||
-rw-r--r-- | lib/ash.c | 110 | ||||
-rw-r--r-- | lib/ax25.c | 207 | ||||
-rw-r--r-- | lib/ax25_gr.c | 64 | ||||
-rw-r--r-- | lib/ddp.c | 53 | ||||
-rw-r--r-- | lib/ddp_gr.c | 4 | ||||
-rw-r--r-- | lib/econet.c | 87 | ||||
-rw-r--r-- | lib/ether.c | 143 | ||||
-rw-r--r-- | lib/fddi.c | 133 | ||||
-rw-r--r-- | lib/frame.c | 44 | ||||
-rw-r--r-- | lib/getargs.c | 100 | ||||
-rw-r--r-- | lib/getroute.c | 152 | ||||
-rw-r--r-- | lib/hdlclapb.c | 40 | ||||
-rw-r--r-- | lib/hippi.c | 138 | ||||
-rw-r--r-- | lib/hw.c | 217 | ||||
-rw-r--r-- | lib/inet.c | 461 | ||||
-rw-r--r-- | lib/inet6.c | 166 | ||||
-rw-r--r-- | lib/inet6_gr.c | 279 | ||||
-rw-r--r-- | lib/inet6_sr.c | 251 | ||||
-rw-r--r-- | lib/inet_gr.c | 345 | ||||
-rw-r--r-- | lib/inet_sr.c | 428 | ||||
-rw-r--r-- | lib/ipx.c | 219 | ||||
-rw-r--r-- | lib/ipx_gr.c | 74 | ||||
-rw-r--r-- | lib/ipx_sr.c | 19 | ||||
-rw-r--r-- | lib/loopback.c | 62 | ||||
-rw-r--r-- | lib/masq_info.c | 320 | ||||
-rw-r--r-- | lib/net-features.h | 330 | ||||
-rw-r--r-- | lib/net-string.c | 77 | ||||
-rw-r--r-- | lib/net-support.h | 160 | ||||
-rw-r--r-- | lib/netrom.c | 204 | ||||
-rw-r--r-- | lib/netrom_gr.c | 98 | ||||
-rw-r--r-- | lib/netrom_sr.c | 14 | ||||
-rw-r--r-- | lib/nstrcmp.c | 43 | ||||
-rw-r--r-- | lib/pathnames.h | 71 | ||||
-rw-r--r-- | lib/ppp.c | 38 | ||||
-rw-r--r-- | lib/ppp_ac.c | 24 | ||||
-rw-r--r-- | lib/proc.c | 70 | ||||
-rw-r--r-- | lib/proc.h | 4 | ||||
-rw-r--r-- | lib/rose.c | 136 | ||||
-rw-r--r-- | lib/rose_gr.c | 71 | ||||
-rw-r--r-- | lib/setroute.c | 90 | ||||
-rw-r--r-- | lib/sit.c | 29 | ||||
-rw-r--r-- | lib/slip.c | 57 | ||||
-rw-r--r-- | lib/slip_ac.c | 88 | ||||
-rw-r--r-- | lib/tr.c | 136 | ||||
-rw-r--r-- | lib/tunnel.c | 26 | ||||
-rw-r--r-- | lib/unix.c | 90 | ||||
-rw-r--r-- | lib/util.c | 38 | ||||
-rw-r--r-- | lib/util.h | 12 |
52 files changed, 3274 insertions, 3329 deletions
diff --git a/lib/Makefile b/lib/Makefile index 97e736d..f36b6af 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -22,9 +22,8 @@ AFGROBJS = inet_gr.o inet6_gr.o ipx_gr.o ddp_gr.o netrom_gr.o ax25_gr.o rose_gr. AFSROBJS = inet_sr.o inet6_sr.o netrom_sr.o ipx_sr.o setroute.o ACTOBJS = slip_ac.o ppp_ac.o activate.o VARIA = getargs.o masq_info.o proc.o util.o nstrcmp.o -NLSMISC = net-string.o -OBJS = $(NLSMISC) $(VARIA) $(AFOBJS) $(HWOBJS) \ +OBJS = $(VARIA) $(AFOBJS) $(HWOBJS) \ $(AFGROBJS) $(AFSROBJS) $(ACTOBJS) diff --git a/lib/activate.c b/lib/activate.c index 07c5521..ae8ade2 100644 --- a/lib/activate.c +++ b/lib/activate.c @@ -1,27 +1,27 @@ /* - * lib/activate.c This file contains a small interface function to - * use the HW specific activate routines for line - * disciplines + * lib/activate.c This file contains a small interface function to + * use the HW specific activate routines for line + * disciplines * - * NET-LIB A collection of functions used from the base set of the - * NET-3 Networking Distribution for the LINUX operating - * system. (net-tools, net-drivers) + * NET-LIB A collection of functions used from the base set of the + * NET-3 Networking Distribution for the LINUX operating + * system. (net-tools, net-drivers) * - * Version: lib/activate.c 0.01 (1996-03-22) + * Version: $Id: activate.c,v 1.3 1998/11/15 20:08:55 freitag Exp $ * - * Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de> - * Copyright 1996 Bernd Eckenfels, Germany + * Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de> + * Copyright 1996 Bernd Eckenfels, Germany * * Modifications: * - *960322 {0.01} Bernd Eckenfels: creation + *960322 {0.01} Bernd Eckenfels: creation *980411 {0.01i} Arnaldo Carvalho: i18n: now uses gettext * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include <stdio.h> #include <string.h> @@ -31,12 +31,12 @@ #include "config.h" #include "intl.h" -extern struct hwtype slip_hwtype; -extern struct hwtype cslip_hwtype; -extern struct hwtype slip6_hwtype; -extern struct hwtype cslip6_hwtype; -extern struct hwtype adaptive_hwtype; -extern struct hwtype ppp_hwtype; +extern struct hwtype slip_hwtype; +extern struct hwtype cslip_hwtype; +extern struct hwtype slip6_hwtype; +extern struct hwtype cslip6_hwtype; +extern struct hwtype adaptive_hwtype; +extern struct hwtype ppp_hwtype; extern int SLIP_activate(int fd); extern int CSLIP_activate(int fd); @@ -45,34 +45,33 @@ extern int CSLIP6_activate(int fd); extern int ADAPTIVE_activate(int fd); extern int PPP_activate(int fd); -void -activate_init(void) +void activate_init(void) { #if HAVE_HWSLIP - slip_hwtype.activate = SLIP_activate; - cslip_hwtype.activate = CSLIP_activate; - slip6_hwtype.activate = SLIP6_activate; - cslip6_hwtype.activate = CSLIP6_activate; - adaptive_hwtype.activate = ADAPTIVE_activate; + slip_hwtype.activate = SLIP_activate; + cslip_hwtype.activate = CSLIP_activate; + slip6_hwtype.activate = SLIP6_activate; + cslip6_hwtype.activate = CSLIP6_activate; + adaptive_hwtype.activate = ADAPTIVE_activate; #endif #if HAVE_HWPPP - ppp_hwtype.activate = PPP_activate; + ppp_hwtype.activate = PPP_activate; #endif } int activate_ld(const char *hwname, int fd) { - struct hwtype *hw; - - hw = get_hwtype(hwname); - - if (!hw) { - fprintf(stderr,_("Hardware type `%s' not supported.\n"),hwname); - return(E_NOSUPP); - } - if (!hw->activate) { - fprintf(stderr,_("Cannot change line discipline to `%s'.\n"),hw->name); - return(E_OPTERR); - } - return(hw->activate(fd)); + struct hwtype *hw; + + hw = get_hwtype(hwname); + + if (!hw) { + fprintf(stderr, _("Hardware type `%s' not supported.\n"), hwname); + return (E_NOSUPP); + } + if (!hw->activate) { + fprintf(stderr, _("Cannot change line discipline to `%s'.\n"), hw->name); + return (E_OPTERR); + } + return (hw->activate(fd)); } @@ -1,17 +1,17 @@ /* - * lib/af.c This file contains the top-level part of the protocol - * support functions module for the NET-2 base distribution. + * lib/af.c This file contains the top-level part of the protocol + * support functions module for the NET-2 base distribution. * - * Version: lib/af.c 1.13 (1996-02-21) + * Version: $Id: af.c,v 1.6 1998/11/15 20:08:59 freitag Exp $ * - * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993 MicroWalt Corporation + * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Copyright 1993 MicroWalt Corporation * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include <sys/types.h> #include <sys/socket.h> @@ -38,231 +38,257 @@ int flag_econet = 0; struct aftrans_t { - char *alias; - char *name; - int *flag; -} aftrans[]={ - {"ax25", "ax25", &flag_ax25}, - {"ip", "inet", &flag_inet}, - {"ip6", "inet6", &flag_inet6}, - {"ipx", "ipx", &flag_ipx}, - {"appletalk", "ddp", &flag_ddp}, - {"netrom", "netrom", &flag_netrom}, - {"inet", "inet", &flag_inet}, - {"inet6", "inet6", &flag_inet6}, - {"ddp", "ddp", &flag_ddp}, - {"unix", "unix", &flag_unx}, - {"tcpip", "inet", &flag_inet}, - {"econet", "ec", &flag_econet}, - {0, 0, 0} + char *alias; + char *name; + int *flag; +} aftrans[] = { + + { + "ax25", "ax25", &flag_ax25 + }, + { + "ip", "inet", &flag_inet + }, + { + "ip6", "inet6", &flag_inet6 + }, + { + "ipx", "ipx", &flag_ipx + }, + { + "appletalk", "ddp", &flag_ddp + }, + { + "netrom", "netrom", &flag_netrom + }, + { + "inet", "inet", &flag_inet + }, + { + "inet6", "inet6", &flag_inet6 + }, + { + "ddp", "ddp", &flag_ddp + }, + { + "unix", "unix", &flag_unx + }, + { + "tcpip", "inet", &flag_inet + }, + { + "econet", "ec", &flag_econet + }, + { + 0, 0, 0 + } }; -char afname[256]=""; +char afname[256] = ""; -extern struct aftype unspec_aftype; -extern struct aftype unix_aftype; -extern struct aftype inet_aftype; -extern struct aftype inet6_aftype; -extern struct aftype ax25_aftype; -extern struct aftype netrom_aftype; -extern struct aftype ipx_aftype; -extern struct aftype ddp_aftype; -extern struct aftype ec_aftype; +extern struct aftype unspec_aftype; +extern struct aftype unix_aftype; +extern struct aftype inet_aftype; +extern struct aftype inet6_aftype; +extern struct aftype ax25_aftype; +extern struct aftype netrom_aftype; +extern struct aftype ipx_aftype; +extern struct aftype ddp_aftype; +extern struct aftype ec_aftype; static short sVafinit = 0; -struct aftype *aftypes[] = { +struct aftype *aftypes[] = +{ #if HAVE_AFUNIX - &unix_aftype, + &unix_aftype, #endif #if HAVE_AFINET - &inet_aftype, + &inet_aftype, #endif #if HAVE_AFINET6 - &inet6_aftype, + &inet6_aftype, #endif #if HAVE_AFAX25 - &ax25_aftype, + &ax25_aftype, #endif #if HAVE_AFNETROM - &netrom_aftype, + &netrom_aftype, #endif #if HAVE_AFIPX - &ipx_aftype, + &ipx_aftype, #endif #if HAVE_AFATALK - &ddp_aftype, + &ddp_aftype, #endif #if HAVE_AFECONET - &ec_aftype, + &ec_aftype, #endif - &unspec_aftype, - NULL + &unspec_aftype, + NULL }; -void afinit () +void afinit() { - unspec_aftype.title = _("UNSPEC"); + unspec_aftype.title = _("UNSPEC"); #if HAVE_AFINET - unix_aftype.title = _("UNIX Domain"); + unix_aftype.title = _("UNIX Domain"); #endif #if HAVE_AFINET - inet_aftype.title = _("DARPA Internet"); + inet_aftype.title = _("DARPA Internet"); #endif #if HAVE_AFINET6 - inet6_aftype.title = _("IPv6"); + inet6_aftype.title = _("IPv6"); #endif #if HAVE_AFAX25 - ax25_aftype.title = _("AMPR AX.25"); + ax25_aftype.title = _("AMPR AX.25"); #endif #if HAVE_AFNETROM - netrom_aftype.title = _("AMPR NET/ROM"); + netrom_aftype.title = _("AMPR NET/ROM"); #endif #if HAVE_AFIPX - ipx_aftype.title = _("IPX"); + ipx_aftype.title = _("IPX"); #endif #if HAVE_AFATALK - ddp_aftype.title = _("Appletalk DDP"); + ddp_aftype.title = _("Appletalk DDP"); #endif #if HAVE_AFECONET - ec_aftype.title = _("Econet"); + ec_aftype.title = _("Econet"); #endif - sVafinit = 1; + sVafinit = 1; } -/* set the default AF list from the program name or a constant value */ -void -aftrans_def(char *tool, char *argv0, char *dflt) +/* set the default AF list from the program name or a constant value */ +void aftrans_def(char *tool, char *argv0, char *dflt) { - char *tmp; - char *buf; - - strcpy(afname, dflt); - - if (!(tmp = strrchr(argv0, '/'))) - tmp = argv0; /* no slash?! */ - else - tmp++; - - if (!(buf = strdup(tmp))) - return; - - if (strlen(tool) >= strlen(tmp)) { - free(buf); - return; - } - tmp = buf+(strlen(tmp)-strlen(tool)); - - if (strcmp(tmp, tool)!=0) { - free(buf); - return; - } - - *tmp = '\0'; - if ((tmp = strchr(buf,'_'))) - *tmp = '\0'; - - afname[0]='\0'; - if (aftrans_opt(buf)) - strcpy(afname, buf); - - free(buf); + char *tmp; + char *buf; + + strcpy(afname, dflt); + + if (!(tmp = strrchr(argv0, '/'))) + tmp = argv0; /* no slash?! */ + else + tmp++; + + if (!(buf = strdup(tmp))) + return; + + if (strlen(tool) >= strlen(tmp)) { + free(buf); + return; + } + tmp = buf + (strlen(tmp) - strlen(tool)); + + if (strcmp(tmp, tool) != 0) { + free(buf); + return; + } + *tmp = '\0'; + if ((tmp = strchr(buf, '_'))) + *tmp = '\0'; + + afname[0] = '\0'; + if (aftrans_opt(buf)) + strcpy(afname, buf); + + free(buf); } /* Check our protocol family table for this family. */ -struct aftype * -get_aftype(const char *name) +struct aftype *get_aftype(const char *name) { - struct aftype **afp; - - if (!sVafinit) - afinit (); - - afp = aftypes; - while (*afp != NULL) { - if (!strcmp((*afp)->name, name)) return(*afp); + struct aftype **afp; + + if (!sVafinit) + afinit(); + + afp = aftypes; + while (*afp != NULL) { + if (!strcmp((*afp)->name, name)) + return (*afp); afp++; - } - if (index(name,',')) - fprintf(stderr,_("Please don't supply more than one address family.\n")); - return(NULL); + } + if (index(name, ',')) + fprintf(stderr, _("Please don't supply more than one address family.\n")); + return (NULL); } /* Check our protocol family table for this family. */ -struct aftype * -get_afntype(int af) +struct aftype *get_afntype(int af) { - struct aftype **afp; - - if (!sVafinit) - afinit (); - - afp = aftypes; - while (*afp != NULL) { - if ((*afp)->af == af) return(*afp); + struct aftype **afp; + + if (!sVafinit) + afinit(); + + afp = aftypes; + while (*afp != NULL) { + if ((*afp)->af == af) + return (*afp); afp++; - } - return(NULL); + } + return (NULL); } /* Check our protocol family table for this family and return its socket */ -int -get_socket_for_af(int af) +int get_socket_for_af(int af) { - struct aftype **afp; - - if (!sVafinit) - afinit (); - - afp = aftypes; - while (*afp != NULL) { - if ((*afp)->af == af) return (*afp)->fd; + struct aftype **afp; + + if (!sVafinit) + afinit(); + + afp = aftypes; + while (*afp != NULL) { + if ((*afp)->af == af) + return (*afp)->fd; afp++; - } - return -1; + } + return -1; } int aftrans_opt(const char *arg) { - struct aftrans_t *paft; - char *tmp1, *tmp2; - char buf[256]; - - strncpy(buf,arg,sizeof(buf)); - buf[sizeof(buf)-1]='\0'; - - tmp1=buf; - - while(tmp1) { - - tmp2=index(tmp1,','); - - if (tmp2) - *(tmp2++)='\0'; - - paft=aftrans; - for(paft=aftrans;paft->alias;paft++) { - if (strcmp(tmp1,paft->alias)) - continue; - if (strlen(paft->name)+strlen(afname)+1 >= sizeof(afname)) { - fprintf(stderr,_("Too much address family arguments.\n")); - return(0); - } - if (paft->flag) - (*paft->flag)++; - if (afname[0]) - strcat(afname,","); - strcat(afname,paft->name); - break; - } - if (!paft->alias) { - fprintf(stderr,_("Unknown address family `%s'.\n"),tmp1); - return(1); - } - tmp1=tmp2; + struct aftrans_t *paft; + char *tmp1, *tmp2; + char buf[256]; + + strncpy(buf, arg, sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + + tmp1 = buf; + + while (tmp1) { + + tmp2 = index(tmp1, ','); + + if (tmp2) + *(tmp2++) = '\0'; + + paft = aftrans; + for (paft = aftrans; paft->alias; paft++) { + if (strcmp(tmp1, paft->alias)) + continue; + if (strlen(paft->name) + strlen(afname) + 1 >= sizeof(afname)) { + fprintf(stderr, _("Too much address family arguments.\n")); + return (0); + } + if (paft->flag) + (*paft->flag)++; + if (afname[0]) + strcat(afname, ","); + strcat(afname, paft->name); + break; + } + if (!paft->alias) { + fprintf(stderr, _("Unknown address family `%s'.\n"), tmp1); + return (1); } + tmp1 = tmp2; + } - return(0); + return (0); } diff --git a/lib/arcnet.c b/lib/arcnet.c index 7804211..8b8a870 100644 --- a/lib/arcnet.c +++ b/lib/arcnet.c @@ -1,17 +1,17 @@ /* - * lib/arcnet.c This file contains an implementation of the "ARCnet" - * support functions for the NET-2 base distribution. + * lib/arcnet.c This file contains an implementation of the "ARCnet" + * support functions for the NET-2 base distribution. * - * Version: @(#)arcnet.c 1.10 10/07/93 + * Version: $Id: arcnet.c,v 1.3 1998/11/15 20:09:06 freitag Exp $ * - * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993 MicroWalt Corporation + * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Copyright 1993 MicroWalt Corporation * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -34,103 +34,106 @@ extern struct hwtype arcnet_hwtype; /* Display an ARCnet address in readable format. */ -static char * -pr_arcnet(unsigned char *ptr) +static char *pr_arcnet(unsigned char *ptr) { - static char buff[64]; + static char buff[64]; - snprintf(buff, sizeof(buff), "%02X",(ptr[0] & 0377)); - return(buff); + snprintf(buff, sizeof(buff), "%02X", (ptr[0] & 0377)); + return (buff); } /* Display an ARCnet socket address. */ -static char * -pr_sarcnet(struct sockaddr *sap) +static char *pr_sarcnet(struct sockaddr *sap) { - static char buf[64]; + static char buf[64]; - if (sap->sa_family == 0xFFFF || sap->sa_family == 0) - return strncpy (buf, _("[NONE SET]"), sizeof (buf)); - return(pr_arcnet(sap->sa_data)); + if (sap->sa_family == 0xFFFF || sap->sa_family == 0) + return strncpy(buf, _("[NONE SET]"), sizeof(buf)); + return (pr_arcnet(sap->sa_data)); } /* Input an ARCnet address and convert to binary. */ -static int -in_arcnet(char *bufp, struct sockaddr *sap) +static int in_arcnet(char *bufp, struct sockaddr *sap) { - unsigned char *ptr; - char c, *orig; - int i, val; + unsigned char *ptr; + char c, *orig; + int i, val; - sap->sa_family = arcnet_hwtype.type; - ptr = sap->sa_data; + sap->sa_family = arcnet_hwtype.type; + ptr = sap->sa_data; - i = 0; - orig = bufp; - while((*bufp != '\0') && (i < 1)) { + i = 0; + orig = bufp; + while ((*bufp != '\0') && (i < 1)) { val = 0; c = *bufp++; - if (isdigit(c)) val = c - '0'; - else if (c >= 'a' && c <= 'f') val = c - 'a' + 10; - else if (c >= 'A' && c <= 'F') val = c - 'A' + 10; - else { + if (isdigit(c)) + val = c - '0'; + else if (c >= 'a' && c <= 'f') + val = c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + val = c - 'A' + 10; + else { #ifdef DEBUG - fprintf(stderr, _("in_arcnet(%s): invalid arcnet address!\n"), orig); + fprintf(stderr, _("in_arcnet(%s): invalid arcnet address!\n"), orig); #endif - errno = EINVAL; - return(-1); + errno = EINVAL; + return (-1); } val <<= 4; c = *bufp++; - if (isdigit(c)) val |= c - '0'; - else if (c >= 'a' && c <= 'f') val |= c - 'a' + 10; - else if (c >= 'A' && c <= 'F') val |= c - 'A' + 10; - else { + if (isdigit(c)) + val |= c - '0'; + else if (c >= 'a' && c <= 'f') + val |= c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + val |= c - 'A' + 10; + else { #ifdef DEBUG - fprintf(stderr, _("in_arcnet(%s): invalid arcnet address!\n"), orig); + fprintf(stderr, _("in_arcnet(%s): invalid arcnet address!\n"), orig); #endif - errno = EINVAL; - return(-1); + errno = EINVAL; + return (-1); } *ptr++ = (unsigned char) (val & 0377); i++; /* We might get a semicolon here - not required. */ if (*bufp == ':') { - if (i == ETH_ALEN) { + if (i == ETH_ALEN) { #ifdef DEBUG - fprintf(stderr, _("in_arcnet(%s): trailing : ignored!\n"), - orig) + fprintf(stderr, _("in_arcnet(%s): trailing : ignored!\n"), + orig) #endif - ; /* nothing */ - } - bufp++; + ; /* nothing */ + } + bufp++; } - } + } - /* That's it. Any trailing junk? */ - if ((i == ETH_ALEN) && (*bufp != '\0')) { + /* That's it. Any trailing junk? */ + if ((i == ETH_ALEN) && (*bufp != '\0')) { #ifdef DEBUG fprintf(stderr, _("in_arcnet(%s): trailing junk!\n"), orig); errno = EINVAL; - return(-1); + return (-1); #endif - } - + } #ifdef DEBUG - fprintf(stderr, "in_arcnet(%s): %s\n", orig, pr_arcnet(sap->sa_data)); + fprintf(stderr, "in_arcnet(%s): %s\n", orig, pr_arcnet(sap->sa_data)); #endif - return(0); + return (0); } -struct hwtype arcnet_hwtype = { - "arcnet", NULL, /*"2.5Mbps ARCnet",*/ ARPHRD_ARCNET, 1, - pr_arcnet, pr_sarcnet, in_arcnet, NULL +struct hwtype arcnet_hwtype = +{ + "arcnet", NULL, /*"2.5Mbps ARCnet", */ ARPHRD_ARCNET, 1, + pr_arcnet, pr_sarcnet, in_arcnet, NULL }; -#endif /* HAVE_HWARC */ +#endif /* HAVE_HWARC */ @@ -1,6 +1,7 @@ /* - * lib/ash.c This file contains an implementation of the Ash - * support functions for the NET-2 base distribution. + * lib/ash.c This file contains an implementation of the Ash + * support functions for the NET-2 base distribution. + * $Id: ash.c,v 1.6 1998/11/15 20:09:16 freitag Exp $ */ #include "config.h" @@ -29,77 +30,76 @@ extern struct hwtype ash_hwtype; /* Display an Ash address in readable format. */ -static char * -pr_ash(unsigned char *ptr) +static char *pr_ash(unsigned char *ptr) { - static char buff[128]; - char *p = buff; - unsigned int i = 0; - - p[0] = '['; p++; - while (ptr[i] != 0xc9 && ptr[i] != 0xff && (i < ASH_ALEN)) - sprintf (p++, "%1x", ptr[i++]); - *(p++) = ']'; - *p = 0; - - return buff; + static char buff[128]; + char *p = buff; + unsigned int i = 0; + + p[0] = '['; + p++; + while (ptr[i] != 0xc9 && ptr[i] != 0xff && (i < ASH_ALEN)) + sprintf(p++, "%1x", ptr[i++]); + *(p++) = ']'; + *p = 0; + + return buff; } /* Display an Ash socket address. */ -static char * -pr_sash(struct sockaddr *sap) +static char *pr_sash(struct sockaddr *sap) { - static char buf[64]; + static char buf[64]; - if (sap->sa_family == 0xFFFF || sap->sa_family == 0) - return strncpy (buf, "[NONE SET]", 64); - return pr_ash (sap->sa_data); + if (sap->sa_family == 0xFFFF || sap->sa_family == 0) + return strncpy(buf, "[NONE SET]", 64); + return pr_ash(sap->sa_data); } -static unsigned char hamming[16] = -{ - 0x15, 0x02, 0x49, 0x5e, 0x64, 0x73, 0x38, 0x2f, - 0xd0, 0xc7, 0x8c, 0x9b, 0xa1, 0xb6, 0xfd, 0xea +static unsigned char hamming[16] = +{ + 0x15, 0x02, 0x49, 0x5e, 0x64, 0x73, 0x38, 0x2f, + 0xd0, 0xc7, 0x8c, 0x9b, 0xa1, 0xb6, 0xfd, 0xea }; -static int -in_ash(char *bufp, struct sockaddr *sap) +static int in_ash(char *bufp, struct sockaddr *sap) { - unsigned char *ptr; - unsigned int i = 0; - - sap->sa_family = ash_hwtype.type; - ptr = sap->sa_data; - - while (bufp && i < ASH_ALEN) { - char *next; - int hop = strtol (bufp, &next, 16); - ptr[i++] = hamming[hop]; - switch (*next) { - case ':': - bufp = next + 1; - break; - case 0: - bufp = NULL; - break; - default: - fprintf (stderr, _("Malformed Ash address")); - memset (ptr, 0xc9, ASH_ALEN); - return -1; + unsigned char *ptr; + unsigned int i = 0; + + sap->sa_family = ash_hwtype.type; + ptr = sap->sa_data; + + while (bufp && i < ASH_ALEN) { + char *next; + int hop = strtol(bufp, &next, 16); + ptr[i++] = hamming[hop]; + switch (*next) { + case ':': + bufp = next + 1; + break; + case 0: + bufp = NULL; + break; + default: + fprintf(stderr, _("Malformed Ash address")); + memset(ptr, 0xc9, ASH_ALEN); + return -1; + } } - } - while (i < ASH_ALEN) - ptr[i++] = 0xc9; + while (i < ASH_ALEN) + ptr[i++] = 0xc9; - return 0; + return 0; } -struct hwtype ash_hwtype = { - "ash", NULL, ARPHRD_ASH, ASH_ALEN, - pr_ash, pr_sash, in_ash, NULL +struct hwtype ash_hwtype = +{ + "ash", NULL, ARPHRD_ASH, ASH_ALEN, + pr_ash, pr_sash, in_ash, NULL }; #endif @@ -1,22 +1,22 @@ /* - * lib/ax25.c This file contains an implementation of the "AX.25" - * support functions for the NET-2 base distribution. + * lib/ax25.c This file contains an implementation of the "AX.25" + * support functions. * - * Version: @(#)ax25.c 1.20 12/16/93 + * Version: $Id: ax25.c,v 1.6 1998/11/15 20:09:19 freitag Exp $ * - * NOTE: I will redo this module as soon as I got the libax25.a - * library sorted out. This library contains some useful - * and often used address conversion functions, database - * lookup stuff, and more of the like. + * NOTE: I will redo this module as soon as I got the libax25.a + * library sorted out. This library contains some useful + * and often used address conversion functions, database + * lookup stuff, and more of the like. * - * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993 MicroWalt Corporation + * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Copyright 1993 MicroWalt Corporation * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -44,164 +44,165 @@ static char AX25_errmsg[128]; - extern struct aftype ax25_aftype; - -static char * -AX25_print(unsigned char *ptr) +static char *AX25_print(unsigned char *ptr) { - static char buff[8]; - int i; + static char buff[8]; + int i; - for (i = 0; i < 6; i++) { + for (i = 0; i < 6; i++) { buff[i] = ((ptr[i] & 0377) >> 1); - if (buff[i] == ' ') buff[i] = '\0'; - } - buff[6] = '\0'; - i = ((ptr[6] & 0x1E) >> 1); - if (i != 0) sprintf(&buff[strlen(buff)], "-%d", i); - return(buff); + if (buff[i] == ' ') + buff[i] = '\0'; + } + buff[6] = '\0'; + i = ((ptr[6] & 0x1E) >> 1); + if (i != 0) + sprintf(&buff[strlen(buff)], "-%d", i); + return (buff); } /* Display an AX.25 socket address. */ static char * -AX25_sprint(struct sockaddr *sap, int numeric) + AX25_sprint(struct sockaddr *sap, int numeric) { - static char buf[64]; + static char buf[64]; - if (sap->sa_family == 0xFFFF || sap->sa_family == 0) - return strncpy (buf, _("[NONE SET]"), sizeof (buf)); - return(AX25_print(((struct sockaddr_ax25 *)sap)->sax25_call.ax25_call)); + if (sap->sa_family == 0xFFFF || sap->sa_family == 0) + return strncpy(buf, _("[NONE SET]"), sizeof(buf)); + return (AX25_print(((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call)); } -static int -AX25_input(int type, char *bufp, struct sockaddr *sap) +static int AX25_input(int type, char *bufp, struct sockaddr *sap) { - unsigned char *ptr; - char *orig, c; - int i; + unsigned char *ptr; + char *orig, c; + int i; - sap->sa_family = ax25_aftype.af; - ptr = ((struct sockaddr_ax25 *)sap)->sax25_call.ax25_call; + sap->sa_family = ax25_aftype.af; + ptr = ((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call; - /* First, scan and convert the basic callsign. */ - orig = bufp; - i = 0; - while((*bufp != '\0') && (*bufp != '-') && (i < 6)) { + /* First, scan and convert the basic callsign. */ + orig = bufp; + i = 0; + while ((*bufp != '\0') && (*bufp != '-') && (i < 6)) { c = *bufp++; - if (islower(c)) c = toupper(c); - if (! (isupper(c) || isdigit(c))) { - strcpy(AX25_errmsg, _("Invalid callsign")); + if (islower(c)) + c = toupper(c); + if (!(isupper(c) || isdigit(c))) { + strncpy(AX25_errmsg, _("Invalid callsign"), sizeof(AX25_errmsg)-2); + AX25_errmsg[sizeof(AX25_errmsg)-1]=0; #ifdef DEBUG - fprintf(stderr, "ax25_input(%s): %s !\n", AX25_errmsg, orig); + fprintf(stderr, "ax25_input(%s): %s !\n", AX25_errmsg, orig); #endif - errno = EINVAL; - return(-1); + errno = EINVAL; + return (-1); } *ptr++ = (unsigned char) ((c << 1) & 0xFE); i++; - } + } - /* Callsign too long? */ - if ((i == 6) && (*bufp != '-') && (*bufp != '\0')) { + /* Callsign too long? */ + if ((i == 6) && (*bufp != '-') && (*bufp != '\0')) { strcpy(AX25_errmsg, _("Callsign too long")); #ifdef DEBUG fprintf(stderr, "ax25_input(%s): %s !\n", AX25_errmsg, orig); #endif errno = E2BIG; - return(-1); - } - - /* Nope, fill out the address bytes with blanks. */ - while (i++ < sizeof(ax25_address)-1) { + return (-1); + } + /* Nope, fill out the address bytes with blanks. */ + while (i++ < sizeof(ax25_address) - 1) { *ptr++ = (unsigned char) ((' ' << 1) & 0xFE); - } + } - /* See if we need to add an SSID field. */ - if (*bufp == '-') { + /* See if we need to add an SSID field. */ + if (*bufp == '-') { i = atoi(++bufp); *ptr = (unsigned char) ((i << 1) & 0xFE); - } else { + } else { *ptr = (unsigned char) '\0'; - } + } - /* All done. */ + /* All done. */ #ifdef DEBUG - fprintf(stderr, "ax25_input(%s): ", orig); - for (i = 0; i < sizeof(ax25_address); i++) + fprintf(stderr, "ax25_input(%s): ", orig); + for (i = 0; i < sizeof(ax25_address); i++) fprintf(stderr, "%02X ", sap->sa_data[i] & 0377); - fprintf(stderr, "\n"); + fprintf(stderr, "\n"); #endif - return(0); + return (0); } /* Display an error message. */ -static void -AX25_herror(char *text) +static void AX25_herror(char *text) { - if (text == NULL) fprintf(stderr, "%s\n", AX25_errmsg); - else fprintf(stderr, "%s: %s\n", text, AX25_errmsg); + if (text == NULL) + fprintf(stderr, "%s\n", AX25_errmsg); + else + fprintf(stderr, "%s: %s\n", text, AX25_errmsg); } -static char * -AX25_hprint(struct sockaddr *sap) +static char *AX25_hprint(struct sockaddr *sap) { - static char buf[64]; + static char buf[64]; - if (sap->sa_family == 0xFFFF || sap->sa_family == 0) - return strncpy (buf, _("[NONE SET]"), sizeof (buf)); - return(AX25_print(((struct sockaddr_ax25 *)sap)->sax25_call.ax25_call)); + if (sap->sa_family == 0xFFFF || sap->sa_family == 0) + return strncpy(buf, _("[NONE SET]"), sizeof(buf)); + return (AX25_print(((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call)); } -static int -AX25_hinput(char *bufp, struct sockaddr *sap) +static int AX25_hinput(char *bufp, struct sockaddr *sap) { - if (AX25_input(0, bufp, sap) < 0) return(-1); - sap->sa_family = ARPHRD_AX25; - return(0); + if (AX25_input(0, bufp, sap) < 0) + return (-1); + sap->sa_family = ARPHRD_AX25; + return (0); } #if 0 /* Set the line discipline of a terminal line. */ -static int -KISS_set_disc(int fd, int disc) +static int KISS_set_disc(int fd, int disc) { - if (ioctl(fd, TIOCSETD, &disc) < 0) { + if (ioctl(fd, TIOCSETD, &disc) < 0) { fprintf(stderr, "KISS_set_disc(%d): %s\n", disc, strerror(errno)); - return(-errno); - } - return(0); + return (-errno); + } + return (0); } /* Start the KISS encapsulation on the file descriptor. */ -static int -KISS_init(int fd) +static int KISS_init(int fd) { - if (KISS_set_disc(fd, N_SLIP) < 0) return(-1); - if (ioctl(fd, SIOCSIFENCAP, 4) <0) return(-1); - return(0); + if (KISS_set_disc(fd, N_SLIP) < 0) + return (-1); + if (ioctl(fd, SIOCSIFENCAP, 4) < 0) + return (-1); + return (0); } #endif -struct hwtype ax25_hwtype = { - "ax25", NULL, /*"AMPR AX.25",*/ ARPHRD_AX25, 7, - AX25_print, AX25_hprint, AX25_hinput, NULL +struct hwtype ax25_hwtype = +{ + "ax25", NULL, /*"AMPR AX.25", */ ARPHRD_AX25, 7, + AX25_print, AX25_hprint, AX25_hinput, NULL }; -struct aftype ax25_aftype = { - "ax25", NULL, /*"AMPR AX.25",*/ AF_AX25, 7, - AX25_print, AX25_sprint, AX25_input, AX25_herror, - NULL, NULL, NULL, - -1, - "/proc/net/ax25" +struct aftype ax25_aftype = +{ + "ax25", NULL, /*"AMPR AX.25", */ AF_AX25, 7, + AX25_print, AX25_sprint, AX25_input, AX25_herror, + NULL, NULL, NULL, + -1, + "/proc/net/ax25" }; -#endif /* HAVE_xxAX25 */ +#endif /* HAVE_xxAX25 */ diff --git a/lib/ax25_gr.c b/lib/ax25_gr.c index 6ecf59e..69f0793 100644 --- a/lib/ax25_gr.c +++ b/lib/ax25_gr.c @@ -1,18 +1,18 @@ /* - * lib/ax25_gr.c This file contains an implementation of the "AX.25" - * route print support functions. + * lib/ax25_gr.c This file contains an implementation of the "AX.25" + * route print support functions. * - * Version: lib/ax25_gr.c 1.01 (1996-02-15) + * Version: $Id: ax25_gr.c,v 1.3 1998/11/15 20:09:22 freitag Exp $ * - * Author: Bernd Eckenfels, <ecki@lina.inka.de> - * Copyright 1999 Bernd Eckenfels, Germany - * base on Code from Jonathan Naylor <jsn@Cs.Nott.AC.UK> + * Author: Bernd Eckenfels, <ecki@lina.inka.de> + * Copyright 1999 Bernd Eckenfels, Germany + * base on Code from Jonathan Naylor <jsn@Cs.Nott.AC.UK> * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -38,28 +38,26 @@ int AX25_rprint(int options) { - FILE *f=fopen(_PATH_PROCNET_AX25_ROUTE, "r"); - char buffer[256]; - int use; + FILE *f = fopen(_PATH_PROCNET_AX25_ROUTE, "r"); + char buffer[256]; + int use; - if(f==NULL) - { - printf(_("AX.25 not configured in this system.\n")); /* xxx */ - return 1; - } - printf(_("Kernel AX.25 routing table\n")); /* xxx */ - printf(_("Destination Iface Use\n")); /* xxx */ - fgets(buffer,256,f); - while(fgets(buffer,256,f)) - { - buffer[9]=0; - buffer[14]=0; - use=atoi(buffer+15); - printf("%-9s %-5s %5d\n", - buffer,buffer+10,use); - } - fclose(f); - return 0; + if (f == NULL) { + printf(_("AX.25 not configured in this system.\n")); /* xxx */ + return 1; + } + printf(_("Kernel AX.25 routing table\n")); /* xxx */ + printf(_("Destination Iface Use\n")); /* xxx */ + fgets(buffer, 256, f); + while (fgets(buffer, 256, f)) { + buffer[9] = 0; + buffer[14] = 0; + use = atoi(buffer + 15); + printf("%-9s %-5s %5d\n", + buffer, buffer + 10, use); + } + fclose(f); + return 0; } -#endif /* HAVE_AFAX25 */ +#endif /* HAVE_AFAX25 */ @@ -1,14 +1,16 @@ /* - * DDP protocol output functions. - * [Not yet input] + * DDP protocol output functions. + * [Not yet input] * - * Alan Cox <Alan.Cox@linux.org> + * Alan Cox <Alan.Cox@linux.org> * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * $Id: ddp.c,v 1.4 1998/11/15 20:09:25 freitag Exp $ + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -29,34 +31,33 @@ #include "intl.h" /* Display a ddp domain address. */ -static char * -ddp_print(unsigned char *ptr) +static char *ddp_print(unsigned char *ptr) { - static char buff[64]; - struct sockaddr_at *sat=(struct sockaddr_at *)(ptr-2); - sprintf(buff,"%d/%d",(int) ntohs(sat->sat_addr.s_net), (int)sat->sat_addr.s_node); - return(buff); + static char buff[64]; + struct sockaddr_at *sat = (struct sockaddr_at *) (ptr - 2); + sprintf(buff, "%d/%d", (int) ntohs(sat->sat_addr.s_net), (int) sat->sat_addr.s_node); + return (buff); } /* Display a ddp domain address. */ -static char * -ddp_sprint(struct sockaddr *sap, int numeric) +static char *ddp_sprint(struct sockaddr *sap, int numeric) { - static char buf[64]; + static char buf[64]; - if (sap->sa_family != AF_APPLETALK) - return strncpy (buf, _("[NONE SET]"), sizeof (buf)); - return(ddp_print(sap->sa_data)); + if (sap->sa_family != AF_APPLETALK) + return strncpy(buf, _("[NONE SET]"), sizeof(buf)); + return (ddp_print(sap->sa_data)); } -struct aftype ddp_aftype = { - "ddp", NULL, /*"Appletalk DDP",*/ AF_APPLETALK, 0, - ddp_print, ddp_sprint, NULL, NULL, - NULL/*DDP_rprint*/, NULL, NULL, - -1, - "/proc/net/appletalk" +struct aftype ddp_aftype = +{ + "ddp", NULL, /*"Appletalk DDP", */ AF_APPLETALK, 0, + ddp_print, ddp_sprint, NULL, NULL, + NULL /*DDP_rprint */ , NULL, NULL, + -1, + "/proc/net/appletalk" }; #endif diff --git a/lib/ddp_gr.c b/lib/ddp_gr.c index 317fab3..94169f0 100644 --- a/lib/ddp_gr.c +++ b/lib/ddp_gr.c @@ -18,7 +18,7 @@ int DDP_rprint(int options) { - fprintf(stderr, _("Routing table for `ddp' not yet supported.\n")); - return(1); + fprintf(stderr, _("Routing table for `ddp' not yet supported.\n")); + return (1); } #endif diff --git a/lib/econet.c b/lib/econet.c index faf0246..41cbdac 100644 --- a/lib/econet.c +++ b/lib/econet.c @@ -1,19 +1,19 @@ /* - * lib/econet.c This file contains an implementation of the Econet - * support functions for the net-tools. - * (NET-3 base distribution). + * lib/econet.c This file contains an implementation of the Econet + * support functions for the net-tools. + * (NET-3 base distribution). * - * Version: lib/econet.c 1.00 1998-04-10 + * Version: $Id: econet.c,v 1.4 1998/11/15 20:09:30 freitag Exp $ * - * Author: Philip Blundell <philb@gnu.org> + * Author: Philip Blundell <philb@gnu.org> * * Modified: * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -33,54 +33,53 @@ /* Display an Econet address */ static char * -ec_print(unsigned char *ptr) + ec_print(unsigned char *ptr) { - static char buff[64]; - struct ec_addr *ec = (struct ec_addr *)ptr; - sprintf(buff,"%d.%d", ec->net, ec->station); - return buff; + static char buff[64]; + struct ec_addr *ec = (struct ec_addr *) ptr; + sprintf(buff, "%d.%d", ec->net, ec->station); + return buff; } /* Display an Econet socket address */ static char * -ec_sprint(struct sockaddr *sap, int numeric) + ec_sprint(struct sockaddr *sap, int numeric) { - struct sockaddr_ec *sec = (struct sockaddr_ec *)sap; + struct sockaddr_ec *sec = (struct sockaddr_ec *) sap; - if (sap->sa_family != AF_ECONET) - return _("[NONE SET]"); + if (sap->sa_family != AF_ECONET) + return _("[NONE SET]"); - return ec_print((unsigned char *)&sec->addr); + return ec_print((unsigned char *) &sec->addr); } -static int -ec_input(int type, char *bufp, struct sockaddr *sap) +static int ec_input(int type, char *bufp, struct sockaddr *sap) { - struct sockaddr_ec *sec = (struct sockaddr_ec *)sap; - int net, stn; - switch (sscanf(bufp, "%d.%d", &net, &stn)) - { - case 2: - sec->addr.station = stn; - sec->addr.net = net; - return 0; - case 1: - if (sscanf(bufp, "%d", &stn) == 1) { - sec->addr.net = 0; - sec->addr.station = stn; - return 0; + struct sockaddr_ec *sec = (struct sockaddr_ec *) sap; + int net, stn; + switch (sscanf(bufp, "%d.%d", &net, &stn)) { + case 2: + sec->addr.station = stn; + sec->addr.net = net; + return 0; + case 1: + if (sscanf(bufp, "%d", &stn) == 1) { + sec->addr.net = 0; + sec->addr.station = stn; + return 0; + } } - } - return -1; + return -1; } -struct aftype ec_aftype = { - "ec", NULL, AF_ECONET, 0, - ec_print, ec_sprint, ec_input, NULL, - NULL, NULL, NULL, - -1, - NULL +struct aftype ec_aftype = +{ + "ec", NULL, AF_ECONET, 0, + ec_print, ec_sprint, ec_input, NULL, + NULL, NULL, NULL, + -1, + NULL }; -#endif /* HAVE_AFECONET */ +#endif /* HAVE_AFECONET */ diff --git a/lib/ether.c b/lib/ether.c index 7991706..56f8dc1 100644 --- a/lib/ether.c +++ b/lib/ether.c @@ -1,17 +1,17 @@ /* - * lib/ether.c This file contains an implementation of the "Ethernet" - * support functions for the NET-2 base distribution. + * lib/ether.c This file contains an implementation of the "Ethernet" + * support functions. * - * Version: @(#)ether.c 1.10 10/07/93 + * Version: $Id: ether.c,v 1.4 1998/11/15 20:09:33 freitag Exp $ * - * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993 MicroWalt Corporation + * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Copyright 1993 MicroWalt Corporation * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -34,109 +34,114 @@ extern struct hwtype ether_hwtype; /* Display an Ethernet address in readable format. */ -static char * -pr_ether(unsigned char *ptr) +static char *pr_ether(unsigned char *ptr) { - static char buff[64]; + static char buff[64]; - snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X", - (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), - (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) - ); - return(buff); + snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X", + (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), + (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) + ); + return (buff); } /* Display an Ethernet socket address. */ -static char * -pr_sether(struct sockaddr *sap) +static char *pr_sether(struct sockaddr *sap) { - static char buf[64]; + static char buf[64]; - if (sap->sa_family == 0xFFFF || sap->sa_family == 0) - return strncpy (buf, _("[NONE SET]"), sizeof (buf)); - return(pr_ether(sap->sa_data)); + if (sap->sa_family == 0xFFFF || sap->sa_family == 0) + return strncpy(buf, _("[NONE SET]"), sizeof(buf)); + return (pr_ether(sap->sa_data)); } /* Input an Ethernet address and convert to binary. */ -static int -in_ether(char *bufp, struct sockaddr *sap) +static int in_ether(char *bufp, struct sockaddr *sap) { - unsigned char *ptr; - char c, *orig; - int i; - unsigned val; + unsigned char *ptr; + char c, *orig; + int i; + unsigned val; - sap->sa_family = ether_hwtype.type; - ptr = sap->sa_data; + sap->sa_family = ether_hwtype.type; + ptr = sap->sa_data; - i = 0; - orig = bufp; - while((*bufp != '\0') && (i < ETH_ALEN)) { + i = 0; + orig = bufp; + while ((*bufp != '\0') && (i < ETH_ALEN)) { val = 0; c = *bufp++; - if (isdigit(c)) val = c - '0'; - else if (c >= 'a' && c <= 'f') val = c - 'a' + 10; - else if (c >= 'A' && c <= 'F') val = c - 'A' + 10; - else { + if (isdigit(c)) + val = c - '0'; + else if (c >= 'a' && c <= 'f') + val = c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + val = c - 'A' + 10; + else { #ifdef DEBUG - fprintf(stderr, _("in_ether(%s): invalid ether address!\n"), orig); + fprintf(stderr, _("in_ether(%s): invalid ether address!\n"), orig); #endif - errno = EINVAL; - return(-1); + errno = EINVAL; + return (-1); } val <<= 4; c = *bufp; - if (isdigit(c)) val |= c - '0'; - else if (c >= 'a' && c <= 'f') val |= c - 'a' + 10; - else if (c >= 'A' && c <= 'F') val |= c - 'A' + 10; - else if (c == ':' || c == 0) val >>= 4; - else { + if (isdigit(c)) + val |= c - '0'; + else if (c >= 'a' && c <= 'f') + val |= c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + val |= c - 'A' + 10; + else if (c == ':' || c == 0) + val >>= 4; + else { #ifdef DEBUG - fprintf(stderr, _("in_ether(%s): invalid ether address!\n"), orig); + fprintf(stderr, _("in_ether(%s): invalid ether address!\n"), orig); #endif - errno = EINVAL; - return(-1); + errno = EINVAL; + return (-1); } - if (c != 0) bufp++; + if (c != 0) + bufp++; *ptr++ = (unsigned char) (val & 0377); i++; /* We might get a semicolon here - not required. */ if (*bufp == ':') { - if (i == ETH_ALEN) { + if (i == ETH_ALEN) { #ifdef DEBUG - fprintf(stderr, _("in_ether(%s): trailing : ignored!\n"), - orig) + fprintf(stderr, _("in_ether(%s): trailing : ignored!\n"), + orig) #endif - ; /* nothing */ - } - bufp++; + ; /* nothing */ + } + bufp++; } - } + } - /* That's it. Any trailing junk? */ - if ((i == ETH_ALEN) && (*bufp != '\0')) { + /* That's it. Any trailing junk? */ + if ((i == ETH_ALEN) && (*bufp != '\0')) { #ifdef DEBUG fprintf(stderr, _("in_ether(%s): trailing junk!\n"), orig); errno = EINVAL; - return(-1); + return (-1); #endif - } - + } #ifdef DEBUG - fprintf(stderr, "in_ether(%s): %s\n", orig, pr_ether(sap->sa_data)); + fprintf(stderr, "in_ether(%s): %s\n", orig, pr_ether(sap->sa_data)); #endif - return(0); + return (0); } -struct hwtype ether_hwtype = { - "ether", NULL, /*"10Mbps Ethernet",*/ ARPHRD_ETHER, ETH_ALEN, - pr_ether, pr_sether, in_ether, NULL +struct hwtype ether_hwtype = +{ + "ether", NULL, /*"10Mbps Ethernet", */ ARPHRD_ETHER, ETH_ALEN, + pr_ether, pr_sether, in_ether, NULL }; -#endif /* HAVE_HWETHER */ +#endif /* HAVE_HWETHER */ @@ -1,18 +1,18 @@ /* - * lib/fddi.c This file contains an implementation of the "FDDI" - * support functions for the NET-2 base distribution. + * lib/fddi.c This file contains an implementation of the "FDDI" + * support functions. * - * Version: @(#)fddi.c 1.01 07/01/1998 + * Version: $Id: fddi.c,v 1.4 1998/11/15 20:09:35 freitag Exp $ * - * Author: Lawrence V. Stefani, <stefani@lkg.dec.com> + * Author: Lawrence V. Stefani, <stefani@lkg.dec.com> * * 1998-07-01 - Arnaldo Carvalho de Melo <acme@conectiva.com.br> GNU gettext * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -45,106 +45,109 @@ extern struct hwtype fddi_hwtype; /* Display an FDDI address in readable format. */ -static char * -pr_fddi(unsigned char *ptr) +static char *pr_fddi(unsigned char *ptr) { - static char buff[64]; + static char buff[64]; - snprintf(buff, sizeof(buff), "%02X-%02X-%02X-%02X-%02X-%02X", - (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), - (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) - ); - return(buff); + snprintf(buff, sizeof(buff), "%02X-%02X-%02X-%02X-%02X-%02X", + (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), + (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) + ); + return (buff); } /* Display an FDDI socket address. */ -static char * -pr_sfddi(struct sockaddr *sap) +static char *pr_sfddi(struct sockaddr *sap) { - static char buf[64]; + static char buf[64]; - if (sap->sa_family == 0xFFFF || sap->sa_family == 0) - return strncpy (buf, _("[NONE SET]"), sizeof (buf)); - return(pr_fddi(sap->sa_data)); + if (sap->sa_family == 0xFFFF || sap->sa_family == 0) + return strncpy(buf, _("[NONE SET]"), sizeof(buf)); + return (pr_fddi(sap->sa_data)); } /* Input an FDDI address and convert to binary. */ -static int -in_fddi(char *bufp, struct sockaddr *sap) +static int in_fddi(char *bufp, struct sockaddr *sap) { - unsigned char *ptr; - char c, *orig; - int i, val; + unsigned char *ptr; + char c, *orig; + int i, val; - sap->sa_family = fddi_hwtype.type; - ptr = sap->sa_data; + sap->sa_family = fddi_hwtype.type; + ptr = sap->sa_data; - i = 0; - orig = bufp; - while((*bufp != '\0') && (i < FDDI_K_ALEN)) { + i = 0; + orig = bufp; + while ((*bufp != '\0') && (i < FDDI_K_ALEN)) { val = 0; c = *bufp++; - if (isdigit(c)) val = c - '0'; - else if (c >= 'a' && c <= 'f') val = c - 'a' + 10; - else if (c >= 'A' && c <= 'F') val = c - 'A' + 10; - else { + if (isdigit(c)) + val = c - '0'; + else if (c >= 'a' && c <= 'f') + val = c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + val = c - 'A' + 10; + else { #ifdef DEBUG - fprintf(stderr, _("in_fddi(%s): invalid fddi address!\n"), orig); + fprintf(stderr, _("in_fddi(%s): invalid fddi address!\n"), orig); #endif - errno = EINVAL; - return(-1); + errno = EINVAL; + return (-1); } val <<= 4; c = *bufp++; - if (isdigit(c)) val |= c - '0'; - else if (c >= 'a' && c <= 'f') val |= c - 'a' + 10; - else if (c >= 'A' && c <= 'F') val |= c - 'A' + 10; - else { + if (isdigit(c)) + val |= c - '0'; + else if (c >= 'a' && c <= 'f') + val |= c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + val |= c - 'A' + 10; + else { #ifdef DEBUG - fprintf(stderr, _("in_fddi(%s): invalid fddi address!\n"), orig); + fprintf(stderr, _("in_fddi(%s): invalid fddi address!\n"), orig); #endif - errno = EINVAL; - return(-1); + errno = EINVAL; + return (-1); } *ptr++ = (unsigned char) (val & 0377); i++; /* We might get a semicolon here - not required. */ if (*bufp == ':') { - if (i == FDDI_K_ALEN) { + if (i == FDDI_K_ALEN) { #ifdef DEBUG - fprintf(stderr, _("in_fddi(%s): trailing : ignored!\n"), - orig) + fprintf(stderr, _("in_fddi(%s): trailing : ignored!\n"), + orig) #endif - ; /* nothing */ - } - bufp++; + ; /* nothing */ + } + bufp++; } - } + } - /* That's it. Any trailing junk? */ - if ((i == FDDI_K_ALEN) && (*bufp != '\0')) { + /* That's it. Any trailing junk? */ + if ((i == FDDI_K_ALEN) && (*bufp != '\0')) { #ifdef DEBUG fprintf(stderr, _("in_fddi(%s): trailing junk!\n"), orig); errno = EINVAL; - return(-1); + return (-1); #endif - } - + } #ifdef DEBUG - fprintf(stderr, "in_fddi(%s): %s\n", orig, pr_fddi(sap->sa_data)); + fprintf(stderr, "in_fddi(%s): %s\n", orig, pr_fddi(sap->sa_data)); #endif - return(0); + return (0); } -struct hwtype fddi_hwtype = { - "fddi", NULL, /*"Fiber Distributed Data Interface (FDDI)",*/ ARPHRD_FDDI, FDDI_K_ALEN, - pr_fddi, pr_sfddi, in_fddi, NULL +struct hwtype fddi_hwtype = +{ + "fddi", NULL, /*"Fiber Distributed Data Interface (FDDI)", */ ARPHRD_FDDI, FDDI_K_ALEN, + pr_fddi, pr_sfddi, in_fddi, NULL }; -#endif /* HAVE_HWFDDI */ +#endif /* HAVE_HWFDDI */ diff --git a/lib/frame.c b/lib/frame.c index e24e06e..1cfd88e 100644 --- a/lib/frame.c +++ b/lib/frame.c @@ -1,22 +1,22 @@ /* - * lib/frame.c This file contains the Frame Relay support. + * lib/frame.c This file contains the Frame Relay support. * - * Version: lib/frame.c 0.01 (1996-03-23) + * Version: $Id: frame.c,v 1.3 1998/11/15 20:09:39 freitag Exp $ * - * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de> + * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de> * - * Author: Mike McLagan <mike.mclagan@linux.org> + * Author: Mike McLagan <mike.mclagan@linux.org> * * Changes: * - *962303 {0.01} Mike McLagan : creation - *960413 {0.02} Bernd Eckenfels : included in net-lib + *962303 {0.01} Mike McLagan : creation + *960413 {0.02} Bernd Eckenfels : included in net-lib * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -39,19 +39,21 @@ char *pr_dlci(unsigned char *ptr) { - static char buf[12]; + static char buf[12]; - snprintf(buf, sizeof(buf), "%i", *(short *)ptr); - return(buf); + snprintf(buf, sizeof(buf), "%i", *(short *) ptr); + return (buf); } -struct hwtype dlci_hwtype = { - "dlci", NULL, /*"Frame Relay DLCI",*/ ARPHRD_DLCI, 3, - pr_dlci, NULL, NULL, NULL +struct hwtype dlci_hwtype = +{ + "dlci", NULL, /*"Frame Relay DLCI", */ ARPHRD_DLCI, 3, + pr_dlci, NULL, NULL, NULL }; -struct hwtype frad_hwtype = { - "frad", NULL, /*"Frame Relay Access Device",*/ ARPHRD_FRAD, 0, - NULL, NULL, NULL, NULL +struct hwtype frad_hwtype = +{ + "frad", NULL, /*"Frame Relay Access Device", */ ARPHRD_FRAD, 0, + NULL, NULL, NULL, NULL }; -#endif /* HAVE_HWFR */ +#endif /* HAVE_HWFR */ diff --git a/lib/getargs.c b/lib/getargs.c index cebd91b..4170097 100644 --- a/lib/getargs.c +++ b/lib/getargs.c @@ -1,16 +1,16 @@ /* - * lib/getargs.c General argument parser. + * lib/getargs.c General argument parser. * - * Version: @(#)getargs.c 4.0.1 04/05/94 + * Version: $Id: getargs.c,v 1.3 1998/11/15 20:09:43 freitag Exp $ * * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993,1994 MicroWalt Corporation + * Copyright 1993,1994 MicroWalt Corporation * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" #include <sys/types.h> @@ -27,61 +27,65 @@ /* Split the input string into multiple fields. */ -int -getargs(char *string, char *arguments[]) +int getargs(char *string, char *arguments[]) { - char temp[1024]; - char *sp, *ptr; - int i, argc; - char want; + int len = strlen(string); + char temp[len+1]; + char *sp, *ptr; + int i, argc; + char want; - /* - * Copy the string into a buffer. We may have to modify - * the original string because of all the quoting... - */ - sp = string; i = 0; - strcpy(temp, string); - ptr = temp; - - /* - * Look for delimiters ("); if present whatever - * they enclose will be considered one argument. - */ - while (*ptr != '\0' && i < 31) { + /* + * Copy the string into a buffer. We may have to modify + * the original string because of all the quoting... + */ + sp = string; + i = 0; + strcpy(temp, string); + ptr = temp; + + /* + * Look for delimiters ("); if present whatever + * they enclose will be considered one argument. + */ + while (*ptr != '\0' && i < 31) { /* Ignore leading whitespace on input string. */ - while (*ptr == ' ' || *ptr == '\t') ptr++; + while (*ptr == ' ' || *ptr == '\t') + ptr++; /* Set string pointer. */ arguments[i++] = sp; /* Check for any delimiters. */ if (*ptr == '"' || *ptr == '\'') { - /* - * Copy the string up to any whitespace OR the next - * delimiter. If the delimiter was escaped, skip it - * as it if was not there. - */ - want = *ptr++; - while(*ptr != '\0') { - if (*ptr == want && *(ptr - 1) != '\\') { - ptr++; - break; - } - *sp++ = *ptr++; + /* + * Copy the string up to any whitespace OR the next + * delimiter. If the delimiter was escaped, skip it + * as it if was not there. + */ + want = *ptr++; + while (*ptr != '\0') { + if (*ptr == want && *(ptr - 1) != '\\') { + ptr++; + break; } + *sp++ = *ptr++; + } } else { - /* Just copy the string up to any whitespace. */ - while(*ptr != '\0' && *ptr != ' ' && *ptr != '\t') - *sp++ = *ptr++; + /* Just copy the string up to any whitespace. */ + while (*ptr != '\0' && *ptr != ' ' && *ptr != '\t') + *sp++ = *ptr++; } *sp++ = '\0'; /* Skip trailing whitespace. */ if (*ptr != '\0') { - while(*ptr == ' ' || *ptr == '\t') ptr++; + while (*ptr == ' ' || *ptr == '\t') + ptr++; } - } - argc = i; - while (i < 32) arguments[i++] = (char *)NULL; - return(argc); + } + argc = i; + while (i < 32) + arguments[i++] = (char *) NULL; + return (argc); } diff --git a/lib/getroute.c b/lib/getroute.c index d6d282e..f4b91e7 100644 --- a/lib/getroute.c +++ b/lib/getroute.c @@ -1,33 +1,33 @@ /* - * lib/getroute.c This file contains a small interface function to - * use the AF specific print routine for the routing - * table. + * lib/getroute.c This file contains a small interface function to + * use the AF specific print routine for the routing + * table. * - * NET-LIB A collection of functions used from the base set of the - * NET-3 Networking Distribution for the LINUX operating - * system. (net-tools, net-drivers) + * NET-LIB A collection of functions used from the base set of the + * NET-3 Networking Distribution for the LINUX operating + * system. (net-tools, net-drivers) * - * Version: lib/getroute.c 1.03 (1996-04-13) + * Version: $Id: getroute.c,v 1.3 1998/11/15 20:09:47 freitag Exp $ * - * Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de> - * Copyright 1999 Bernd Eckenfels, Germany + * Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de> + * Copyright 1999 Bernd Eckenfels, Germany * * Modifications: * - *951020 {0.10} Bernd Eckenfels: creation - *960202 {0.90} Bernd Eckenfels: rewrite to use getaftype. - *960204 {0.91} Bernd Eckenfels: takes constant list of AFs - *960206 {1.01} Bernd Eckenfels: route_init will enable routing - * support in the AF handlers - *960221 {1.02} Bernd Eckenfels: renamed from route_info to getroute.c - *960413 {1.03} Bernd Eckenfels: new RTACTION support + *951020 {0.10} Bernd Eckenfels: creation + *960202 {0.90} Bernd Eckenfels: rewrite to use getaftype. + *960204 {0.91} Bernd Eckenfels: takes constant list of AFs + *960206 {1.01} Bernd Eckenfels: route_init will enable routing + * support in the AF handlers + *960221 {1.02} Bernd Eckenfels: renamed from route_info to getroute.c + *960413 {1.03} Bernd Eckenfels: new RTACTION support *980701 {1.04} Arnaldo C. Melo: GNU gettext instead of catgets * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include <stdio.h> #include <string.h> @@ -37,81 +37,77 @@ #include "config.h" #include "intl.h" -extern struct aftype unspec_aftype; -extern struct aftype unix_aftype; -extern struct aftype inet_aftype; -extern struct aftype inet6_aftype; -extern struct aftype ax25_aftype; -extern struct aftype netrom_aftype; -extern struct aftype ipx_aftype; -extern struct aftype ddp_aftype; +extern struct aftype unspec_aftype; +extern struct aftype unix_aftype; +extern struct aftype inet_aftype; +extern struct aftype inet6_aftype; +extern struct aftype ax25_aftype; +extern struct aftype netrom_aftype; +extern struct aftype ipx_aftype; +extern struct aftype ddp_aftype; -void -getroute_init(void) +void getroute_init(void) { #if HAVE_AFINET - inet_aftype.rprint = INET_rprint; + inet_aftype.rprint = INET_rprint; #endif #if HAVE_AFINET6 - inet6_aftype.rprint = INET6_rprint; + inet6_aftype.rprint = INET6_rprint; #endif #if HAVE_AFNETROM - netrom_aftype.rprint = NETROM_rprint; + netrom_aftype.rprint = NETROM_rprint; #endif #if HAVE_AFAX25 - ax25_aftype.rprint = AX25_rprint; + ax25_aftype.rprint = AX25_rprint; #endif #if HAVE_AFIPX - ipx_aftype.rprint = IPX_rprint; + ipx_aftype.rprint = IPX_rprint; #endif #if HAVE_AFATALK - ddp_aftype.rprint = DDP_rprint; + ddp_aftype.rprint = DDP_rprint; #endif } -int -route_info(const char *afname, int options) +int route_info(const char *afname, int options) { - struct aftype *ap; - char *tmp1,*tmp2; - int found=E_NOTFOUND,rc; - char buf[256]; - - strncpy(buf,afname,sizeof(buf)); - buf[sizeof(buf)-1]='\0'; - - tmp1=buf; - - while(tmp1) { - - ap=NULL; - - if ((tmp2=index(tmp1,','))) - *tmp2++='\0'; - + struct aftype *ap; + char *tmp1, *tmp2; + int found = E_NOTFOUND, rc; + char buf[256]; + + strncpy(buf, afname, sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + + tmp1 = buf; + + while (tmp1) { + + ap = NULL; + + if ((tmp2 = index(tmp1, ','))) + *tmp2++ = '\0'; + if (!tmp1[0]) { - tmp1=tmp2; - continue; + tmp1 = tmp2; + continue; } - - ap = get_aftype(tmp1); - - if (!ap) { - fprintf(stderr,_("Address family `%s' not supported.\n"),tmp1); - return(E_OPTERR); - } - tmp1=tmp2; - - if (!ap->rprint) { - fprintf(stderr,_("No routing for address family `%s'.\n"),ap->name); - return(E_OPTERR); - } - - found = 0; - + ap = get_aftype(tmp1); + + if (!ap) { + fprintf(stderr, _("Address family `%s' not supported.\n"), tmp1); + return (E_OPTERR); + } + tmp1 = tmp2; + + if (!ap->rprint) { + fprintf(stderr, _("No routing for address family `%s'.\n"), ap->name); + return (E_OPTERR); + } + found = 0; + if ((rc = ap->rprint(options))) - return(rc); - - } - return(found); + return (rc); + + } + return (found); } diff --git a/lib/hdlclapb.c b/lib/hdlclapb.c index c5a0ce7..4cac136 100644 --- a/lib/hdlclapb.c +++ b/lib/hdlclapb.c @@ -1,21 +1,21 @@ /* * lib/hdlclapb.c - * This file contains the HDLC/LAPB support for the NET-2 base - * distribution. + * This file contains the HDLC/LAPB support for the NET-2 base + * distribution. * - * Version: @(#)hdlclapb.c 0.10 22/04/1998 + * Version: $Id: hdlclapb.c,v 1.3 1998/11/15 20:09:55 freitag Exp $ * - * Original Author: - * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993 MicroWalt Corporation + * Original Author: + * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Copyright 1993 MicroWalt Corporation * - * Modified by Alan Cox, May 94 to cover NET-3 + * Modified by Alan Cox, May 94 to cover NET-3 * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -36,13 +36,15 @@ #include "net-support.h" #include "pathnames.h" -struct hwtype hdlc_hwtype = { - "hdlc", NULL, /*"(Cisco) HDLC",*/ ARPHRD_HDLC, 0, - NULL, NULL, NULL, NULL, +struct hwtype hdlc_hwtype = +{ + "hdlc", NULL, /*"(Cisco) HDLC", */ ARPHRD_HDLC, 0, + NULL, NULL, NULL, NULL, }; -struct hwtype lapb_hwtype = { - "lapb", NULL, /*"LAPB",*/ ARPHRD_LAPB, 0, - NULL, NULL, NULL, NULL, +struct hwtype lapb_hwtype = +{ + "lapb", NULL, /*"LAPB", */ ARPHRD_LAPB, 0, + NULL, NULL, NULL, NULL, }; -#endif /* HAVE_HWHDLCLAPB */ +#endif /* HAVE_HWHDLCLAPB */ diff --git a/lib/hippi.c b/lib/hippi.c index ce58462..0086a76 100644 --- a/lib/hippi.c +++ b/lib/hippi.c @@ -1,19 +1,19 @@ /* - * lib/hippi.c This file contains an implementation of the "HIPPI" - * support functions for the NET-2 base distribution. + * lib/hippi.c This file contains an implementation of the "HIPPI" + * support functions for the NET-2 base distribution. * - * Version: @(#)hippi.c 1.0 06/06/97 + * Version: $Id$ * - * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993 MicroWalt Corporation + * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Copyright 1993 MicroWalt Corporation * - * Modified for HIPPI by Jes Sorensen, <Jes.Sorensen@cern.ch> + * Modified for HIPPI by Jes Sorensen, <Jes.Sorensen@cern.ch> * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -36,114 +36,118 @@ #include "intl.h" /* - * HIPPI magic constants. + * HIPPI magic constants. */ -#define HIPPI_ALEN 6 /* Bytes in one HIPPI hw-addr */ +#define HIPPI_ALEN 6 /* Bytes in one HIPPI hw-addr */ extern struct hwtype hippi_hwtype; /* Display an HIPPI address in readable format. */ -static char * -pr_hippi(unsigned char *ptr) +static char *pr_hippi(unsigned char *ptr) { - static char buff[64]; + static char buff[64]; - sprintf(buff, "%02X:%02X:%02X:%02X:%02X:%02X", - (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), - (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) - ); - return(buff); + sprintf(buff, "%02X:%02X:%02X:%02X:%02X:%02X", + (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), + (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) + ); + return (buff); } /* Display an HIPPI socket address. */ static char * -pr_shippi(struct sockaddr *sap) + pr_shippi(struct sockaddr *sap) { - static char buf[64]; + static char buf[64]; - if (sap->sa_family == 0xFFFF || sap->sa_family == 0) - return(strncpy(buf, _("[NONE SET]"), 64)); - return(pr_hippi(sap->sa_data)); + if (sap->sa_family == 0xFFFF || sap->sa_family == 0) + return (strncpy(buf, _("[NONE SET]"), 64)); + return (pr_hippi(sap->sa_data)); } /* Input an HIPPI address and convert to binary. */ -static int -in_hippi(char *bufp, struct sockaddr *sap) +static int in_hippi(char *bufp, struct sockaddr *sap) { - unsigned char *ptr; - char c, *orig; - int i, val; + unsigned char *ptr; + char c, *orig; + int i, val; - sap->sa_family = hippi_hwtype.type; - ptr = sap->sa_data; + sap->sa_family = hippi_hwtype.type; + ptr = sap->sa_data; - i = 0; - orig = bufp; - while((*bufp != '\0') && (i < HIPPI_ALEN)) { + i = 0; + orig = bufp; + while ((*bufp != '\0') && (i < HIPPI_ALEN)) { val = 0; c = *bufp++; - if (isdigit(c)) val = c - '0'; - else if (c >= 'a' && c <= 'f') val = c - 'a' + 10; - else if (c >= 'A' && c <= 'F') val = c - 'A' + 10; - else { + if (isdigit(c)) + val = c - '0'; + else if (c >= 'a' && c <= 'f') + val = c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + val = c - 'A' + 10; + else { #ifdef DEBUG - fprintf(stderr, _("in_hippi(%s): invalid hippi address!\n"), orig); + fprintf(stderr, _("in_hippi(%s): invalid hippi address!\n"), orig); #endif - errno = EINVAL; - return(-1); + errno = EINVAL; + return (-1); } val <<= 4; c = *bufp++; - if (isdigit(c)) val |= c - '0'; - else if (c >= 'a' && c <= 'f') val |= c - 'a' + 10; - else if (c >= 'A' && c <= 'F') val |= c - 'A' + 10; - else { + if (isdigit(c)) + val |= c - '0'; + else if (c >= 'a' && c <= 'f') + val |= c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + val |= c - 'A' + 10; + else { #ifdef DEBUG - fprintf(stderr, _("in_hippi(%s): invalid hippi address!\n"), orig); + fprintf(stderr, _("in_hippi(%s): invalid hippi address!\n"), orig); #endif - errno = EINVAL; - return(-1); + errno = EINVAL; + return (-1); } *ptr++ = (unsigned char) (val & 0377); i++; /* We might get a semicolon here - not required. */ if (*bufp == ':') { - if (i == HIPPI_ALEN) { + if (i == HIPPI_ALEN) { #ifdef DEBUG - fprintf(stderr, _("in_hippi(%s): trailing : ignored!\n"), orig) + fprintf(stderr, _("in_hippi(%s): trailing : ignored!\n"), orig) #endif - ; /* nothing */ - } - bufp++; + ; /* nothing */ + } + bufp++; } - } + } - /* That's it. Any trailing junk? */ - if ((i == HIPPI_ALEN) && (*bufp != '\0')) { + /* That's it. Any trailing junk? */ + if ((i == HIPPI_ALEN) && (*bufp != '\0')) { #ifdef DEBUG fprintf(stderr, _("in_hippi(%s): trailing junk!\n"), orig); errno = EINVAL; - return(-1); + return (-1); #endif - } - + } #ifdef DEBUG - fprintf(stderr, "in_hippi(%s): %s\n", orig, pr_hippi(sap->sa_data)); + fprintf(stderr, "in_hippi(%s): %s\n", orig, pr_hippi(sap->sa_data)); #endif - return(0); + return (0); } -struct hwtype hippi_hwtype = { - "hippi", NULL, /*"HIPPI",*/ ARPHRD_HIPPI, HIPPI_ALEN, - pr_hippi, pr_shippi, in_hippi, NULL +struct hwtype hippi_hwtype = +{ + "hippi", NULL, /*"HIPPI", */ ARPHRD_HIPPI, HIPPI_ALEN, + pr_hippi, pr_shippi, in_hippi, NULL }; -#endif /* HAVE_HWHIPPI */ +#endif /* HAVE_HWHIPPI */ @@ -1,21 +1,21 @@ /* - * lib/hw.c This file contains the top-level part of the hardware - * support functions module for the NET-2 base distribution. + * lib/hw.c This file contains the top-level part of the hardware + * support functions module. * - * Version: lib/hw.c 1.21 (1998-07-01) + * Version: $Id: hw.c,v 1.8 1998/11/15 20:10:13 freitag Exp $ * - * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de> + * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de> * - * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993 MicroWalt Corporation + * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Copyright 1993 MicroWalt Corporation * *980701 {1.21} Arnaldo C. Melo GNU gettext instead of catgets * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include <sys/types.h> #include <sys/socket.h> @@ -30,186 +30,187 @@ #include "pathnames.h" #include "intl.h" -extern struct hwtype unspec_hwtype; -extern struct hwtype loop_hwtype; +extern struct hwtype unspec_hwtype; +extern struct hwtype loop_hwtype; -extern struct hwtype slip_hwtype; -extern struct hwtype cslip_hwtype; -extern struct hwtype slip6_hwtype; -extern struct hwtype cslip6_hwtype; -extern struct hwtype adaptive_hwtype; +extern struct hwtype slip_hwtype; +extern struct hwtype cslip_hwtype; +extern struct hwtype slip6_hwtype; +extern struct hwtype cslip6_hwtype; +extern struct hwtype adaptive_hwtype; -extern struct hwtype ether_hwtype; -extern struct hwtype fddi_hwtype; -extern struct hwtype hippi_hwtype; -extern struct hwtype tr_hwtype; +extern struct hwtype ether_hwtype; +extern struct hwtype fddi_hwtype; +extern struct hwtype hippi_hwtype; +extern struct hwtype tr_hwtype; -extern struct hwtype ax25_hwtype; -extern struct hwtype rose_hwtype; -extern struct hwtype netrom_hwtype; -extern struct hwtype tunnel_hwtype; +extern struct hwtype ax25_hwtype; +extern struct hwtype rose_hwtype; +extern struct hwtype netrom_hwtype; +extern struct hwtype tunnel_hwtype; -extern struct hwtype ash_hwtype; +extern struct hwtype ash_hwtype; -extern struct hwtype ppp_hwtype; +extern struct hwtype ppp_hwtype; -extern struct hwtype arcnet_hwtype; +extern struct hwtype arcnet_hwtype; -extern struct hwtype dlci_hwtype; -extern struct hwtype frad_hwtype; +extern struct hwtype dlci_hwtype; +extern struct hwtype frad_hwtype; -extern struct hwtype hdlc_hwtype; -extern struct hwtype lapb_hwtype; +extern struct hwtype hdlc_hwtype; +extern struct hwtype lapb_hwtype; -extern struct hwtype sit_hwtype; +extern struct hwtype sit_hwtype; -static struct hwtype *hwtypes[] = { +static struct hwtype *hwtypes[] = +{ - &loop_hwtype, + &loop_hwtype, #if HAVE_HWSLIP - &slip_hwtype, - &cslip_hwtype, - &slip6_hwtype, - &cslip6_hwtype, - &adaptive_hwtype, + &slip_hwtype, + &cslip_hwtype, + &slip6_hwtype, + &cslip6_hwtype, + &adaptive_hwtype, #endif #if HAVE_HWASH - &ash_hwtype, + &ash_hwtype, #endif #if HAVE_HWETHER - ðer_hwtype, + ðer_hwtype, #endif #if HAVE_HWTR - &tr_hwtype, + &tr_hwtype, #endif #if HAVE_HWAX25 - &ax25_hwtype, + &ax25_hwtype, #endif #if HAVE_HWNETROM - &netrom_hwtype, + &netrom_hwtype, #endif #if HAVE_HWTUNNEL - &tunnel_hwtype, + &tunnel_hwtype, #endif #if HAVE_HWPPP - &ppp_hwtype, -#endif + &ppp_hwtype, +#endif #if HAVE_HWHDLCLAPB - &hdlc_hwtype, - &lapb_hwtype, + &hdlc_hwtype, + &lapb_hwtype, #endif #if HAVE_HWARC - &arcnet_hwtype, -#endif + &arcnet_hwtype, +#endif #if HAVE_HWFR - &dlci_hwtype, - &frad_hwtype, + &dlci_hwtype, + &frad_hwtype, #endif #if HAVE_HWSIT - &sit_hwtype, + &sit_hwtype, #endif #if HAVE_HWROSE - &rose_hwtype, + &rose_hwtype, #endif #if HAVE_HWFDDI - &fddi_hwtype, + &fddi_hwtype, #endif #if HAVE_HWHIPPI - &hippi_hwtype, + &hippi_hwtype, #endif - &unspec_hwtype, - NULL + &unspec_hwtype, + NULL }; static short sVhwinit = 0; -void hwinit () +void hwinit() { - loop_hwtype.title = _("Local Loopback"); - unspec_hwtype.title = _("UNSPEC"); + loop_hwtype.title = _("Local Loopback"); + unspec_hwtype.title = _("UNSPEC"); #if HAVE_HWSLIP - slip_hwtype.title = _("Serial Line IP"); - cslip_hwtype.title = _("VJ Serial Line IP"); - slip6_hwtype.title = _("6-bit Serial Line IP"); - cslip6_hwtype.title = _("VJ 6-bit Serial Line IP"); - adaptive_hwtype.title = _("Adaptive Serial Line IP"); + slip_hwtype.title = _("Serial Line IP"); + cslip_hwtype.title = _("VJ Serial Line IP"); + slip6_hwtype.title = _("6-bit Serial Line IP"); + cslip6_hwtype.title = _("VJ 6-bit Serial Line IP"); + adaptive_hwtype.title = _("Adaptive Serial Line IP"); #endif #if HAVE_HWETHER - ether_hwtype.title = _("Ethernet"); + ether_hwtype.title = _("Ethernet"); #endif #if HAVE_HWASH - ash_hwtype.title = _("Ash"); + ash_hwtype.title = _("Ash"); #endif #if HAVE_HWFDDI - fddi_hwtype.title = _("Fiber Distributed Data Interface"); + fddi_hwtype.title = _("Fiber Distributed Data Interface"); #endif #if HAVE_HWHIPPI - hippi_hwtype.title = _("HIPPI"); + hippi_hwtype.title = _("HIPPI"); #endif #if HAVE_HWAX25 - ax25_hwtype.title = _("AMPR AX.25"); + ax25_hwtype.title = _("AMPR AX.25"); #endif #if HAVE_HWROSE - rose_hwtype.title = _("AMPR ROSE"); + rose_hwtype.title = _("AMPR ROSE"); #endif #if HAVE_HWNETROM - netrom_hwtype.title = _("AMPR NET/ROM"); + netrom_hwtype.title = _("AMPR NET/ROM"); #endif #if HAVE_HWTUNNEL - tunnel_hwtype.title = _("IPIP Tunnel"); + tunnel_hwtype.title = _("IPIP Tunnel"); #endif #if HAVE_HWPPP - ppp_hwtype.title = _("Point-to-Point Protocol"); -#endif + ppp_hwtype.title = _("Point-to-Point Protocol"); +#endif #if HAVE_HWHDLCLAPB - hdlc_hwtype.title = _("(Cisco)-HDLC"); - lapb_hwtype.title = _("LAPB"); + hdlc_hwtype.title = _("(Cisco)-HDLC"); + lapb_hwtype.title = _("LAPB"); #endif #if HAVE_HWARC - arcnet_hwtype.title = _("1.5Mbps ARCnet"); + arcnet_hwtype.title = _("1.5Mbps ARCnet"); #endif #if HAVE_HWFR - dlci_hwtype.title = _("Frame Relay DLCI"); - frad_hwtype.title = _("Frame Relay Access Device"); + dlci_hwtype.title = _("Frame Relay DLCI"); + frad_hwtype.title = _("Frame Relay Access Device"); #endif #if HAVE_HWSIT - sit_hwtype.title = _("IPv6-in-IPv4"); + sit_hwtype.title = _("IPv6-in-IPv4"); #endif - sVhwinit = 1; + sVhwinit = 1; } /* Check our hardware type table for this type. */ -struct hwtype * -get_hwtype(const char *name) +struct hwtype *get_hwtype(const char *name) { - struct hwtype **hwp; - - if (!sVhwinit) - hwinit(); - - hwp = hwtypes; - while (*hwp != NULL) { - if (!strcmp((*hwp)->name, name)) return(*hwp); + struct hwtype **hwp; + + if (!sVhwinit) + hwinit(); + + hwp = hwtypes; + while (*hwp != NULL) { + if (!strcmp((*hwp)->name, name)) + return (*hwp); hwp++; - } - return(NULL); + } + return (NULL); } /* Check our hardware type table for this type. */ -struct hwtype * -get_hwntype(int type) +struct hwtype *get_hwntype(int type) { - struct hwtype **hwp; + struct hwtype **hwp; - if (!sVhwinit) - hwinit(); + if (!sVhwinit) + hwinit(); - hwp = hwtypes; - while (*hwp != NULL) { - if ((*hwp)->type == type) return(*hwp); + hwp = hwtypes; + while (*hwp != NULL) { + if ((*hwp)->type == type) + return (*hwp); hwp++; - } - return(NULL); + } + return (NULL); } @@ -1,26 +1,26 @@ /* - * lib/inet.c This file contains an implementation of the "INET" - * support functions for the net-tools. - * (NET-3 base distribution). + * lib/inet.c This file contains an implementation of the "INET" + * support functions for the net-tools. + * (NET-3 base distribution). * - * Version: lib/inet.c 1.26 1996-03-29 + * Version: $Id: inet.c,v 1.5 1998/11/15 20:10:27 freitag Exp $ * - * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993 MicroWalt Corporation + * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Copyright 1993 MicroWalt Corporation * * Modified: - *960113 {1.21} Bernd Eckenfels : rresolve cache bug. - *960128 {1.22} Bernd Eckenfels : endian bug in print + *960113 {1.21} Bernd Eckenfels : rresolve cache bug. + *960128 {1.22} Bernd Eckenfels : endian bug in print *960203 {1.23} Bernd Eckenfels : net-features support - *960217 {1.24} Bernd Eckenfels : get_sname - *960219 {1.25} Bernd Eckenfels : extern int h_errno - *960329 {1.26} Bernd Eckenfels : resolve 255.255.255.255 + *960217 {1.24} Bernd Eckenfels : get_sname + *960219 {1.25} Bernd Eckenfels : extern int h_errno + *960329 {1.26} Bernd Eckenfels : resolve 255.255.255.255 * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -43,342 +43,329 @@ #include "pathnames.h" #include "intl.h" -extern int h_errno; /* some netdb.h versions don't export this */ +extern int h_errno; /* some netdb.h versions don't export this */ struct addr { - struct sockaddr_in addr; - char *name; - struct addr *next; + struct sockaddr_in addr; + char *name; + struct addr *next; }; struct service { - int number; - char *name; - struct service *next; + int number; + char *name; + struct service *next; }; -static struct service *tcp_name = NULL, - *udp_name = NULL, - *raw_name = NULL; +static struct service *tcp_name = NULL, *udp_name = NULL, *raw_name = NULL; -static struct addr *INET_nn = NULL; /* addr-to-name cache */ +static struct addr *INET_nn = NULL; /* addr-to-name cache */ -static int -INET_resolve(char *name, struct sockaddr_in *sin) +static int INET_resolve(char *name, struct sockaddr_in *sin) { - struct hostent *hp; - struct netent *np; + struct hostent *hp; + struct netent *np; - /* Grmpf. -FvK */ - sin->sin_family = AF_INET; - sin->sin_port = 0; + /* Grmpf. -FvK */ + sin->sin_family = AF_INET; + sin->sin_port = 0; - /* Default is special, meaning 0.0.0.0. */ - if (!strcmp(name, "default")) { + /* Default is special, meaning 0.0.0.0. */ + if (!strcmp(name, "default")) { sin->sin_addr.s_addr = INADDR_ANY; - return(1); - } - - /* Look to see if it's a dotted quad. */ - if (inet_aton(name, &sin->sin_addr)) { - return 0; - } - - /* Try the NETWORKS database to see if this is a known network. */ - if ((np = getnetbyname(name)) != (struct netent *)NULL) { - sin->sin_addr.s_addr = htonl(np->n_net); - strcpy(name, np->n_name); - return 1; - } - + return (1); + } + /* Look to see if it's a dotted quad. */ + if (inet_aton(name, &sin->sin_addr)) { + return 0; + } + /* Try the NETWORKS database to see if this is a known network. */ + if ((np = getnetbyname(name)) != (struct netent *) NULL) { + sin->sin_addr.s_addr = htonl(np->n_net); + strcpy(name, np->n_name); + return 1; + } #ifdef DEBUG - res_init(); - _res.options |= RES_DEBUG; + res_init(); + _res.options |= RES_DEBUG; #endif - if ((hp = gethostbyname(name)) == (struct hostent *)NULL) { - errno = h_errno; - return -1; - } - memcpy((char *) &sin->sin_addr, (char *) hp->h_addr_list[0], hp->h_length); - strcpy(name, hp->h_name); - return 0; + if ((hp = gethostbyname(name)) == (struct hostent *) NULL) { + errno = h_errno; + return -1; + } + memcpy((char *) &sin->sin_addr, (char *) hp->h_addr_list[0], hp->h_length); + strcpy(name, hp->h_name); + return 0; } -static int -INET_rresolve(char *name, struct sockaddr_in *sin, int numeric) +static int INET_rresolve(char *name, struct sockaddr_in *sin, int numeric) { - struct hostent *ent; - struct netent *np; - struct addr *pn; - unsigned long ad, host_ad; + struct hostent *ent; + struct netent *np; + struct addr *pn; + unsigned long ad, host_ad; - /* Grmpf. -FvK */ - if (sin->sin_family != AF_INET) { + /* Grmpf. -FvK */ + if (sin->sin_family != AF_INET) { #ifdef DEBUG fprintf(stderr, _("rresolve: unsupport address family %d !\n"), sin->sin_family); #endif errno = EAFNOSUPPORT; - return(-1); - } - - ad = (unsigned long) sin->sin_addr.s_addr; - if (ad == INADDR_ANY) { + return (-1); + } + ad = (unsigned long) sin->sin_addr.s_addr; + if (ad == INADDR_ANY) { if ((numeric & 0x7FFF) == 0) { - if (numeric & 0x8000) strcpy(name, "default"); - else strcpy(name, "*"); - return(0); + if (numeric & 0x8000) + strcpy(name, "default"); + else + strcpy(name, "*"); + return (0); } - } - if (numeric & 0x7FFF) { - strcpy(name,inet_ntoa (sin->sin_addr)); - return(0); - } - + } + if (numeric & 0x7FFF) { + strcpy(name, inet_ntoa(sin->sin_addr)); + return (0); + } #if 0 - INET_nn = NULL; + INET_nn = NULL; #endif - pn = INET_nn; - while (pn != NULL) { + pn = INET_nn; + while (pn != NULL) { if (pn->addr.sin_addr.s_addr == ad) { - strcpy(name, pn->name); - return(0); + strcpy(name, pn->name); + return (0); } pn = pn->next; - } + } - host_ad = ntohl(ad); - np = NULL; - ent = NULL; - if ((host_ad & 0xFF) != 0) { + host_ad = ntohl(ad); + np = NULL; + ent = NULL; + if ((host_ad & 0xFF) != 0) { ent = gethostbyaddr((char *) &ad, 4, AF_INET); if (ent != NULL) - strcpy(name, ent->h_name); - } else { + strcpy(name, ent->h_name); + } else { np = getnetbyaddr(host_ad, AF_INET); if (np != NULL) { - strcpy(name, np->n_name); + strcpy(name, np->n_name); } - } - if ((ent == NULL) && (np == NULL)) { - strcpy(name,inet_ntoa (sin->sin_addr)); - } - pn = (struct addr *)malloc(sizeof(struct addr)); - pn->addr = *sin; - pn->next = INET_nn; - pn->name = (char *) malloc(strlen(name) + 1); - strcpy(pn->name, name); - INET_nn = pn; - - return(0); + } + if ((ent == NULL) && (np == NULL)) { + strcpy(name, inet_ntoa(sin->sin_addr)); + } + pn = (struct addr *) malloc(sizeof(struct addr)); + pn->addr = *sin; + pn->next = INET_nn; + pn->name = (char *) malloc(strlen(name) + 1); + strcpy(pn->name, name); + INET_nn = pn; + + return (0); } -static void -INET_reserror(char *text) +static void INET_reserror(char *text) { - herror(text); + herror(text); } /* Display an Internet socket address. */ -static char * -INET_print(unsigned char *ptr) +static char *INET_print(unsigned char *ptr) { - return(inet_ntoa((*(struct in_addr *) ptr))); + return (inet_ntoa((*(struct in_addr *) ptr))); } /* Display an Internet socket address. */ -static char * -INET_sprint(struct sockaddr *sap, int numeric) +static char *INET_sprint(struct sockaddr *sap, int numeric) { - static char buff[128]; + static char buff[128]; - if (sap->sa_family == 0xFFFF || sap->sa_family == 0) - return strncpy (buff, _("[NONE SET]"), sizeof(buff)); - if (INET_rresolve(buff, (struct sockaddr_in *) sap, numeric) != 0) - return(NULL); - return(buff); + if (sap->sa_family == 0xFFFF || sap->sa_family == 0) + return strncpy(buff, _("[NONE SET]"), sizeof(buff)); + if (INET_rresolve(buff, (struct sockaddr_in *) sap, numeric) != 0) + return (NULL); + return (buff); } -static int -INET_getsock(char *bufp, struct sockaddr *sap) +static int INET_getsock(char *bufp, struct sockaddr *sap) { - char *sp = bufp,*bp; - unsigned int i; - unsigned val; - struct sockaddr_in *sin; - - sin = (struct sockaddr_in *) sap; - sin->sin_family = AF_INET; - sin->sin_port = 0; - - val = 0; - bp=(char *)&val; - for (i = 0; i < sizeof(sin->sin_addr.s_addr); i++) { + char *sp = bufp, *bp; + unsigned int i; + unsigned val; + struct sockaddr_in *sin; + + sin = (struct sockaddr_in *) sap; + sin->sin_family = AF_INET; + sin->sin_port = 0; + + val = 0; + bp = (char *) &val; + for (i = 0; i < sizeof(sin->sin_addr.s_addr); i++) { *sp = toupper(*sp); - - if ((*sp >= 'A') && (*sp <= 'F')) - bp[i] |= (int) (*sp - 'A') + 10; + + if ((*sp >= 'A') && (*sp <= 'F')) + bp[i] |= (int) (*sp - 'A') + 10; else if ((*sp >= '0') && (*sp <= '9')) - bp[i] |= (int) (*sp - '0'); + bp[i] |= (int) (*sp - '0'); else - return(-1); + return (-1); bp[i] <<= 4; sp++; *sp = toupper(*sp); - - if ((*sp >= 'A') && (*sp <= 'F')) - bp[i] |= (int) (*sp - 'A') + 10; + + if ((*sp >= 'A') && (*sp <= 'F')) + bp[i] |= (int) (*sp - 'A') + 10; else if ((*sp >= '0') && (*sp <= '9')) - bp[i] |= (int) (*sp - '0'); + bp[i] |= (int) (*sp - '0'); else - return(-1); - + return (-1); + sp++; } - sin->sin_addr.s_addr = htonl (val); + sin->sin_addr.s_addr = htonl(val); - return(sp-bufp); + return (sp - bufp); } -static int -INET_input(int type, char *bufp, struct sockaddr *sap) +static int INET_input(int type, char *bufp, struct sockaddr *sap) { - switch(type) { - case 1: - return(INET_getsock(bufp,sap)); - default: - return(INET_resolve(bufp, (struct sockaddr_in *) sap)); - } + switch (type) { + case 1: + return (INET_getsock(bufp, sap)); + default: + return (INET_resolve(bufp, (struct sockaddr_in *) sap)); + } } static int INET_getnetmask(char *adr, struct sockaddr *m, char *name) -{ - struct sockaddr_in *mask = (struct sockaddr_in *)m; - char *slash, *end; - int prefix; - - if ((slash = strchr(adr, '/')) == NULL) - return 0; - - *slash++ = '\0'; - prefix = strtoul(slash,&end,0); - if (*end != '\0') - return -1; - - if (name) { - sprintf(name, "/%d", prefix); - } - - mask->sin_family = AF_INET; - mask->sin_addr.s_addr = htonl(~(0xffffffffU >> prefix)); - return 1; -} +{ + struct sockaddr_in *mask = (struct sockaddr_in *) m; + char *slash, *end; + int prefix; + + if ((slash = strchr(adr, '/')) == NULL) + return 0; + + *slash++ = '\0'; + prefix = strtoul(slash, &end, 0); + if (*end != '\0') + return -1; + + if (name) { + sprintf(name, "/%d", prefix); + } + mask->sin_family = AF_INET; + mask->sin_addr.s_addr = htonl(~(0xffffffffU >> prefix)); + return 1; +} -struct aftype inet_aftype = { - "inet", NULL, /*"DARPA Internet",*/ AF_INET, sizeof(unsigned long), - INET_print, INET_sprint, INET_input, INET_reserror, - NULL/*INET_rprint*/, NULL/*INET_rinput*/, - INET_getnetmask, - -1, - NULL +struct aftype inet_aftype = +{ + "inet", NULL, /*"DARPA Internet", */ AF_INET, sizeof(unsigned long), + INET_print, INET_sprint, INET_input, INET_reserror, + NULL /*INET_rprint */ , NULL /*INET_rinput */ , + INET_getnetmask, + -1, + NULL }; -#endif /* HAVE_AFINET || HAVE_AFINET6 */ +#endif /* HAVE_AFINET || HAVE_AFINET6 */ #if HAVE_AFINET || HAVE_AFINET6 -static void -add2list(struct service **namebase, struct service *item) +static void add2list(struct service **namebase, struct service *item) { - if (*namebase == NULL) { + if (*namebase == NULL) { *namebase = item; item->next = NULL; - } else { + } else { item->next = *namebase; *namebase = item; - } + } } -static struct service * -searchlist(struct service *servicebase, int number) +static struct service *searchlist(struct service *servicebase, int number) { - struct service *item; + struct service *item; - for(item = servicebase; item != NULL; item = item->next) { - if (item->number == number) return(item); - } - return(NULL); + for (item = servicebase; item != NULL; item = item->next) { + if (item->number == number) + return (item); + } + return (NULL); } -static int -read_services(void) +static int read_services(void) { - struct servent *se; - struct service *item; + struct servent *se; + struct service *item; - setservent(1); - while((se=getservent())) { + setservent(1); + while ((se = getservent())) { /* Allocate a service entry. */ item = (struct service *) malloc(sizeof(struct service)); - if (item == NULL) perror("netstat"); + if (item == NULL) + perror("netstat"); item->name = strdup(se->s_name); item->number = se->s_port; /* Fill it in. */ - if (! strcmp(se->s_proto, "tcp")) { - add2list(&tcp_name,item); - } else if (! strcmp(se->s_proto, "udp")) { - add2list(&udp_name,item); - } else if (! strcmp(se->s_proto, "raw")) { - add2list(&raw_name,item); + if (!strcmp(se->s_proto, "tcp")) { + add2list(&tcp_name, item); + } else if (!strcmp(se->s_proto, "udp")) { + add2list(&udp_name, item); + } else if (!strcmp(se->s_proto, "raw")) { + add2list(&raw_name, item); } - } - endservent(); - return(0); + } + endservent(); + return (0); } -char * -get_sname(int socknumber, char *proto, int numeric) +char *get_sname(int socknumber, char *proto, int numeric) { - static char buffer[64], init=0; - struct service *item; + static char buffer[64], init = 0; + struct service *item; - if (socknumber == 0) return("*"); - if (numeric) { + if (socknumber == 0) + return ("*"); + if (numeric) { sprintf(buffer, "%d", ntohs(socknumber)); - return(buffer); - } - if (!init) { - (void)read_services(); - init=1; - } - buffer[0]='\0'; - if (! strcmp(proto, "tcp")) { + return (buffer); + } + if (!init) { + (void) read_services(); + init = 1; + } + buffer[0] = '\0'; + if (!strcmp(proto, "tcp")) { if ((item = searchlist(tcp_name, socknumber)) != NULL) - sprintf(buffer, "%s", item->name); - } else if (! strcmp(proto, "udp")) { + sprintf(buffer, "%s", item->name); + } else if (!strcmp(proto, "udp")) { if ((item = searchlist(udp_name, socknumber)) != NULL) - sprintf(buffer, "%s", item->name); - } else if (! strcmp(proto, "raw")) { + sprintf(buffer, "%s", item->name); + } else if (!strcmp(proto, "raw")) { if ((item = searchlist(raw_name, socknumber)) != NULL) - sprintf(buffer, "%s", item->name); + sprintf(buffer, "%s", item->name); - } - if (!buffer[0]) - sprintf(buffer, "%d", ntohs(socknumber)); - return(buffer); + } + if (!buffer[0]) + sprintf(buffer, "%d", ntohs(socknumber)); + return (buffer); } -#endif /* HAVE_AFINET || HAVE_AFINET6 */ +#endif /* HAVE_AFINET || HAVE_AFINET6 */ diff --git a/lib/inet6.c b/lib/inet6.c index 564de85..7c11528 100644 --- a/lib/inet6.c +++ b/lib/inet6.c @@ -1,22 +1,22 @@ /* - * lib/inet6.c This file contains an implementation of the "INET6" - * support functions for the net-tools. - * (most of it copied from lib/inet.c 1.26). + * lib/inet6.c This file contains an implementation of the "INET6" + * support functions for the net-tools. + * (most of it copied from lib/inet.c 1.26). * - * Version: lib/inet6.c 0.02 1998-07-01 + * Version: $Id: inet6.c,v 1.4 1998/11/15 20:10:37 freitag Exp $ * - * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993 MicroWalt Corporation + * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Copyright 1993 MicroWalt Corporation * * Modified: - *960808 {0.01} Frank Strauss : adapted for IPv6 support + *960808 {0.01} Frank Strauss : adapted for IPv6 support *980701 {0.02} Arnaldo C. Melo: GNU gettext instead of catgets * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -40,126 +40,116 @@ #include "pathnames.h" #include "intl.h" -extern int h_errno; /* some netdb.h versions don't export this */ +extern int h_errno; /* some netdb.h versions don't export this */ -static int -INET6_resolve(char *name, struct sockaddr_in6 *sin6) +static int INET6_resolve(char *name, struct sockaddr_in6 *sin6) { - struct addrinfo req, *ai; - int s; + struct addrinfo req, *ai; + int s; - req.ai_family = AF_INET6; - if ((s = getaddrinfo(name, NULL, &req, &ai))) { - fprintf(stderr, "getaddrinfo: %s: %s\n", name, gai_strerror(s)); - return -1; - } + req.ai_family = AF_INET6; + if ((s = getaddrinfo(name, NULL, &req, &ai))) { + fprintf(stderr, "getaddrinfo: %s: %s\n", name, gai_strerror(s)); + return -1; + } + memcpy(sin6, ai->ai_addr, sizeof(struct sockaddr_in6)); - memcpy(sin6, ai->ai_addr, sizeof(struct sockaddr_in6)); + freeaddrinfo(ai); - freeaddrinfo(ai); - - return(0); + return (0); } -static int -INET6_rresolve(char *name, struct sockaddr_in6 *sin6, int numeric) +static int INET6_rresolve(char *name, struct sockaddr_in6 *sin6, int numeric) { - int s; + int s; - /* Grmpf. -FvK */ - if (sin6->sin6_family != AF_INET6) { + /* Grmpf. -FvK */ + if (sin6->sin6_family != AF_INET6) { #ifdef DEBUG fprintf(stderr, _("rresolve: unsupport address family %d !\n"), - sin6->sin6_family); + sin6->sin6_family); #endif errno = EAFNOSUPPORT; - return(-1); - } - - if (numeric & 0x7FFF) { - inet_ntop(AF_INET6, &sin6->sin6_addr, name, 80); - return(0); - } - - if ((s = getnameinfo((struct sockaddr *)sin6, sizeof(struct sockaddr_in6), - name, 255 /* !! */, NULL, 0, 0))) { - fprintf(stderr, "getnameinfo: %s\n", gai_strerror(s)); - return -1; - } - - return(0); + return (-1); + } + if (numeric & 0x7FFF) { + inet_ntop(AF_INET6, &sin6->sin6_addr, name, 80); + return (0); + } + if ((s = getnameinfo((struct sockaddr *) sin6, sizeof(struct sockaddr_in6), + name, 255 /* !! */ , NULL, 0, 0))) { + fprintf(stderr, "getnameinfo: %s\n", gai_strerror(s)); + return -1; + } + return (0); } -static void -INET6_reserror(char *text) +static void INET6_reserror(char *text) { - herror(text); + herror(text); } /* Display an Internet socket address. */ -static char * -INET6_print(unsigned char *ptr) +static char *INET6_print(unsigned char *ptr) { - static char name[80]; + static char name[80]; - inet_ntop(AF_INET6, (struct in6_addr *)ptr, name, 80); - return name; + inet_ntop(AF_INET6, (struct in6_addr *) ptr, name, 80); + return name; } /* Display an Internet socket address. */ /* dirty! struct sockaddr usually doesn't suffer for inet6 addresses, fst. */ -static char * -INET6_sprint(struct sockaddr *sap, int numeric) +static char *INET6_sprint(struct sockaddr *sap, int numeric) { - static char buff[128]; + static char buff[128]; - if (sap->sa_family == 0xFFFF || sap->sa_family == 0) - return strncpy (buff, _("[NONE SET]"), sizeof (buff)); - if (INET6_rresolve(buff, (struct sockaddr_in6 *) sap, numeric) != 0) - return(NULL); - return(buff); + if (sap->sa_family == 0xFFFF || sap->sa_family == 0) + return strncpy(buff, _("[NONE SET]"), sizeof(buff)); + if (INET6_rresolve(buff, (struct sockaddr_in6 *) sap, numeric) != 0) + return (NULL); + return (buff); } -static int -INET6_getsock(char *bufp, struct sockaddr *sap) +static int INET6_getsock(char *bufp, struct sockaddr *sap) { - struct sockaddr_in6 *sin6; - - sin6 = (struct sockaddr_in6 *) sap; - sin6->sin6_family = AF_INET6; - sin6->sin6_port = 0; + struct sockaddr_in6 *sin6; + + sin6 = (struct sockaddr_in6 *) sap; + sin6->sin6_family = AF_INET6; + sin6->sin6_port = 0; - if (inet_pton(AF_INET6, bufp, sin6->sin6_addr.s6_addr) <= 0) - return(-1); + if (inet_pton(AF_INET6, bufp, sin6->sin6_addr.s6_addr) <= 0) + return (-1); - return 16; /* ?;) */ + return 16; /* ?;) */ } -static int -INET6_input(int type, char *bufp, struct sockaddr *sap) +static int INET6_input(int type, char *bufp, struct sockaddr *sap) { - switch(type) { - case 1: - return(INET6_getsock(bufp, sap)); - default: - return(INET6_resolve(bufp, (struct sockaddr_in6 *) sap)); - } + switch (type) { + case 1: + return (INET6_getsock(bufp, sap)); + default: + return (INET6_resolve(bufp, (struct sockaddr_in6 *) sap)); + } } -struct aftype inet6_aftype = { - "inet6", NULL, /*"IPv6",*/ AF_INET6, sizeof(struct in6_addr), - INET6_print, INET6_sprint, INET6_input, INET6_reserror, - INET6_rprint, INET6_rinput, NULL, +struct aftype inet6_aftype = +{ + "inet6", NULL, /*"IPv6", */ AF_INET6, sizeof(struct in6_addr), + INET6_print, INET6_sprint, INET6_input, INET6_reserror, + INET6_rprint, INET6_rinput, NULL, - -1, - "/proc/net/if_inet6" + -1, + "/proc/net/if_inet6" }; -#endif /* HAVE_AFINET6 */ +#endif /* HAVE_AFINET6 */ diff --git a/lib/inet6_gr.c b/lib/inet6_gr.c index f54cc7d..42f8839 100644 --- a/lib/inet6_gr.c +++ b/lib/inet6_gr.c @@ -1,8 +1,8 @@ /* - Modifications: - 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets, - snprintf instead of sprintf -*/ + Modifications: + 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets, + snprintf instead of sprintf + */ #include "config.h" @@ -24,7 +24,7 @@ #include <stdio.h> #include <unistd.h> #ifndef __GLIBC__ -#include <netinet6/ipv6_route.h> /* glibc doesn't have this */ +#include <netinet6/ipv6_route.h> /* glibc doesn't have this */ #endif #include "version.h" #include "net-support.h" @@ -34,11 +34,11 @@ /* this is from linux/include/net/ndisc.h */ /* - * Neighbor Cache Entry States (7.3.2.) + * Neighbor Cache Entry States (7.3.2.) */ /* - * The lsb is set for states that have a timer associated + * The lsb is set for states that have a timer associated */ #define NUD_NONE 0x00 @@ -47,45 +47,43 @@ #define NUD_STALE 0x30 #define NUD_DELAY 0x41 #define NUD_PROBE 0x51 -#define NUD_FAILED 0x60 /* neighbour discovery failed */ +#define NUD_FAILED 0x60 /* neighbour discovery failed */ #define NUD_IN_TIMER 0x01 #define NDISC_QUEUE_LEN 3 #define NCF_NOARP 0x0100 /* no ARP needed on this device */ -#define NCF_SUBNET 0x0200 /* NC entry for subnet */ +#define NCF_SUBNET 0x0200 /* NC entry for subnet */ #define NCF_INVALID 0x0400 -#define NCF_DELAY_EXPIRED 0x0800 /* time to move to PROBE */ -#define NCF_ROUTER 0x1000 /* neighbour is a router */ -#define NCF_HHVALID 0x2000 /* Hardware header is valid */ +#define NCF_DELAY_EXPIRED 0x0800 /* time to move to PROBE */ +#define NCF_ROUTER 0x1000 /* neighbour is a router */ +#define NCF_HHVALID 0x2000 /* Hardware header is valid */ -extern struct aftype inet6_aftype; +extern struct aftype inet6_aftype; int rprint_fib6(int ext, int numeric) { - char buff[4096], iface[16], flags[16]; - char addr6[128], naddr6[128]; - struct sockaddr_in6 saddr6, snaddr6; - int num, iflags, metric, refcnt, use, prefix_len, slen; - FILE *fp=fopen(_PATH_PROCNET_ROUTE6, "r"); - char addr6p[8][5], saddr6p[8][5], naddr6p[8][5]; - - if (!fp) { - ESYSNOT("getroute","INET6 FIB"); - return 1; - } + char buff[4096], iface[16], flags[16]; + char addr6[128], naddr6[128]; + struct sockaddr_in6 saddr6, snaddr6; + int num, iflags, metric, refcnt, use, prefix_len, slen; + FILE *fp = fopen(_PATH_PROCNET_ROUTE6, "r"); + char addr6p[8][5], saddr6p[8][5], naddr6p[8][5]; - printf(_("Kernel IPv6 routing table\n")); + if (!fp) { + ESYSNOT("getroute", "INET6 FIB"); + return 1; + } + printf(_("Kernel IPv6 routing table\n")); - printf(_("Destination " - "Next Hop " - "Flags Metric Ref Use Iface\n")); + printf(_("Destination " + "Next Hop " + "Flags Metric Ref Use Iface\n")); - while (fgets(buff, 1023, fp)) - { + while (fgets(buff, 1023, fp)) { num = sscanf(buff, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %4s%4s%4s%4s%4s%4s%4s%4s %02x %4s%4s%4s%4s%4s%4s%4s%4s %08x %08x %08x %08x %s\n", addr6p[0], addr6p[1], addr6p[2], addr6p[3], addr6p[4], addr6p[5], addr6p[6], addr6p[7], @@ -97,168 +95,179 @@ int rprint_fib6(int ext, int numeric) naddr6p[4], naddr6p[5], naddr6p[6], naddr6p[7], &metric, &use, &refcnt, &iflags, iface); #if 0 - if (num < 23) continue; + if (num < 23) + continue; #endif - if (!(iflags & RTF_UP)) continue; + if (!(iflags & RTF_UP)) + continue; /* Fetch and resolve the target address. */ snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s", - addr6p[0], addr6p[1], addr6p[2], addr6p[3], - addr6p[4], addr6p[5], addr6p[6], addr6p[7]); - inet6_aftype.input(1, addr6, (struct sockaddr *)&saddr6); + addr6p[0], addr6p[1], addr6p[2], addr6p[3], + addr6p[4], addr6p[5], addr6p[6], addr6p[7]); + inet6_aftype.input(1, addr6, (struct sockaddr *) &saddr6); snprintf(addr6, sizeof(addr6), "%s/%d", - inet6_aftype.sprint((struct sockaddr *)&saddr6, 1), - prefix_len); - + inet6_aftype.sprint((struct sockaddr *) &saddr6, 1), + prefix_len); + /* Fetch and resolve the nexthop address. */ snprintf(naddr6, sizeof(naddr6), "%s:%s:%s:%s:%s:%s:%s:%s", - naddr6p[0], naddr6p[1], naddr6p[2], naddr6p[3], - naddr6p[4], naddr6p[5], naddr6p[6], naddr6p[7]); - inet6_aftype.input(1, naddr6, (struct sockaddr *)&snaddr6); + naddr6p[0], naddr6p[1], naddr6p[2], naddr6p[3], + naddr6p[4], naddr6p[5], naddr6p[6], naddr6p[7]); + inet6_aftype.input(1, naddr6, (struct sockaddr *) &snaddr6); snprintf(naddr6, sizeof(naddr6), "%s", - inet6_aftype.sprint((struct sockaddr *)&snaddr6, 1)); - + inet6_aftype.sprint((struct sockaddr *) &snaddr6, 1)); + /* Decode the flags. */ strcpy(flags, "U"); - if (iflags & RTF_GATEWAY) strcat(flags, "G"); - if (iflags & RTF_HOST) strcat(flags, "H"); - if (iflags & RTF_DEFAULT) strcat(flags, "D"); - if (iflags & RTF_ADDRCONF) strcat(flags, "A"); - if (iflags & RTF_CACHE) strcat(flags, "C"); - + if (iflags & RTF_GATEWAY) + strcat(flags, "G"); + if (iflags & RTF_HOST) + strcat(flags, "H"); + if (iflags & RTF_DEFAULT) + strcat(flags, "D"); + if (iflags & RTF_ADDRCONF) + strcat(flags, "A"); + if (iflags & RTF_CACHE) + strcat(flags, "C"); + /* Print the info. */ printf("%-43s %-39s %-5s %-6d %-2d %7d %-8s\n", addr6, naddr6, flags, metric, refcnt, use, iface); - } + } - (void) fclose(fp); - return(0); + (void) fclose(fp); + return (0); } int rprint_cache6(int ext, int numeric) { - char buff[4096], iface[16], flags[16]; - char addr6[128], haddr[20], statestr[20]; - struct sockaddr_in6 saddr6; - int type, num, refcnt, prefix_len, location,state,gc; - long tstamp, expire, ndflags,reachable,stale,delete; - FILE *fp=fopen(_PATH_PROCNET_NDISC, "r"); - char addr6p[8][5], haddrp[6][3]; - - if (!fp) { - ESYSNOT("nd_print","ND Table"); - return 1; - } + char buff[4096], iface[16], flags[16]; + char addr6[128], haddr[20], statestr[20]; + struct sockaddr_in6 saddr6; + int type, num, refcnt, prefix_len, location, state, gc; + long tstamp, expire, ndflags, reachable, stale, delete; + FILE *fp = fopen(_PATH_PROCNET_NDISC, "r"); + char addr6p[8][5], haddrp[6][3]; - printf(_("Kernel IPv6 Neighbour Cache\n")); + if (!fp) { + ESYSNOT("nd_print", "ND Table"); + return 1; + } + printf(_("Kernel IPv6 Neighbour Cache\n")); - if (ext == 2) - printf(_("Neighbour " - "HW Address " - "Iface Flags Ref State\n")); - else - printf(_("Neighbour " - "HW Address " - "Iface Flags Ref State Stale(sec) Delete(sec)\n")); + if (ext == 2) + printf(_("Neighbour " + "HW Address " + "Iface Flags Ref State\n")); + else + printf(_("Neighbour " + "HW Address " + "Iface Flags Ref State Stale(sec) Delete(sec)\n")); - while (fgets(buff, 1023, fp)) - { + while (fgets(buff, 1023, fp)) { num = sscanf(buff, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %08lx %08lx %08lx %04x %04x %04lx %8s %2s%2s%2s%2s%2s%2s\n", addr6p[0], addr6p[1], addr6p[2], addr6p[3], addr6p[4], addr6p[5], addr6p[6], addr6p[7], &location, &prefix_len, &type, &state, &expire, &tstamp, &reachable, &gc, &refcnt, &ndflags, iface, - haddrp[0], haddrp[1], haddrp[2], haddrp[3], haddrp[4], haddrp[5]); + haddrp[0], haddrp[1], haddrp[2], haddrp[3], haddrp[4], haddrp[5]); /* Fetch and resolve the nexthop address. */ snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s", - addr6p[0], addr6p[1], addr6p[2], addr6p[3], - addr6p[4], addr6p[5], addr6p[6], addr6p[7]); - inet6_aftype.input(1, addr6, (struct sockaddr *)&saddr6); + addr6p[0], addr6p[1], addr6p[2], addr6p[3], + addr6p[4], addr6p[5], addr6p[6], addr6p[7]); + inet6_aftype.input(1, addr6, (struct sockaddr *) &saddr6); snprintf(addr6, sizeof(addr6), "%s/%d", - inet6_aftype.sprint((struct sockaddr *)&saddr6, numeric), - prefix_len); - + inet6_aftype.sprint((struct sockaddr *) &saddr6, numeric), + prefix_len); + /* Fetch the hardware address. */ snprintf(haddr, sizeof(haddr), "%s:%s:%s:%s:%s:%s", - haddrp[0],haddrp[1],haddrp[2], haddrp[3],haddrp[4],haddrp[5]); - + haddrp[0], haddrp[1], haddrp[2], haddrp[3], haddrp[4], haddrp[5]); + /* Decode the flags. */ flags[0] = '\0'; - if (ndflags & NCF_NOARP) strcat(flags, "N"); - if (ndflags & NCF_SUBNET) strcat(flags, "S"); - if (ndflags & NCF_INVALID) strcat(flags, "I"); - if (ndflags & NCF_DELAY_EXPIRED) strcat(flags, "D"); - if (ndflags & NCF_ROUTER) strcat(flags, "R"); - if (ndflags & NCF_HHVALID) strcat(flags, "H"); + if (ndflags & NCF_NOARP) + strcat(flags, "N"); + if (ndflags & NCF_SUBNET) + strcat(flags, "S"); + if (ndflags & NCF_INVALID) + strcat(flags, "I"); + if (ndflags & NCF_DELAY_EXPIRED) + strcat(flags, "D"); + if (ndflags & NCF_ROUTER) + strcat(flags, "R"); + if (ndflags & NCF_HHVALID) + strcat(flags, "H"); /* Decode the state */ switch (state) { case NUD_NONE: - strcpy(statestr,"NONE"); - break; + strcpy(statestr, "NONE"); + break; case NUD_INCOMPLETE: - strcpy(statestr,"INCOMPLETE"); - break; + strcpy(statestr, "INCOMPLETE"); + break; case NUD_REACHABLE: - strcpy(statestr,"REACHABLE"); - break; + strcpy(statestr, "REACHABLE"); + break; case NUD_STALE: - strcpy(statestr,"STALE"); - break; + strcpy(statestr, "STALE"); + break; case NUD_DELAY: - strcpy(statestr,"DELAY"); - break; + strcpy(statestr, "DELAY"); + break; case NUD_PROBE: - strcpy(statestr,"PROBE"); - break; + strcpy(statestr, "PROBE"); + break; case NUD_FAILED: - strcpy(statestr,"FAILED"); - break; + strcpy(statestr, "FAILED"); + break; case NUD_IN_TIMER: - strcpy(statestr,"IN TIMER"); - break; + strcpy(statestr, "IN TIMER"); + break; default: - snprintf(statestr,sizeof (statestr),"UNKNOWN %02x",state); - break; + snprintf(statestr, sizeof(statestr), "UNKNOWN %02x", state); + break; } - + /* Print the info. */ printf("%-43s %-17s %-8s %-5s %-3d %-16s", addr6, haddr, iface, flags, refcnt, statestr); - stale=0; - if (state==NUD_REACHABLE) - stale = reachable > tstamp?reachable - tstamp:0; - delete = gc > tstamp?gc - tstamp:0; - if (ext!=2){ - printf(" %-9ld ",stale/HZ); - if (refcnt) - printf(" * "); - else - printf(" %-7ld ",delete/HZ); + stale = 0; + if (state == NUD_REACHABLE) + stale = reachable > tstamp ? reachable - tstamp : 0; + delete = gc > tstamp ? gc - tstamp : 0; + if (ext != 2) { + printf(" %-9ld ", stale / HZ); + if (refcnt) + printf(" * "); + else + printf(" %-7ld ", delete / HZ); } printf("\n"); - } + } - (void) fclose(fp); - return(0); + (void) fclose(fp); + return (0); } int INET6_rprint(int options) { - int ext = options & FLAG_EXT; - int numeric = options & (FLAG_NUM|FLAG_SYM); - int rc = E_INTERN; - - if (options & FLAG_FIB) - if ((rc = rprint_fib6(ext,numeric))) - return(rc); - - if (options & FLAG_CACHE) - if ((rc = rprint_cache6(ext,numeric))) - return(rc); - return(rc); + int ext = options & FLAG_EXT; + int numeric = options & (FLAG_NUM | FLAG_SYM); + int rc = E_INTERN; + + if (options & FLAG_FIB) + if ((rc = rprint_fib6(ext, numeric))) + return (rc); + + if (options & FLAG_CACHE) + if ((rc = rprint_cache6(ext, numeric))) + return (rc); + return (rc); } -#endif /* HAVE_AFINET6 */ +#endif /* HAVE_AFINET6 */ diff --git a/lib/inet6_sr.c b/lib/inet6_sr.c index 988d46d..7aa0c4d 100644 --- a/lib/inet6_sr.c +++ b/lib/inet6_sr.c @@ -1,7 +1,7 @@ /* - Modifications: - 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets -*/ + Modifications: + 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets + */ #include "config.h" @@ -24,8 +24,8 @@ #include <string.h> #include <stdio.h> #include <unistd.h> -#ifndef __GLIBC__ -#include <netinet6/ipv6_route.h> /* glibc does not have this */ +#ifndef __GLIBC__ +#include <netinet6/ipv6_route.h> /* glibc does not have this */ #endif #include "version.h" #include "net-support.h" @@ -33,158 +33,155 @@ #include "intl.h" #include "net-features.h" -extern struct aftype inet6_aftype; +extern struct aftype inet6_aftype; static int skfd = -1; static int usage(void) { - fprintf(stderr,_("Usage: inet6_route [-vF] del Target\n")); - fprintf(stderr,_(" inet6_route [-vF] add Target [gw Gw] [metric M] [[dev] If]\n")); - fprintf(stderr,_(" inet6_route [-FC] flush NOT supported\n")); - return(E_USAGE); + fprintf(stderr, _("Usage: inet6_route [-vF] del Target\n")); + fprintf(stderr, _(" inet6_route [-vF] add Target [gw Gw] [metric M] [[dev] If]\n")); + fprintf(stderr, _(" inet6_route [-FC] flush NOT supported\n")); + return (E_USAGE); } static int INET6_setroute(int action, int options, char **args) { - struct in6_rtmsg rt; - struct ifreq ifr; - struct sockaddr_in6 sa6; - char target[128], gateway[128] = "NONE"; - int metric, prefix_len; - char *devname = NULL; - char *cp; - - if (*args == NULL) - return(usage()); - - strcpy(target, *args++); - if ((cp = strchr(target, '/'))) { - prefix_len = atol(cp+1); - if ((prefix_len < 0) || (prefix_len > 128)) usage(); - *cp = 0; - } else { - prefix_len = 128; - } - - /* Clean out the RTREQ structure. */ - memset((char *) &rt, 0, sizeof(struct in6_rtmsg)); - - if (inet6_aftype.input(1, target, (struct sockaddr *)&sa6) < 0) { + struct in6_rtmsg rt; + struct ifreq ifr; + struct sockaddr_in6 sa6; + char target[128], gateway[128] = "NONE"; + int metric, prefix_len; + char *devname = NULL; + char *cp; + + if (*args == NULL) + return (usage()); + + strcpy(target, *args++); + if ((cp = strchr(target, '/'))) { + prefix_len = atol(cp + 1); + if ((prefix_len < 0) || (prefix_len > 128)) + usage(); + *cp = 0; + } else { + prefix_len = 128; + } + + /* Clean out the RTREQ structure. */ + memset((char *) &rt, 0, sizeof(struct in6_rtmsg)); + + if (inet6_aftype.input(1, target, (struct sockaddr *) &sa6) < 0) { inet6_aftype.herror(target); return (1); - } - memcpy(&rt.rtmsg_dst, sa6.sin6_addr.s6_addr, sizeof(struct in6_addr)); - - /* Fill in the other fields. */ - rt.rtmsg_flags = RTF_UP; - if (prefix_len == 128) + } + memcpy(&rt.rtmsg_dst, sa6.sin6_addr.s6_addr, sizeof(struct in6_addr)); + + /* Fill in the other fields. */ + rt.rtmsg_flags = RTF_UP; + if (prefix_len == 128) rt.rtmsg_flags |= RTF_HOST; - rt.rtmsg_metric = 1; - rt.rtmsg_dst_len = prefix_len; - - while (*args) { + rt.rtmsg_metric = 1; + rt.rtmsg_dst_len = prefix_len; + + while (*args) { if (!strcmp(*args, "metric")) { - args++; - if (!*args || !isdigit(**args)) - return(usage()); - metric = atoi(*args); - rt.rtmsg_metric = metric; - args++; - continue; + args++; + if (!*args || !isdigit(**args)) + return (usage()); + metric = atoi(*args); + rt.rtmsg_metric = metric; + args++; + continue; } - if (!strcmp(*args,"gw") || !strcmp(*args,"gateway")) { - args++; - if (!*args) - return(usage()); - if (rt.rtmsg_flags & RTF_GATEWAY) - return(usage()); - strcpy(gateway, *args); - if (inet6_aftype.input(1, gateway, - (struct sockaddr *)&sa6) < 0) { - inet6_aftype.herror(gateway); - return (E_LOOKUP); - } - memcpy(&rt.rtmsg_gateway, sa6.sin6_addr.s6_addr, - sizeof(struct in6_addr)); - rt.rtmsg_flags |= RTF_GATEWAY; - args++; - continue; + if (!strcmp(*args, "gw") || !strcmp(*args, "gateway")) { + args++; + if (!*args) + return (usage()); + if (rt.rtmsg_flags & RTF_GATEWAY) + return (usage()); + strcpy(gateway, *args); + if (inet6_aftype.input(1, gateway, + (struct sockaddr *) &sa6) < 0) { + inet6_aftype.herror(gateway); + return (E_LOOKUP); + } + memcpy(&rt.rtmsg_gateway, sa6.sin6_addr.s6_addr, + sizeof(struct in6_addr)); + rt.rtmsg_flags |= RTF_GATEWAY; + args++; + continue; } - if (!strcmp(*args,"mod")) { - args++; - rt.rtmsg_flags |= RTF_MODIFIED; - continue; + if (!strcmp(*args, "mod")) { + args++; + rt.rtmsg_flags |= RTF_MODIFIED; + continue; } - if (!strcmp(*args,"dyn")) { - args++; - rt.rtmsg_flags |= RTF_DYNAMIC; - continue; + if (!strcmp(*args, "dyn")) { + args++; + rt.rtmsg_flags |= RTF_DYNAMIC; + continue; } - if (!strcmp(*args,"device") || !strcmp(*args,"dev")) { - args++; - if (!*args) - return(usage()); - } else - if (args[1]) - return(usage()); + if (!strcmp(*args, "device") || !strcmp(*args, "dev")) { + args++; + if (!*args) + return (usage()); + } else if (args[1]) + return (usage()); devname = *args; args++; - } - - /* Create a socket to the INET6 kernel. */ - if ((skfd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { - perror("socket"); - return(E_SOCK); - } - - if (devname) { - memset(&ifr, 0, sizeof(ifr)); - strcpy(ifr.ifr_name, devname); - - if (ioctl(skfd, SIOGIFINDEX, &ifr) < 0) { - perror("SIOGIFINDEX"); - return(E_SOCK); - } - - rt.rtmsg_ifindex = ifr.ifr_ifindex; - } - else - rt.rtmsg_ifindex = 0; - - /* Tell the kernel to accept this route. */ - if (action==RTACTION_DEL) { + } + + /* Create a socket to the INET6 kernel. */ + if ((skfd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { + perror("socket"); + return (E_SOCK); + } + if (devname) { + memset(&ifr, 0, sizeof(ifr)); + strcpy(ifr.ifr_name, devname); + + if (ioctl(skfd, SIOGIFINDEX, &ifr) < 0) { + perror("SIOGIFINDEX"); + return (E_SOCK); + } + rt.rtmsg_ifindex = ifr.ifr_ifindex; + } else + rt.rtmsg_ifindex = 0; + + /* Tell the kernel to accept this route. */ + if (action == RTACTION_DEL) { if (ioctl(skfd, SIOCDELRT, &rt) < 0) { - perror("SIOCDELRT"); - close(skfd); - return(E_SOCK); + perror("SIOCDELRT"); + close(skfd); + return (E_SOCK); } - } else { + } else { if (ioctl(skfd, SIOCADDRT, &rt) < 0) { - perror("SIOCADDRT"); - close(skfd); - return(E_SOCK); + perror("SIOCADDRT"); + close(skfd); + return (E_SOCK); } - } + } - /* Close the socket. */ - (void) close(skfd); - return(0); + /* Close the socket. */ + (void) close(skfd); + return (0); } int INET6_rinput(int action, int options, char **args) { - if (action == RTACTION_FLUSH) { - fprintf(stderr,_("Flushing `inet6' routing table not supported\n")); - return(usage()); - } - if ((*args == NULL) || (action == RTACTION_HELP)) - return(usage()); - - return(INET6_setroute(action, options, args)); + if (action == RTACTION_FLUSH) { + fprintf(stderr, _("Flushing `inet6' routing table not supported\n")); + return (usage()); + } + if ((*args == NULL) || (action == RTACTION_HELP)) + return (usage()); + + return (INET6_setroute(action, options, args)); } -#endif /* HAVE_AFINET6 */ +#endif /* HAVE_AFINET6 */ diff --git a/lib/inet_gr.c b/lib/inet_gr.c index 5de96ef..3d09348 100644 --- a/lib/inet_gr.c +++ b/lib/inet_gr.c @@ -1,7 +1,9 @@ /* - Modifications: - 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets -*/ + $Id: inet_gr.c,v 1.9 1998/11/15 20:10:48 freitag Exp $ + + Modifications: + 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets + */ #include "config.h" @@ -27,268 +29,279 @@ #include "net-features.h" #include "proc.h" -extern struct aftype inet_aftype; +extern struct aftype inet_aftype; int rprint_fib(int ext, int numeric) { - char buff[1024], iface[16], flags[16]; - char gate_addr[128], net_addr[128]; - char mask_addr[128]; - struct sockaddr snet, sgate, smask; - int num, iflags, metric, refcnt, use, mss, window, irtt; - FILE *fp=fopen(_PATH_PROCNET_ROUTE, "r"); - char *fmt; + char buff[1024], iface[16], flags[16]; + char gate_addr[128], net_addr[128]; + char mask_addr[128]; + struct sockaddr snet, sgate, smask; + int num, iflags, metric, refcnt, use, mss, window, irtt; + FILE *fp = fopen(_PATH_PROCNET_ROUTE, "r"); + char *fmt; - if (!fp) { - ESYSNOT("getroute","INET FIB"); + if (!fp) { + ESYSNOT("getroute", "INET FIB"); return 1; - } - - printf(_("Kernel IP routing table\n")); + } + printf(_("Kernel IP routing table\n")); - if (ext == 1) + if (ext == 1) printf(_("Destination Gateway Genmask " "Flags Metric Ref Use Iface\n")); - if (ext == 2) + if (ext == 2) printf(_("Destination Gateway Genmask " "Flags MSS Window irtt Iface\n")); - if (ext >= 3) + if (ext >= 3) printf(_("Destination Gateway Genmask " "Flags Metric Ref Use Iface " "MSS Window irtt\n")); - irtt=0; - window=0; - mss=0; + irtt = 0; + window = 0; + mss = 0; - fmt = proc_gen_fmt(_PATH_PROCNET_ROUTE, 0, fp, - "Iface", "%16s", - "Destination", "%128s", - "Gateway", "%128s", - "Flags", "%X", - "RefCnt", "%d", - "Use", "%d", - "Metric", "%d", - "Mask", "%128s", - "MTU", "%d", - "Window", "%d", - "IRTT", "%d", - NULL); - /* "%16s %128s %128s %X %d %d %d %128s %d %d %d\n" */ + fmt = proc_gen_fmt(_PATH_PROCNET_ROUTE, 0, fp, + "Iface", "%16s", + "Destination", "%128s", + "Gateway", "%128s", + "Flags", "%X", + "RefCnt", "%d", + "Use", "%d", + "Metric", "%d", + "Mask", "%128s", + "MTU", "%d", + "Window", "%d", + "IRTT", "%d", + NULL); + /* "%16s %128s %128s %X %d %d %d %128s %d %d %d\n" */ - if (!fmt) - return 1; + if (!fmt) + return 1; - while (fgets(buff, 1023, fp)) - { - num = sscanf(buff, fmt, - iface, net_addr, gate_addr, - &iflags, &refcnt, &use, &metric, mask_addr, - &mss,&window,&irtt); - if (num < 10 || !(iflags & RTF_UP)) continue; + while (fgets(buff, 1023, fp)) { + num = sscanf(buff, fmt, + iface, net_addr, gate_addr, + &iflags, &refcnt, &use, &metric, mask_addr, + &mss, &window, &irtt); + if (num < 10 || !(iflags & RTF_UP)) + continue; /* Fetch and resolve the target address. */ - (void)inet_aftype.input(1, net_addr, &snet); + (void) inet_aftype.input(1, net_addr, &snet); strcpy(net_addr, inet_aftype.sprint(&snet, (numeric | 0x8000))); net_addr[15] = '\0'; - + /* Fetch and resolve the gateway address. */ - (void)inet_aftype.input(1, gate_addr, &sgate); + (void) inet_aftype.input(1, gate_addr, &sgate); strcpy(gate_addr, inet_aftype.sprint(&sgate, numeric)); gate_addr[15] = '\0'; /* Fetch and resolve the genmask. */ - (void)inet_aftype.input(1, mask_addr, &smask); + (void) inet_aftype.input(1, mask_addr, &smask); strcpy(mask_addr, inet_aftype.sprint(&smask, 1)); mask_addr[15] = '\0'; /* Decode the flags. */ strcpy(flags, "U"); - if (iflags & RTF_GATEWAY) strcat(flags, "G"); + if (iflags & RTF_GATEWAY) + strcat(flags, "G"); #if HAVE_RTF_REJECT - if (iflags & RTF_REJECT) strcpy(flags,"!"); + if (iflags & RTF_REJECT) + strcpy(flags, "!"); #endif - if (iflags & RTF_HOST) strcat(flags, "H"); - if (iflags & RTF_REINSTATE) strcat(flags, "R"); - if (iflags & RTF_DYNAMIC) strcat(flags, "D"); - if (iflags & RTF_MODIFIED) strcat(flags, "M"); + if (iflags & RTF_HOST) + strcat(flags, "H"); + if (iflags & RTF_REINSTATE) + strcat(flags, "R"); + if (iflags & RTF_DYNAMIC) + strcat(flags, "D"); + if (iflags & RTF_MODIFIED) + strcat(flags, "M"); /* Print the info. */ if (ext == 1) { #if HAVE_RTF_REJECT - if (iflags & RTF_REJECT) - printf("%-15s - %-15s %-5s %-6d - %7d -\n", - net_addr, mask_addr, flags, metric, use); - else + if (iflags & RTF_REJECT) + printf("%-15s - %-15s %-5s %-6d - %7d -\n", + net_addr, mask_addr, flags, metric, use); + else #endif - printf("%-15s %-15s %-15s %-5s %-6d %-2d %7d %s\n", - net_addr, gate_addr, mask_addr, flags, - metric, refcnt, use, iface); + printf("%-15s %-15s %-15s %-5s %-6d %-2d %7d %s\n", + net_addr, gate_addr, mask_addr, flags, + metric, refcnt, use, iface); } if (ext == 2) { #if HAVE_RTF_REJECT - if (iflags & RTF_REJECT) - printf("%-15s - %-15s %-5s - - - -\n", - net_addr, mask_addr, flags); - else + if (iflags & RTF_REJECT) + printf("%-15s - %-15s %-5s - - - -\n", + net_addr, mask_addr, flags); + else #endif - printf("%-15s %-15s %-15s %-5s %5d %-5d %6d %s\n", - net_addr, gate_addr, mask_addr, flags, - mss, window, irtt, iface); + printf("%-15s %-15s %-15s %-5s %5d %-5d %6d %s\n", + net_addr, gate_addr, mask_addr, flags, + mss, window, irtt, iface); } if (ext >= 3) { #if HAVE_RTF_REJECT - if (iflags & RTF_REJECT) - printf("%-15s - %-15s %-5s %-6d - %7d - - - -\n", - net_addr, mask_addr, flags, metric, use); - else + if (iflags & RTF_REJECT) + printf("%-15s - %-15s %-5s %-6d - %7d - - - -\n", + net_addr, mask_addr, flags, metric, use); + else #endif - printf("%-15s %-15s %-15s %-5s %-6d %-3d %6d %-6.6s %-5d %-6d %d\n", - net_addr, gate_addr, mask_addr, flags, - metric, refcnt, use, iface, mss, window, irtt); + printf("%-15s %-15s %-15s %-5s %-6d %-3d %6d %-6.6s %-5d %-6d %d\n", + net_addr, gate_addr, mask_addr, flags, + metric, refcnt, use, iface, mss, window, irtt); } - } + } - free(fmt); - (void) fclose(fp); - return(0); + free(fmt); + (void) fclose(fp); + return (0); } int rprint_cache(int ext, int numeric) { - char buff[1024], iface[16], flags[16]; - char gate_addr[128], net_addr[128]; - char mask_addr[128]; - struct sockaddr snet, sgate, smask; - int num, iflags, metric, refcnt, use, mss, window, irtt, hh, arp; - char *fmt; + char buff[1024], iface[16], flags[16]; + char gate_addr[128], net_addr[128]; + char mask_addr[128]; + struct sockaddr snet, sgate, smask; + int num, iflags, metric, refcnt, use, mss, window, irtt, hh, arp; + char *fmt; - FILE *fp=fopen(_PATH_PROCNET_RTCACHE, "r"); + FILE *fp = fopen(_PATH_PROCNET_RTCACHE, "r"); - if (!fp) { - ESYSNOT("getroute","INET CACHE"); + if (!fp) { + ESYSNOT("getroute", "INET CACHE"); return 1; - } - - if (ext == 1) + } + if (ext == 1) printf(_("Destination Gateway Source " "Flags Metric Ref Use Iface\n")); - if (ext == 2) + if (ext == 2) printf(_("Destination Gateway Source " "Flags MSS Window irtt Iface\n")); - if (ext >= 3) + if (ext >= 3) printf(_("Destination Gateway Source " "Flags Metric Ref Use Iface " "MSS Window irtt HH Arp\n")); - fmt = proc_gen_fmt(_PATH_PROCNET_ROUTE, 0, fp, - "Iface", "%16s", - "Destination", "%128s", - "Gateway", "%128s", - "Flags", "%X", - "RefCnt", "%d", - "Use", "%d", - "Metric", "%d", - "Mask", "%128s", - "MTU", "%d", - "Window", "%d", - "IRTT", "%d", - NULL); - /* "%16s %128s %128s %X %d %d %d %128s %d %d %d %d %d\n" */ + fmt = proc_gen_fmt(_PATH_PROCNET_ROUTE, 0, fp, + "Iface", "%16s", + "Destination", "%128s", + "Gateway", "%128s", + "Flags", "%X", + "RefCnt", "%d", + "Use", "%d", + "Metric", "%d", + "Mask", "%128s", + "MTU", "%d", + "Window", "%d", + "IRTT", "%d", + NULL); + /* "%16s %128s %128s %X %d %d %d %128s %d %d %d %d %d\n" */ - irtt=0; - window=0; - mss=0; - hh=0; - arp=0; - while (fgets(buff, 1023, fp)) - { + irtt = 0; + window = 0; + mss = 0; + hh = 0; + arp = 0; + while (fgets(buff, 1023, fp)) { num = sscanf(buff, fmt, - iface, net_addr, gate_addr, - &iflags, &refcnt, &use, &metric, mask_addr, - &mss,&window,&irtt,&hh,&arp); - if (num < 12) continue; + iface, net_addr, gate_addr, + &iflags, &refcnt, &use, &metric, mask_addr, + &mss, &window, &irtt, &hh, &arp); + if (num < 12) + continue; /* Fetch and resolve the target address. */ - (void)inet_aftype.input(1, net_addr, &snet); + (void) inet_aftype.input(1, net_addr, &snet); strcpy(net_addr, inet_aftype.sprint(&snet, (numeric | 0x8000))); net_addr[15] = '\0'; /* Fetch and resolve the gateway address. */ - (void)inet_aftype.input(1, gate_addr, &sgate); + (void) inet_aftype.input(1, gate_addr, &sgate); strcpy(gate_addr, inet_aftype.sprint(&sgate, numeric)); gate_addr[15] = '\0'; /* Fetch and resolve the genmask. */ - (void)inet_aftype.input(1, mask_addr, &smask); + (void) inet_aftype.input(1, mask_addr, &smask); strcpy(mask_addr, inet_aftype.sprint(&smask, 1)); mask_addr[15] = '\0'; /* Decode the flags. */ flags[0] = '\0'; - if (iflags & RTF_UP) strcat(flags, "U"); - if (iflags & RTF_GATEWAY) strcat(flags, "G"); + if (iflags & RTF_UP) + strcat(flags, "U"); + if (iflags & RTF_GATEWAY) + strcat(flags, "G"); #if HAVE_RTF_REJECT - if (iflags & RTF_REJECT) strcpy(flags,"!"); + if (iflags & RTF_REJECT) + strcpy(flags, "!"); #endif - if (iflags & RTF_HOST) strcat(flags, "H"); - if (iflags & RTF_REINSTATE) strcat(flags, "R"); - if (iflags & RTF_DYNAMIC) strcat(flags, "D"); - if (iflags & RTF_MODIFIED) strcat(flags, "M"); + if (iflags & RTF_HOST) + strcat(flags, "H"); + if (iflags & RTF_REINSTATE) + strcat(flags, "R"); + if (iflags & RTF_DYNAMIC) + strcat(flags, "D"); + if (iflags & RTF_MODIFIED) + strcat(flags, "M"); /* Print the info. */ if (ext == 1) { #if HAVE_RTF_REJECT - if (iflags & RTF_REJECT) - printf("%-15s - %-15s %-5s %-6d - %7d -\n", - net_addr, mask_addr, flags, metric, use); - else + if (iflags & RTF_REJECT) + printf("%-15s - %-15s %-5s %-6d - %7d -\n", + net_addr, mask_addr, flags, metric, use); + else #endif - printf("%-15s %-15s %-15s %-5s %-6d %-2d %7d %s\n", - net_addr, gate_addr, mask_addr, flags, - metric, refcnt, use, iface); + printf("%-15s %-15s %-15s %-5s %-6d %-2d %7d %s\n", + net_addr, gate_addr, mask_addr, flags, + metric, refcnt, use, iface); } if (ext == 2) { #if HAVE_RTF_REJECT - if (iflags & RTF_REJECT) - printf("%-15s - %-15s %-5s - - - -\n", - net_addr, mask_addr, flags); - else + if (iflags & RTF_REJECT) + printf("%-15s - %-15s %-5s - - - -\n", + net_addr, mask_addr, flags); + else #endif - printf("%-15s %-15s %-15s %-5s %5d %-5d %6d %s\n", - net_addr, gate_addr, mask_addr, flags, - mss, window, irtt, iface); + printf("%-15s %-15s %-15s %-5s %5d %-5d %6d %s\n", + net_addr, gate_addr, mask_addr, flags, + mss, window, irtt, iface); } if (ext >= 3) { #if HAVE_RTF_REJECT - if (iflags & RTF_REJECT) - printf("%-15s - %-15s %-5s %-6d - %7d - - - -\n", - net_addr, mask_addr, flags, metric, use); - else + if (iflags & RTF_REJECT) + printf("%-15s - %-15s %-5s %-6d - %7d - - - -\n", + net_addr, mask_addr, flags, metric, use); + else #endif - printf("%-15s %-15s %-15s %-5s %-6d %-3d %6d %-6.6s %-5d %-6d %-6d %-3d %d\n", - net_addr, gate_addr, mask_addr, flags, - metric, refcnt, use, iface, mss, window, irtt, hh, arp); + printf("%-15s %-15s %-15s %-5s %-6d %-3d %6d %-6.6s %-5d %-6d %-6d %-3d %d\n", + net_addr, gate_addr, mask_addr, flags, + metric, refcnt, use, iface, mss, window, irtt, hh, arp); } - } + } - free(fmt); - (void) fclose(fp); - return(0); + free(fmt); + (void) fclose(fp); + return (0); } int INET_rprint(int options) { - int ext = options & FLAG_EXT; - int numeric = options & (FLAG_NUM|FLAG_SYM); - int rc = E_INTERN; - - if (options & FLAG_FIB) - if ((rc = rprint_fib(ext,numeric))) - return(rc); - if (options & FLAG_CACHE) - rc = rprint_cache(ext,numeric); - - return(rc); + int ext = options & FLAG_EXT; + int numeric = options & (FLAG_NUM | FLAG_SYM); + int rc = E_INTERN; + + if (options & FLAG_FIB) + if ((rc = rprint_fib(ext, numeric))) + return (rc); + if (options & FLAG_CACHE) + rc = rprint_cache(ext, numeric); + + return (rc); } -#endif /* HAVE_AFINET */ +#endif /* HAVE_AFINET */ diff --git a/lib/inet_sr.c b/lib/inet_sr.c index 51516ae..6636e3a 100644 --- a/lib/inet_sr.c +++ b/lib/inet_sr.c @@ -1,7 +1,7 @@ /* - Modifications: - 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets -*/ + Modifications: + 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets + */ #include "config.h" @@ -37,294 +37,286 @@ #define full_mask(x) (((struct sockaddr_in *)&(x))->sin_addr.s_addr) #endif -extern struct aftype inet_aftype; +extern struct aftype inet_aftype; static int skfd = -1; static int usage(void) { - fprintf(stderr,_("Usage: inet_route [-vF] del {-host|-net} Target[/prefix] [gw Gw] [metric M] [[dev] If]\n")); - fprintf(stderr,_(" inet_route [-vF] add {-host|-net} Target[/prefix] [gw Gw] [metric M]\n")); - fprintf(stderr,_(" [netmask N] [mss Mss] [window W] [irtt I]\n")); - fprintf(stderr,_(" [mod] [dyn] [reinstate] [[dev] If]\n")); - fprintf(stderr,_(" inet_route [-vF] add {-host|-net} Target[/prefix] [metric M] reject\n")); - fprintf(stderr,_(" inet_route [-FC] flush NOT supported\n")); - return(E_USAGE); + fprintf(stderr, _("Usage: inet_route [-vF] del {-host|-net} Target[/prefix] [gw Gw] [metric M] [[dev] If]\n")); + fprintf(stderr, _(" inet_route [-vF] add {-host|-net} Target[/prefix] [gw Gw] [metric M]\n")); + fprintf(stderr, _(" [netmask N] [mss Mss] [window W] [irtt I]\n")); + fprintf(stderr, _(" [mod] [dyn] [reinstate] [[dev] If]\n")); + fprintf(stderr, _(" inet_route [-vF] add {-host|-net} Target[/prefix] [metric M] reject\n")); + fprintf(stderr, _(" inet_route [-FC] flush NOT supported\n")); + return (E_USAGE); } static int INET_setroute(int action, int options, char **args) { - struct rtentry rt; - char target[128], gateway[128] = "NONE", netmask[128] = "default"; - int xflag, isnet; + struct rtentry rt; + char target[128], gateway[128] = "NONE", netmask[128] = "default"; + int xflag, isnet; - xflag = 0; + xflag = 0; - if (!strcmp(*args, "#net")) { + if (!strcmp(*args, "#net")) { xflag = 1; args++; - } else if (!strcmp(*args, "#host")) { + } else if (!strcmp(*args, "#host")) { xflag = 2; args++; - } - - if (*args == NULL) - return(usage()); + } + if (*args == NULL) + return (usage()); - target[(sizeof target)-1] = 0; - strncpy(target, *args++, (sizeof target)-1); + target[(sizeof target) - 1] = 0; + strncpy(target, *args++, (sizeof target) - 1); - /* Clean out the RTREQ structure. */ - memset((char *) &rt, 0, sizeof(struct rtentry)); + /* Clean out the RTREQ structure. */ + memset((char *) &rt, 0, sizeof(struct rtentry)); - /* Special hack for /prefix syntax */ - { - union { - struct sockaddr_in m; - struct sockaddr d; - } mask; - int n; + /* Special hack for /prefix syntax */ + { + union { + struct sockaddr_in m; + struct sockaddr d; + } mask; + int n; - n = inet_aftype.getmask(target, &mask.d, netmask); - if (n < 0) - return usage(); - else if (n) - rt.rt_genmask = full_mask(mask.d); - } - - if ((isnet = inet_aftype.input(0, target, &rt.rt_dst)) < 0) { + n = inet_aftype.getmask(target, &mask.d, netmask); + if (n < 0) + return usage(); + else if (n) + rt.rt_genmask = full_mask(mask.d); + } + + if ((isnet = inet_aftype.input(0, target, &rt.rt_dst)) < 0) { inet_aftype.herror(target); return (1); - } - switch (xflag) { - case 1: - isnet = 1; - break; + } + switch (xflag) { + case 1: + isnet = 1; + break; - case 2: - isnet = 0; - break; + case 2: + isnet = 0; + break; - default: - break; - } + default: + break; + } - /* Fill in the other fields. */ - rt.rt_flags = (RTF_UP | RTF_HOST); - if (isnet) + /* Fill in the other fields. */ + rt.rt_flags = (RTF_UP | RTF_HOST); + if (isnet) rt.rt_flags &= ~RTF_HOST; - while (*args) { + while (*args) { if (!strcmp(*args, "metric")) { - int metric; + int metric; - args++; - if (!*args || !isdigit(**args)) - return(usage()); - metric = atoi(*args); + args++; + if (!*args || !isdigit(**args)) + return (usage()); + metric = atoi(*args); #if HAVE_NEW_ADDRT - rt.rt_metric = metric + 1; + rt.rt_metric = metric + 1; #else - ENOSUPP("inet_setroute","NEW_ADDRT (metric)"); + ENOSUPP("inet_setroute", "NEW_ADDRT (metric)"); #endif - args++; - continue; + args++; + continue; } if (!strcmp(*args, "netmask")) { - struct sockaddr mask; + struct sockaddr mask; - args++; - if (!*args || mask_in_addr(rt)) - return(usage()); - netmask[(sizeof netmask)-1] = 0; - strncpy(netmask, *args, (sizeof netmask)-1); - if ((isnet = inet_aftype.input(0, netmask, &mask)) < 0) { - inet_aftype.herror(netmask); - return (E_LOOKUP); - } - rt.rt_genmask = full_mask(mask); - args++; - continue; + args++; + if (!*args || mask_in_addr(rt)) + return (usage()); + netmask[(sizeof netmask) - 1] = 0; + strncpy(netmask, *args, (sizeof netmask) - 1); + if ((isnet = inet_aftype.input(0, netmask, &mask)) < 0) { + inet_aftype.herror(netmask); + return (E_LOOKUP); + } + rt.rt_genmask = full_mask(mask); + args++; + continue; } - if (!strcmp(*args,"gw") || !strcmp(*args,"gateway")) { - args++; - if (!*args) - return(usage()); - if (rt.rt_flags & RTF_GATEWAY) - return(usage()); - gateway[(sizeof gateway)-1] = 0; - strncpy(gateway, *args, (sizeof gateway)-1); - if ((isnet = inet_aftype.input(0, gateway, &rt.rt_gateway)) < 0) { - inet_aftype.herror(gateway); - return (E_LOOKUP); - } - if (isnet) { - fprintf(stderr, _("route: %s: cannot use a NETWORK as gateway!\n"), - gateway); - return (E_OPTERR); - } - rt.rt_flags |= RTF_GATEWAY; - args++; - continue; + if (!strcmp(*args, "gw") || !strcmp(*args, "gateway")) { + args++; + if (!*args) + return (usage()); + if (rt.rt_flags & RTF_GATEWAY) + return (usage()); + gateway[(sizeof gateway) - 1] = 0; + strncpy(gateway, *args, (sizeof gateway) - 1); + if ((isnet = inet_aftype.input(0, gateway, &rt.rt_gateway)) < 0) { + inet_aftype.herror(gateway); + return (E_LOOKUP); + } + if (isnet) { + fprintf(stderr, _("route: %s: cannot use a NETWORK as gateway!\n"), + gateway); + return (E_OPTERR); + } + rt.rt_flags |= RTF_GATEWAY; + args++; + continue; } - if (!strcmp(*args,"mss")) { - args++; - rt.rt_flags |= RTF_MSS; - if(!*args) - return(usage()); - rt.rt_mss = atoi(*args); - args++; - if(rt.rt_mss<64||rt.rt_mss>32768) - { - fprintf(stderr, _("route: Invalid MSS.\n")); - return(E_OPTERR); - } - continue; + if (!strcmp(*args, "mss")) { + args++; + rt.rt_flags |= RTF_MSS; + if (!*args) + return (usage()); + rt.rt_mss = atoi(*args); + args++; + if (rt.rt_mss < 64 || rt.rt_mss > 32768) { + fprintf(stderr, _("route: Invalid MSS.\n")); + return (E_OPTERR); + } + continue; } - if (!strcmp(*args,"window")) { - args++; - if(!*args) - return(usage()); - rt.rt_flags |= RTF_WINDOW; - rt.rt_window = atoi(*args); - args++; - if(rt.rt_window<128) - { - fprintf(stderr, _("route: Invalid window.\n")); - return(E_OPTERR); - } - continue; + if (!strcmp(*args, "window")) { + args++; + if (!*args) + return (usage()); + rt.rt_flags |= RTF_WINDOW; + rt.rt_window = atoi(*args); + args++; + if (rt.rt_window < 128) { + fprintf(stderr, _("route: Invalid window.\n")); + return (E_OPTERR); + } + continue; } - if (!strcmp(*args,"irtt")) { - args++; - if(!*args) - return(usage()); - args++; + if (!strcmp(*args, "irtt")) { + args++; + if (!*args) + return (usage()); + args++; #if HAVE_RTF_IRTT - rt.rt_flags |= RTF_IRTT; - rt.rt_irtt = atoi(*(args-1)); - rt.rt_irtt*=(HZ/100); /* FIXME */ -#if 0 /* FIXME: do we need to check anything of this? */ - if(rt.rt_irtt<1||rt.rt_irtt> (120*HZ)) - { - fprintf(stderr, _("route: Invalid initial rtt.\n")); - return(E_OPTERR); - } + rt.rt_flags |= RTF_IRTT; + rt.rt_irtt = atoi(*(args - 1)); + rt.rt_irtt *= (HZ / 100); /* FIXME */ +#if 0 /* FIXME: do we need to check anything of this? */ + if (rt.rt_irtt < 1 || rt.rt_irtt > (120 * HZ)) { + fprintf(stderr, _("route: Invalid initial rtt.\n")); + return (E_OPTERR); + } #endif #else - ENOSUPP("inet_setroute","RTF_IRTT"); + ENOSUPP("inet_setroute", "RTF_IRTT"); #endif - continue; + continue; } - if (!strcmp(*args,"reject")) { - args++; + if (!strcmp(*args, "reject")) { + args++; #if HAVE_RTF_REJECT - rt.rt_flags |= RTF_REJECT; + rt.rt_flags |= RTF_REJECT; #else - ENOSUPP("inet_setroute","RTF_REJECT"); + ENOSUPP("inet_setroute", "RTF_REJECT"); #endif - continue; + continue; } - if (!strcmp(*args,"mod")) { - args++; - rt.rt_flags |= RTF_MODIFIED; - continue; + if (!strcmp(*args, "mod")) { + args++; + rt.rt_flags |= RTF_MODIFIED; + continue; } - if (!strcmp(*args,"dyn")) { - args++; - rt.rt_flags |= RTF_DYNAMIC; - continue; + if (!strcmp(*args, "dyn")) { + args++; + rt.rt_flags |= RTF_DYNAMIC; + continue; } - if (!strcmp(*args,"reinstate")) { - args++; - rt.rt_flags |= RTF_REINSTATE; - continue; + if (!strcmp(*args, "reinstate")) { + args++; + rt.rt_flags |= RTF_REINSTATE; + continue; } - - if (!strcmp(*args,"device") || !strcmp(*args,"dev")) { - args++; - if (rt.rt_dev || *args == NULL) - return usage(); - rt.rt_dev = *args++; - continue; + if (!strcmp(*args, "device") || !strcmp(*args, "dev")) { + args++; + if (rt.rt_dev || *args == NULL) + return usage(); + rt.rt_dev = *args++; + continue; } - - /* nothing matches */ - if (!rt.rt_dev) { - rt.rt_dev = *args++; - if (*args) - return usage(); /* must be last to catch typos */ + /* nothing matches */ + if (!rt.rt_dev) { + rt.rt_dev = *args++; + if (*args) + return usage(); /* must be last to catch typos */ } else - return usage(); - } + return usage(); + } #if HAVE_RTF_REJECT - if ((rt.rt_flags & RTF_REJECT) && !rt.rt_dev) - rt.rt_dev="lo"; + if ((rt.rt_flags & RTF_REJECT) && !rt.rt_dev) + rt.rt_dev = "lo"; #endif - - /* sanity checks.. */ - if (mask_in_addr(rt)) { + + /* sanity checks.. */ + if (mask_in_addr(rt)) { __u32 mask = ~ntohl(mask_in_addr(rt)); if ((rt.rt_flags & RTF_HOST) && mask != 0xffffffff) { - fprintf(stderr, _("route: netmask %.8x doesn't make sense with host route\n"), mask); - return(E_OPTERR); + fprintf(stderr, _("route: netmask %.8x doesn't make sense with host route\n"), mask); + return (E_OPTERR); } - if (mask & (mask+1)) { - fprintf(stderr, _("route: bogus netmask %s\n"), netmask); - return(E_OPTERR); + if (mask & (mask + 1)) { + fprintf(stderr, _("route: bogus netmask %s\n"), netmask); + return (E_OPTERR); } mask = ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr; if (mask & ~mask_in_addr(rt)) { - fprintf(stderr, _("route: netmask doesn't match route address\n")); - return(E_OPTERR); + fprintf(stderr, _("route: netmask doesn't match route address\n")); + return (E_OPTERR); } - } - - /* Fill out netmask if still unset */ - if ((action==RTACTION_ADD) && rt.rt_flags & RTF_HOST) + } + /* Fill out netmask if still unset */ + if ((action == RTACTION_ADD) && rt.rt_flags & RTF_HOST) mask_in_addr(rt) = 0xffffffff; - /* Create a socket to the INET kernel. */ - if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + /* Create a socket to the INET kernel. */ + if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("socket"); - return(E_SOCK); - } - - /* Tell the kernel to accept this route. */ - if (action==RTACTION_DEL) { + return (E_SOCK); + } + /* Tell the kernel to accept this route. */ + if (action == RTACTION_DEL) { if (ioctl(skfd, SIOCDELRT, &rt) < 0) { - perror("SIOCDELRT"); - close(skfd); - return(E_SOCK); + perror("SIOCDELRT"); + close(skfd); + return (E_SOCK); } - } else { + } else { if (ioctl(skfd, SIOCADDRT, &rt) < 0) { - perror("SIOCADDRT"); - close(skfd); - return(E_SOCK); + perror("SIOCADDRT"); + close(skfd); + return (E_SOCK); } - } + } - /* Close the socket. */ - (void) close(skfd); - return(0); + /* Close the socket. */ + (void) close(skfd); + return (0); } int INET_rinput(int action, int options, char **args) { - if (action == RTACTION_FLUSH) { - fprintf(stderr,_("Flushing `inet' routing table not supported\n")); - return(usage()); - } - if (options & FLAG_CACHE) { - fprintf(stderr,_("Modifying `inet' routing cache not supported\n")); - return(usage()); - } - if ((*args == NULL) || (action == RTACTION_HELP)) - return(usage()); - - return(INET_setroute(action, options, args)); + if (action == RTACTION_FLUSH) { + fprintf(stderr, _("Flushing `inet' routing table not supported\n")); + return (usage()); + } + if (options & FLAG_CACHE) { + fprintf(stderr, _("Modifying `inet' routing cache not supported\n")); + return (usage()); + } + if ((*args == NULL) || (action == RTACTION_HELP)) + return (usage()); + + return (INET_setroute(action, options, args)); } -#endif /* HAVE_AFINET */ +#endif /* HAVE_AFINET */ @@ -1,14 +1,14 @@ /* - * IPX protocol output functions. - * [Not yet input] + * IPX protocol output functions. + * [Not yet input] * - * Alan Cox <Alan.Cox@linux.org> + * Alan Cox <Alan.Cox@linux.org> * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. * Modifications: * 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets, * snprintf instead of sprintf @@ -41,142 +41,139 @@ #endif /* Display a ipx domain address. */ -static char * -IPX_print(unsigned char *ptr) +static char *IPX_print(unsigned char *ptr) { - static char buff[64]; - struct sockaddr_ipx *sipx=(struct sockaddr_ipx *)(ptr-2); - int t; - - - for(t=IPX_NODE_LEN;t;t--) - if (sipx->sipx_node[t-1]) - break; - - if (t && ntohl(sipx->sipx_network)) - snprintf(buff,sizeof(buff),"%08lX:%02X%02X%02X%02X%02X%02X", - (long int)ntohl(sipx->sipx_network), - (int)sipx->sipx_node[0],(int)sipx->sipx_node[1], - (int)sipx->sipx_node[2],(int)sipx->sipx_node[3], - (int)sipx->sipx_node[4],(int)sipx->sipx_node[5]); - else if (!t && ntohl(sipx->sipx_network)) - snprintf(buff,sizeof(buff),"%08lX", (long int)ntohl(sipx->sipx_network)); - else if (t && !ntohl(sipx->sipx_network)) - snprintf(buff,sizeof(buff),"%02X%02X%02X%02X%02X%02X", - (int)sipx->sipx_node[0],(int)sipx->sipx_node[1], - (int)sipx->sipx_node[2],(int)sipx->sipx_node[3], - (int)sipx->sipx_node[4],(int)sipx->sipx_node[5]); - else - buff[0] = '\0'; - return(buff); + static char buff[64]; + struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) (ptr - 2); + int t; + + + for (t = IPX_NODE_LEN; t; t--) + if (sipx->sipx_node[t - 1]) + break; + + if (t && ntohl(sipx->sipx_network)) + snprintf(buff, sizeof(buff), "%08lX:%02X%02X%02X%02X%02X%02X", + (long int) ntohl(sipx->sipx_network), + (int) sipx->sipx_node[0], (int) sipx->sipx_node[1], + (int) sipx->sipx_node[2], (int) sipx->sipx_node[3], + (int) sipx->sipx_node[4], (int) sipx->sipx_node[5]); + else if (!t && ntohl(sipx->sipx_network)) + snprintf(buff, sizeof(buff), "%08lX", (long int) ntohl(sipx->sipx_network)); + else if (t && !ntohl(sipx->sipx_network)) + snprintf(buff, sizeof(buff), "%02X%02X%02X%02X%02X%02X", + (int) sipx->sipx_node[0], (int) sipx->sipx_node[1], + (int) sipx->sipx_node[2], (int) sipx->sipx_node[3], + (int) sipx->sipx_node[4], (int) sipx->sipx_node[5]); + else + buff[0] = '\0'; + return (buff); } /* Display a ipx domain address. */ -static char * -IPX_sprint(struct sockaddr *sap, int numeric) +static char *IPX_sprint(struct sockaddr *sap, int numeric) { - static char buf[64]; + static char buf[64]; - if (sap->sa_family != AF_IPX) - return strncpy (buf, _("[NONE SET]"), sizeof (buf)); - return(IPX_print(sap->sa_data)); + if (sap->sa_family != AF_IPX) + return strncpy(buf, _("[NONE SET]"), sizeof(buf)); + return (IPX_print(sap->sa_data)); } -static int -IPX_getsock(char *bufp, struct sockaddr *sap) +static int IPX_getsock(char *bufp, struct sockaddr *sap) { - char *sp = bufp,*bp; - unsigned int i; - unsigned char val; - struct sockaddr_ipx *sipx=(struct sockaddr_ipx *) sap; - - sipx->sipx_port = 0; - - val = 0; - bp=(char *)sipx->sipx_node; - for (i = 0; i < sizeof(sipx->sipx_node); i++) { + char *sp = bufp, *bp; + unsigned int i; + unsigned char val; + struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) sap; + + sipx->sipx_port = 0; + + val = 0; + bp = (char *) sipx->sipx_node; + for (i = 0; i < sizeof(sipx->sipx_node); i++) { *sp = toupper(*sp); - - if ((*sp >= 'A') && (*sp <= 'F')) - bp[i] |= (int) (*sp - 'A') + 10; + + if ((*sp >= 'A') && (*sp <= 'F')) + bp[i] |= (int) (*sp - 'A') + 10; else if ((*sp >= '0') && (*sp <= '9')) - bp[i] |= (int) (*sp - '0'); + bp[i] |= (int) (*sp - '0'); else - return(-1); + return (-1); bp[i] <<= 4; sp++; *sp = toupper(*sp); - - if ((*sp >= 'A') && (*sp <= 'F')) - bp[i] |= (int) (*sp - 'A') + 10; + + if ((*sp >= 'A') && (*sp <= 'F')) + bp[i] |= (int) (*sp - 'A') + 10; else if ((*sp >= '0') && (*sp <= '9')) - bp[i] |= (int) (*sp - '0'); + bp[i] |= (int) (*sp - '0'); else - return(-1); - + return (-1); + sp++; } if ((memcmp(sipx->sipx_node, "\0\0\0\0\0\0\0\0", IPX_NODE_LEN) == 0) || - (memcmp(sipx->sipx_node, "\377\377\377\377\377\377", IPX_NODE_LEN) == 0)) - return(-1); - - return(0); + (memcmp(sipx->sipx_node, "\377\377\377\377\377\377", IPX_NODE_LEN) == 0)) + return (-1); + + return (0); } -/* XXX define type which makes verbose format checks AF_input*/ +/* XXX define type which makes verbose format checks AF_input */ -static int -IPX_input(int type, char *bufp, struct sockaddr *sap) +static int IPX_input(int type, char *bufp, struct sockaddr *sap) { - struct sockaddr_ipx *sai=(struct sockaddr_ipx *)sap; - unsigned long netnum; - char *ep; - int nbo; - - sai->sipx_family = AF_IPX; - sai->sipx_network = htonl(0); - sai->sipx_node[0] = sai->sipx_node[1] = sai->sipx_node[2] = - sai->sipx_node[3] = sai->sipx_node[4] = sai->sipx_node[5] = '\0'; - sai->sipx_port = 0; - - if (type & 4) - nbo = 1; - else - nbo = 0; - - type &= 3; - if (type <= 1) { - netnum = strtoul(bufp,&ep,16); + struct sockaddr_ipx *sai = (struct sockaddr_ipx *) sap; + unsigned long netnum; + char *ep; + int nbo; + + sai->sipx_family = AF_IPX; + sai->sipx_network = htonl(0); + sai->sipx_node[0] = sai->sipx_node[1] = sai->sipx_node[2] = + sai->sipx_node[3] = sai->sipx_node[4] = sai->sipx_node[5] = '\0'; + sai->sipx_port = 0; + + if (type & 4) + nbo = 1; + else + nbo = 0; + + type &= 3; + if (type <= 1) { + netnum = strtoul(bufp, &ep, 16); if ((netnum == 0xffffffffL) || (netnum == 0L)) - return(-1); + return (-1); if (nbo) - sai->sipx_network = netnum; + sai->sipx_network = netnum; else - sai->sipx_network = htonl(netnum); - } - if (type == 1) { - if (*ep != '\0') - return(-2); - return(0); - } - if (type == 0) { - if (*ep != ':') - return(-3); - bufp=ep+1; - } - return(IPX_getsock(bufp,sap)); + sai->sipx_network = htonl(netnum); + } + if (type == 1) { + if (*ep != '\0') + return (-2); + return (0); + } + if (type == 0) { + if (*ep != ':') + return (-3); + bufp = ep + 1; + } + return (IPX_getsock(bufp, sap)); } -struct aftype ipx_aftype = { - "ipx", NULL, /*"IPX",*/ AF_IPX, 0, - IPX_print, IPX_sprint, IPX_input, NULL, - NULL/*IPX_rprint*/, NULL, NULL, - -1, - "/proc/net/ipx" +struct aftype ipx_aftype = +{ + "ipx", NULL, /*"IPX", */ AF_IPX, 0, + IPX_print, IPX_sprint, IPX_input, NULL, + NULL /*IPX_rprint */ , NULL, NULL, + -1, + "/proc/net/ipx" }; #endif diff --git a/lib/ipx_gr.c b/lib/ipx_gr.c index 1bacaa2..757720a 100644 --- a/lib/ipx_gr.c +++ b/lib/ipx_gr.c @@ -1,9 +1,9 @@ /* support for ap->rresolv missing */ /* - Modifications: - 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets, - snprintf instead of sprintf -*/ + Modifications: + 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets, + snprintf instead of sprintf + */ #include "config.h" @@ -32,54 +32,52 @@ int IPX_rprint(int options) { - /* int ext = options & FLAG_EXT; */ - int numeric = options & FLAG_NUM; - char buff[1024]; - char net[128], router_net[128]; - char router_node[128]; - int num; - FILE *fp; - struct aftype *ap; - struct sockaddr sa; - - printf(_("Kernel IPX routing table\n")); /* xxx */ + /* int ext = options & FLAG_EXT; */ + int numeric = options & FLAG_NUM; + char buff[1024]; + char net[128], router_net[128]; + char router_node[128]; + int num; + FILE *fp; + struct aftype *ap; + struct sockaddr sa; - if ((ap = get_afntype(AF_IPX)) == NULL) { - EINTERN("lib/ipx_rt.c","AF_IPX missing"); - return(-1); - } + printf(_("Kernel IPX routing table\n")); /* xxx */ - printf(_("Destination Router Net Router Node\n")); + if ((ap = get_afntype(AF_IPX)) == NULL) { + EINTERN("lib/ipx_rt.c", "AF_IPX missing"); + return (-1); + } + printf(_("Destination Router Net Router Node\n")); - if ((fp = fopen(_PATH_PROCNET_IPX_ROUTE, "r")) == NULL) { + if ((fp = fopen(_PATH_PROCNET_IPX_ROUTE, "r")) == NULL) { perror(_PATH_PROCNET_IPX_ROUTE); - return(-1); - } + return (-1); + } + fgets(buff, 1023, fp); + + while (fgets(buff, 1023, fp)) { + num = sscanf(buff, "%s %s %s", net, router_net, router_node); + if (num < 3) + continue; - fgets(buff, 1023, fp); - - while (fgets(buff, 1023, fp)) - { - num = sscanf(buff, "%s %s %s",net,router_net,router_node); - if (num < 3) continue; - /* Fetch and resolve the Destination */ - (void)ap->input(5,net,&sa); + (void) ap->input(5, net, &sa); strcpy(net, ap->sprint(&sa, numeric)); /* Fetch and resolve the Router Net */ - (void)ap->input(5,router_net,&sa); + (void) ap->input(5, router_net, &sa); strcpy(router_net, ap->sprint(&sa, numeric)); /* Fetch and resolve the Router Node */ - (void)ap->input(2,router_node,&sa); + (void) ap->input(2, router_node, &sa); strcpy(router_node, ap->sprint(&sa, numeric)); - printf("%-25s %-25s %-25s\n",net, router_net, router_node); - } + printf("%-25s %-25s %-25s\n", net, router_net, router_node); + } - (void) fclose(fp); - return(0); + (void) fclose(fp); + return (0); } -#endif /* HAVE_AFIPX */ +#endif /* HAVE_AFIPX */ diff --git a/lib/ipx_sr.c b/lib/ipx_sr.c index 74fb591..cb3263b 100644 --- a/lib/ipx_sr.c +++ b/lib/ipx_sr.c @@ -23,23 +23,14 @@ #include "net-features.h" -extern struct aftype ipx_aftype; +extern struct aftype ipx_aftype; /* static int skfd = -1; */ -/* -static int usage(void) -{ - fprintf(stderr,"IPX usage\n"); - - return(E_USAGE); -} -*/ - int IPX_rinput(int action, int ext, char **args) { - - fprintf(stderr,_("IPX: this needs to be written\n")); - return(0); + + fprintf(stderr, _("IPX: this needs to be written\n")); + return (0); } -#endif /* HAVE_AFIPX */ +#endif /* HAVE_AFIPX */ diff --git a/lib/loopback.c b/lib/loopback.c index 8c9f4c1..a96fd81 100644 --- a/lib/loopback.c +++ b/lib/loopback.c @@ -1,19 +1,19 @@ /* - * lib/loopback.c This file contains the general hardware types. + * lib/loopback.c This file contains the general hardware types. * - * Version: @(#)loopback.c 1.10 10/07/93 + * Version: $Id: loopback.c,v 1.3 1998/11/15 20:11:06 freitag Exp $ * - * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993 MicroWalt Corporation + * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Copyright 1993 MicroWalt Corporation * * Modifications: * 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -31,40 +31,40 @@ #include "intl.h" /* Display an UNSPEC address. */ -static char * -pr_unspec(unsigned char *ptr) +static char *pr_unspec(unsigned char *ptr) { - static char buff[64]; - char *pos; - unsigned int i; + static char buff[64]; + char *pos; + unsigned int i; - pos = buff; - for(i = 0; i < sizeof(struct sockaddr); i++) { + pos = buff; + for (i = 0; i < sizeof(struct sockaddr); i++) { pos += sprintf(pos, "%02X-", (*ptr++ & 0377)); - } - buff[strlen(buff) - 1] = '\0'; - return(buff); + } + buff[strlen(buff) - 1] = '\0'; + return (buff); } /* Display an UNSPEC socket address. */ -static char * -pr_sunspec(struct sockaddr *sap) +static char *pr_sunspec(struct sockaddr *sap) { - static char buf[64]; + static char buf[64]; - if (sap->sa_family == 0xFFFF || sap->sa_family == 0) - return strncpy (buf, _("[NONE SET]"), sizeof (buf)); - return(pr_unspec(sap->sa_data)); + if (sap->sa_family == 0xFFFF || sap->sa_family == 0) + return strncpy(buf, _("[NONE SET]"), sizeof(buf)); + return (pr_unspec(sap->sa_data)); } -struct hwtype unspec_hwtype = { - "unspec", NULL, /*"UNSPEC",*/ -1, 0, - pr_unspec, pr_sunspec, NULL, NULL +struct hwtype unspec_hwtype = +{ + "unspec", NULL, /*"UNSPEC", */ -1, 0, + pr_unspec, pr_sunspec, NULL, NULL }; -struct hwtype loop_hwtype = { - "loop", NULL, /*"Local Loopback",*/ 255/*ARPHRD_LOOPBACK*/, 0, - NULL, NULL, NULL, NULL +struct hwtype loop_hwtype = +{ + "loop", NULL, /*"Local Loopback", */ 255 /*ARPHRD_LOOPBACK */ , 0, + NULL, NULL, NULL, NULL }; diff --git a/lib/masq_info.c b/lib/masq_info.c index 339ee88..dd61a3a 100644 --- a/lib/masq_info.c +++ b/lib/masq_info.c @@ -1,29 +1,29 @@ /* - * lib/masq_info.c This file contains a the functio masq_info - * to print a table of current masquerade connections. + * lib/masq_info.c This file contains a the functio masq_info + * to print a table of current masquerade connections. * - * NET-LIB A collection of functions used from the base set of the - * NET-3 Networking Distribution for the LINUX operating - * system. (net-tools, net-drivers) + * NET-LIB A collection of functions used from the base set of the + * NET-3 Networking Distribution for the LINUX operating + * system. (net-tools, net-drivers) * - * Version: lib/masq_info.c 0.02 (1996-02-18) + * Version: $Id: masq_info.c,v 1.3 1998/11/15 20:11:11 freitag Exp $ * - * Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de> - * Copyright 1999 Bernd Eckenfels, Germany + * Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de> + * Copyright 1999 Bernd Eckenfels, Germany * * Modifications: * - *960217 {0.01} Bernd Eckenfels: creatin from the code of - * Jos Vos' ipfwadm 2.0beta1 - *950218 {0.02} Bernd Eckenfels: <linux/if.h> added + *960217 {0.01} Bernd Eckenfels: creatin from the code of + * Jos Vos' ipfwadm 2.0beta1 + *950218 {0.02} Bernd Eckenfels: <linux/if.h> added * *980405 {0.03} Arnaldo Carvalho: i18n CATGETS -> gettext * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include <sys/types.h> #include <sys/socket.h> @@ -52,173 +52,165 @@ struct masq { - unsigned long expires; /* Expiration timer */ - char * proto; /* Which protocol are we talking? */ - struct sockaddr_in src, dst; /* Source and destination IP addresses */ - unsigned short sport, dport; /* Source and destination ports */ - unsigned short mport; /* Masqueraded port */ - unsigned long initseq; /* Add delta from this seq. on */ - short delta; /* Delta in sequence numbers */ - short pdelta; /* Delta in sequence numbers before last */ + unsigned long expires; /* Expiration timer */ + char *proto; /* Which protocol are we talking? */ + struct sockaddr_in src, dst; /* Source and destination IP addresses */ + unsigned short sport, dport; /* Source and destination ports */ + unsigned short mport; /* Masqueraded port */ + unsigned long initseq; /* Add delta from this seq. on */ + short delta; /* Delta in sequence numbers */ + short pdelta; /* Delta in sequence numbers before last */ }; -static struct aftype *ap; /* current address family */ +static struct aftype *ap; /* current address family */ static int has_pdelta; -static void -print_masq(struct masq *ms, int numeric, int ext) +static void print_masq(struct masq *ms, int numeric, int ext) { - unsigned long minutes, seconds, sec100s; - - printf("%-4s", ms->proto); - - sec100s = ms->expires % 100L; - seconds = (ms->expires / 100L) % 60; - minutes = ms->expires / 6000L; - - printf("%3ld:%02ld.%02ld ", minutes, seconds, sec100s); - - if (ext>1) { - if (has_pdelta) - printf("%10lu %5hd %5hd ", ms->initseq, - ms->delta, ms->pdelta); - else - printf("%10lu %5hd - ", ms->initseq, - ms->delta); - } - printf("%-20s ", ap->sprint((struct sockaddr *)&(ms->src),numeric)); - printf("%-20s ", ap->sprint((struct sockaddr *)&(ms->dst),numeric)); - - printf("%s -> ", get_sname(ms->sport, ms->proto, numeric)); - printf("%s", get_sname(ms->dport, ms->proto, numeric)); - printf(" (%s)\n", get_sname(ms->mport, ms->proto, numeric)); + unsigned long minutes, seconds, sec100s; + + printf("%-4s", ms->proto); + + sec100s = ms->expires % 100L; + seconds = (ms->expires / 100L) % 60; + minutes = ms->expires / 6000L; + + printf("%3ld:%02ld.%02ld ", minutes, seconds, sec100s); + + if (ext > 1) { + if (has_pdelta) + printf("%10lu %5hd %5hd ", ms->initseq, + ms->delta, ms->pdelta); + else + printf("%10lu %5hd - ", ms->initseq, + ms->delta); + } + printf("%-20s ", ap->sprint((struct sockaddr *) &(ms->src), numeric)); + printf("%-20s ", ap->sprint((struct sockaddr *) &(ms->dst), numeric)); + + printf("%s -> ", get_sname(ms->sport, ms->proto, numeric)); + printf("%s", get_sname(ms->dport, ms->proto, numeric)); + printf(" (%s)\n", get_sname(ms->mport, ms->proto, numeric)); } -static int -read_masqinfo(FILE *f, struct masq *mslist, int nmslist) +static int read_masqinfo(FILE * f, struct masq *mslist, int nmslist) { - int n, nread = 0; - struct masq *ms; - char buf[256]; - - for (nread = 0; nread < nmslist; nread++) { - ms = &mslist[nread]; - if (has_pdelta) { - if ((n = fscanf(f, " %s %lX:%hX %lX:%hX %hX %lX %hd %hd %lu", - buf, - (unsigned long *) &ms->src.sin_addr.s_addr, &ms->sport, - (unsigned long *) &ms->dst.sin_addr.s_addr, &ms->dport, - &ms->mport, &ms->initseq, &ms->delta, - &ms->pdelta, &ms->expires)) == -1) - return nread; - } else { - if ((n = fscanf(f, " %s %lX:%hX %lX:%hX %hX %lX %hd %lu", - buf, - (unsigned long *) &ms->src.sin_addr.s_addr, &ms->sport, - (unsigned long *) &ms->dst.sin_addr.s_addr, &ms->dport, - &ms->mport, &ms->initseq, &ms->delta, - &ms->expires)) == -1) - return nread; - } - if ((has_pdelta && (n !=10)) || (!has_pdelta && (n != 9))) { - EINTERN("masq_info.c", "ip_masquerade format error"); - return(-1); - } - - ms->src.sin_family = AF_INET; - ms->dst.sin_family = AF_INET; - - if (strcmp("TCP", buf) == 0) - ms->proto = "tcp"; - else if (strcmp("UDP", buf) == 0) - ms->proto = "udp"; - else { - EINTERN("masq_info.c", "ip_masquerade unknown type"); - return(-1); - } - - /* we always keep these addresses in network byte order */ - ms->src.sin_addr.s_addr = htonl(ms->src.sin_addr.s_addr); - ms->dst.sin_addr.s_addr = htonl(ms->dst.sin_addr.s_addr); - ms->sport = htons(ms->sport); - ms->dport = htons(ms->dport); - ms->mport = htons(ms->mport); + int n, nread = 0; + struct masq *ms; + char buf[256]; + + for (nread = 0; nread < nmslist; nread++) { + ms = &mslist[nread]; + if (has_pdelta) { + if ((n = fscanf(f, " %s %lX:%hX %lX:%hX %hX %lX %hd %hd %lu", + buf, + (unsigned long *) &ms->src.sin_addr.s_addr, &ms->sport, + (unsigned long *) &ms->dst.sin_addr.s_addr, &ms->dport, + &ms->mport, &ms->initseq, &ms->delta, + &ms->pdelta, &ms->expires)) == -1) + return nread; + } else { + if ((n = fscanf(f, " %s %lX:%hX %lX:%hX %hX %lX %hd %lu", + buf, + (unsigned long *) &ms->src.sin_addr.s_addr, &ms->sport, + (unsigned long *) &ms->dst.sin_addr.s_addr, &ms->dport, + &ms->mport, &ms->initseq, &ms->delta, + &ms->expires)) == -1) + return nread; + } + if ((has_pdelta && (n != 10)) || (!has_pdelta && (n != 9))) { + EINTERN("masq_info.c", "ip_masquerade format error"); + return (-1); } - return nread; + ms->src.sin_family = AF_INET; + ms->dst.sin_family = AF_INET; + + if (strcmp("TCP", buf) == 0) + ms->proto = "tcp"; + else if (strcmp("UDP", buf) == 0) + ms->proto = "udp"; + else { + EINTERN("masq_info.c", "ip_masquerade unknown type"); + return (-1); + } + + /* we always keep these addresses in network byte order */ + ms->src.sin_addr.s_addr = htonl(ms->src.sin_addr.s_addr); + ms->dst.sin_addr.s_addr = htonl(ms->dst.sin_addr.s_addr); + ms->sport = htons(ms->sport); + ms->dport = htons(ms->dport); + ms->mport = htons(ms->mport); + } + return nread; } int ip_masq_info(int numeric, int ext) { - FILE *f; - int i; - char buf[256]; - struct masq *mslist; - int ntotal = 0, nread; - - if(!(f=fopen(_PATH_PROCNET_IP_MASQ, "r"))) - { - if (errno != ENOENT) { - perror(_PATH_PROCNET_IP_MASQ); - return(-1); - } - ESYSNOT("netstat","ip_masquerade"); - return(1); + FILE *f; + int i; + char buf[256]; + struct masq *mslist; + int ntotal = 0, nread; + + if (!(f = fopen(_PATH_PROCNET_IP_MASQ, "r"))) { + if (errno != ENOENT) { + perror(_PATH_PROCNET_IP_MASQ); + return (-1); } - - if ((ap = get_aftype("inet")) == NULL) { - ENOSUPP("masq_info","AF INET"); - fclose(f); - return(-1); - } - - fgets(buf, sizeof(buf), f); - has_pdelta = strstr(buf,"PDelta")?1:0; - - mslist = (struct masq *) malloc(16 * sizeof(struct masq)); + ESYSNOT("netstat", "ip_masquerade"); + return (1); + } + if ((ap = get_aftype("inet")) == NULL) { + ENOSUPP("masq_info", "AF INET"); + fclose(f); + return (-1); + } + fgets(buf, sizeof(buf), f); + has_pdelta = strstr(buf, "PDelta") ? 1 : 0; + + mslist = (struct masq *) malloc(16 * sizeof(struct masq)); + if (!mslist) { + EINTERN("masq_info", "malloc() failed"); + fclose(f); + return (-1); + } + while ((nread = read_masqinfo(f, &(mslist[ntotal]), 16)) == 16) { + ntotal += nread; + mslist = (struct masq *) realloc(mslist, + (ntotal + 16) * sizeof(struct masq)); if (!mslist) { - EINTERN("masq_info","malloc() failed"); - fclose(f); - return(-1); + EINTERN("masq_info", "realloc() failed"); + fclose(f); + return (-1); } - while ((nread = read_masqinfo(f, &(mslist[ntotal]), 16)) == 16) { - ntotal += nread; - mslist = (struct masq *) realloc(mslist, - (ntotal + 16) * sizeof(struct masq)); - if (!mslist) { - EINTERN("masq_info","realloc() failed"); - fclose(f); - return(-1); - } - + } + fclose(f); + + if (nread < 0) { + if (mslist) + free(mslist); + return (-1); + } + ntotal += nread; + + if (ntotal > 0) { + printf(_("IP masquerading entries\n")); + switch (ext) { + case 1: + printf(_("prot expire source destination ports\n")); + break; + default: + printf(_("prot expire initseq delta prevd source destination ports\n")); + break; } - fclose(f); - - if (nread < 0) { - if (mslist) - free(mslist); - return(-1); - } - - ntotal += nread; + for (i = 0; i < ntotal; i++) + print_masq(&(mslist[i]), numeric, ext); + if (mslist) + free(mslist); - if (ntotal > 0) { - printf(_("IP masquerading entries\n")); - switch(ext) { - case 1: - printf(_("prot expire source destination ports\n")); - break; - default: - printf(_("prot expire initseq delta prevd source destination ports\n")); - break; - } - for (i = 0; i < ntotal; i++) - print_masq(&(mslist[i]), numeric, ext); - if (mslist) - free(mslist); - - } - return 0; + } + return 0; } #endif diff --git a/lib/net-features.h b/lib/net-features.h index b08ee76..3084e8a 100644 --- a/lib/net-features.h +++ b/lib/net-features.h @@ -1,302 +1,302 @@ /* - * lib/net-features.h This file contains the definitions of all kernel - * dependend features. + * lib/net-features.h This file contains the definitions of all kernel + * dependend features. * - * Version: features.h 0.03 (1996-03-22) + * Version: features.h 0.03 (1996-03-22) * - * Author: Bernd Eckenfels <net-tools@lina.inka.de> - * Copyright 1996 Bernd Eckenfels, Germany + * Author: Bernd Eckenfels <net-tools@lina.inka.de> + * Copyright 1996 Bernd Eckenfels, Germany * * Modifications: - *960201 {0.01} Bernd Eckenfels: creation - *960202 {0.02} Bernd Eckenfels: HW and AF added - *960322 {0.03} Bernd Eckenfels: moved into the NET-LIB + *960201 {0.01} Bernd Eckenfels: creation + *960202 {0.02} Bernd Eckenfels: HW and AF added + *960322 {0.03} Bernd Eckenfels: moved into the NET-LIB *980630 {0.04} Arnaldo Carvalho de Melo: changed NLS for I18N * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ /* - * This needs to be included AFTER the KErnel Header Files - * one of the FEATURE_ should be defined to get the Feature Variable - * definition included + * This needs to be included AFTER the KErnel Header Files + * one of the FEATURE_ should be defined to get the Feature Variable + * definition included */ - + #ifndef _NET_FEATURES_H #define _NET_FEATURES_H /* detect the present features */ -#if defined (SIOCADDRTOLD) || defined (RTF_IRTT) /* route */ -# define HAVE_NEW_ADDRT 1 +#if defined (SIOCADDRTOLD) || defined (RTF_IRTT) /* route */ +#define HAVE_NEW_ADDRT 1 #endif -#ifdef RTF_IRTT /* route */ -# define HAVE_RTF_IRTT 1 +#ifdef RTF_IRTT /* route */ +#define HAVE_RTF_IRTT 1 #endif -#ifdef RTF_REJECT /* route */ -# define HAVE_RTF_REJECT 1 +#ifdef RTF_REJECT /* route */ +#define HAVE_RTF_REJECT 1 #endif -#ifdef RTMSG_NEWROUTE /* netstat */ -# define HAVE_RT_NETLINK 1 +#ifdef RTMSG_NEWROUTE /* netstat */ +#define HAVE_RT_NETLINK 1 #endif /* compose the feature information string */ #if defined (FEATURE_ARP) || defined (FEATURE_ROUTE) || defined (FEATURE_NETSTAT) -static char *Features= +static char *Features = /* ---------------------------------------------------- */ #ifdef FEATURE_ROUTE -# if HAVE_NEW_ADDRT - "+" -# else - "-" -# endif - "NEW_ADDRT " - -# if HAVE_RTF_IRTT - "+" -# else - "-" -# endif - "RTF_IRTT " - -# if HAVE_RTF_REJECT - "+" -# else - "-" -# endif - "RTF_REJECT " - -#endif /* FEATURE_ROUTE */ +#if HAVE_NEW_ADDRT +"+" +#else +"-" +#endif +"NEW_ADDRT " + +#if HAVE_RTF_IRTT +"+" +#else +"-" +#endif +"RTF_IRTT " + +#if HAVE_RTF_REJECT +"+" +#else +"-" +#endif +"RTF_REJECT " + +#endif /* FEATURE_ROUTE */ /* ---------------------------------------------------- */ /* ---------------------------------------------------- */ #ifdef FEATURE_NETSTAT -# if HAVE_NEW_ADDRT - "+" -# else - "-" -# endif - "NEW_ADDRT " - -# if HAVE_RTF_IRTT - "+" -# else - "-" -# endif - "RTF_IRTT " - -# if HAVE_RTF_REJECT - "+" -# else - "-" -# endif - "RTF_REJECT " - -# if HAVE_RT_NETLINK - "+" -# else - "-" -# endif - "RT_NETLINK " - -# if HAVE_FW_MASQUERADE - "+" -# else - "-" -# endif - "FW_MASQUERADE " - -#endif /* FEATURE_NETSTAT */ +#if HAVE_NEW_ADDRT +"+" +#else +"-" +#endif +"NEW_ADDRT " + +#if HAVE_RTF_IRTT +"+" +#else +"-" +#endif +"RTF_IRTT " + +#if HAVE_RTF_REJECT +"+" +#else +"-" +#endif +"RTF_REJECT " + +#if HAVE_RT_NETLINK +"+" +#else +"-" +#endif +"RT_NETLINK " + +#if HAVE_FW_MASQUERADE +"+" +#else +"-" +#endif +"FW_MASQUERADE " + +#endif /* FEATURE_NETSTAT */ /* ---------------------------------------------------- */ #if I18N - "+I18N" +"+I18N" #else - "-I18N" -#endif /* I18N */ +"-I18N" +#endif /* I18N */ "\nAF: " #ifdef DFLT_AF - "("DFLT_AF")" +"(" DFLT_AF ")" #endif #if HAVE_AFUNIX - " +" +" +" #else - " -" +" -" #endif - "UNIX " +"UNIX " #if HAVE_AFINET - "+" +"+" #else - "-" +"-" #endif - "INET " +"INET " #if HAVE_AFINET6 - "+" +"+" #else - "-" +"-" #endif - "INET6 " +"INET6 " #if HAVE_AFIPX - "+" +"+" #else - "-" +"-" #endif - "IPX " +"IPX " #if HAVE_AFAX25 - "+" +"+" #else - "-" +"-" #endif - "AX25 " -#if HAVE_AFNETROM - "+" +"AX25 " +#if HAVE_AFNETROM +"+" #else - "-" +"-" #endif - "NETROM " +"NETROM " #if HAVE_AFATALK - "+" +"+" #else - "-" +"-" #endif - "ATALK " +"ATALK " #if HAVE_AFECONET - "+" +"+" #else - "-" +"-" #endif - "ECONET " +"ECONET " #if HAVE_AFROSE - "+" +"+" #else - "-" +"-" #endif - "ROSE " +"ROSE " "\nHW: " #ifdef DFLT_HW - "("DFLT_HW")" +"(" DFLT_HW ")" #endif #if HAVE_HWETHER - " +" +" +" #else - " -" +" -" #endif - "ETHER " +"ETHER " #if HAVE_HWARC - "+" +"+" #else - "-" +"-" #endif - "ARC " +"ARC " #if HAVE_HWSLIP - "+" +"+" #else - "-" +"-" #endif - "SLIP " +"SLIP " #if HAVE_HWPPP - "+" +"+" #else - "-" +"-" #endif - "PPP " +"PPP " #if HAVE_HWTUNNEL - "+" +"+" #else - "-" +"-" #endif - "TUNNEL " +"TUNNEL " #if HAVE_HWTR - "+" +"+" #else - "-" +"-" #endif - "TR " +"TR " #if HAVE_HWAX25 - "+" +"+" #else - "-" +"-" #endif - "AX25 " - +"AX25 " + #if HAVE_HWNETROM - "+" +"+" #else - "-" +"-" #endif - "NETROM " +"NETROM " #if HAVE_HWFR - "+" +"+" #else - "-" +"-" #endif - "FR " +"FR " #if HAVE_HWROSE - "+" +"+" #else - "-" +"-" #endif - "ROSE " +"ROSE " #if HAVE_HWASH - "+" +"+" #else - "-" +"-" #endif - "ASH " +"ASH " #if HAVE_HWSIT - "+" +"+" #else - "-" +"-" #endif - "SIT " +"SIT " #if HAVE_HWFDDI - "+" +"+" #else - "-" +"-" #endif - "FDDI " +"FDDI " #if HAVE_HWHIPPI - "+" +"+" #else - "-" +"-" #endif - "HIPPI " +"HIPPI " #if HAVE_HWHDLCLAPB - "+" +"+" #else - "-" +"-" #endif - "HDLC/LAPB " +"HDLC/LAPB " ; -#endif /* FEATURE_* */ +#endif /* FEATURE_* */ -#endif /* _NET_FEATURES_H */ +#endif /* _NET_FEATURES_H */ /* End of features.h */ diff --git a/lib/net-string.c b/lib/net-string.c deleted file mode 100644 index d1d662b..0000000 --- a/lib/net-string.c +++ /dev/null @@ -1,77 +0,0 @@ -/*- - * This file is part of a file of tcsh-6.05 used for the purpose of - * string handling. It is given ``as it is'' with its copyright. - * - * ----------------------------------------------------------------------- - * Copyright (c) 1980, 1991 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -char * -strsave(s) - register const char *s; -{ - char *n; - register char *p; - - if (s == NULL) - s = (const char *) ""; - for (p = (char *) s; *p++ != '\0';) - continue; - n = p = (char *) malloc((size_t) - ((((const char *) p) - s) * sizeof(char))); - while ((*p++ = *s++) != '\0') - continue; - return (n); -} - - -char *str_in_buff (char *buff, int len, char *string) -{ - if (string) - { - if (strlen (string) >= len) /* does not include \0 */ - { - strncpy (buff, string, len-1); - buff[len] = '\0'; - } - else - strcpy (buff, string); - } - else - buff[0] = '\0'; - - return (buff); -} diff --git a/lib/net-support.h b/lib/net-support.h index 435d511..ea3ffe5 100644 --- a/lib/net-support.h +++ b/lib/net-support.h @@ -1,86 +1,86 @@ /* - * lib/support.h This file contains the definitions of what is in the - * support library. Most of all, it defines structures - * for accessing support modules, and the function proto- - * types. + * lib/support.h This file contains the definitions of what is in the + * support library. Most of all, it defines structures + * for accessing support modules, and the function proto- + * types. * - * NET-LIB A collection of functions used from the base set of the - * NET-3 Networking Distribution for the LINUX operating - * system. (net-tools, net-drivers) + * NET-LIB A collection of functions used from the base set of the + * NET-3 Networking Distribution for the LINUX operating + * system. (net-tools, net-drivers) * - * Version: lib/net-support.h 1.34 (1996-04-13) + * Version: lib/net-support.h 1.34 (1996-04-13) * - * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de> + * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de> * - * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993 MicroWalt Corporation + * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Copyright 1993 MicroWalt Corporation * * Modifications: - *960125 {1.20} Bernd Eckenfels: reformated, layout - *960202 {1.30} Bernd Eckenfels: rprint in aftype - *960206 {1.31} Bernd Eckenfels: route_init - *960219 {1.32} Bernd Eckenfels: type for ap->input() - *960322 {1.33} Bernd Eckenfels: activate_ld and const in get_hwtype - *960413 {1.34} Bernd Eckenfels: new RTACTION suport + *960125 {1.20} Bernd Eckenfels: reformated, layout + *960202 {1.30} Bernd Eckenfels: rprint in aftype + *960206 {1.31} Bernd Eckenfels: route_init + *960219 {1.32} Bernd Eckenfels: type for ap->input() + *960322 {1.33} Bernd Eckenfels: activate_ld and const in get_hwtype + *960413 {1.34} Bernd Eckenfels: new RTACTION suport * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include <sys/socket.h> /* This structure defines protocol families and their handlers. */ struct aftype { - char *name; - char *title; - int af; - int alen; - char *(*print) (unsigned char *); - char *(*sprint) (struct sockaddr *, int numeric); - int (*input) (int type, char *bufp, struct sockaddr *); - void (*herror) (char *text); - int (*rprint) (int options); - int (*rinput) (int typ, int ext, char **argv); - - /* may modify src */ - int (*getmask) (char *src, struct sockaddr *mask, char *name); - - int fd; - char *flag_file; + char *name; + char *title; + int af; + int alen; + char *(*print) (unsigned char *); + char *(*sprint) (struct sockaddr *, int numeric); + int (*input) (int type, char *bufp, struct sockaddr *); + void (*herror) (char *text); + int (*rprint) (int options); + int (*rinput) (int typ, int ext, char **argv); + + /* may modify src */ + int (*getmask) (char *src, struct sockaddr * mask, char *name); + + int fd; + char *flag_file; }; extern struct aftype *aftypes[]; /* This structure defines hardware protocols and their handlers. */ struct hwtype { - char *name; - char *title; - int type; - int alen; - char *(*print) (unsigned char *); - char *(*sprint) (struct sockaddr *); - int (*input) (char *, struct sockaddr *); - int (*activate) (int fd); + char *name; + char *title; + int type; + int alen; + char *(*print) (unsigned char *); + char *(*sprint) (struct sockaddr *); + int (*input) (char *, struct sockaddr *); + int (*activate) (int fd); }; -extern struct hwtype *get_hwtype(const char *name); -extern struct hwtype *get_hwntype(int type); -extern struct aftype *get_aftype(const char *name); -extern struct aftype *get_afntype(int type); +extern struct hwtype *get_hwtype(const char *name); +extern struct hwtype *get_hwntype(int type); +extern struct aftype *get_aftype(const char *name); +extern struct aftype *get_afntype(int type); -extern int getargs(char *string, char *arguments[]); +extern int getargs(char *string, char *arguments[]); -extern int get_socket_for_af(int af); +extern int get_socket_for_af(int af); -extern void getroute_init(void); -extern void setroute_init(void); -extern void activate_init(void); -extern int route_info(const char *afname, int flags); -extern int route_edit(int action, const char *afname, int flags, char **argv); -extern int activate_ld(const char *hwname, int fd); +extern void getroute_init(void); +extern void setroute_init(void); +extern void activate_init(void); +extern int route_info(const char *afname, int flags); +extern int route_edit(int action, const char *afname, int flags, char **argv); +extern int activate_ld(const char *hwname, int fd); #define RTACTION_ADD 1 #define RTACTION_DEL 2 @@ -88,33 +88,33 @@ extern int activate_ld(const char *hwname, int fd); #define RTACTION_FLUSH 4 #define RTACTION_SHOW 5 -#define FLAG_EXT 3 /* AND-Mask */ +#define FLAG_EXT 3 /* AND-Mask */ #define FLAG_NUM 4 #define FLAG_SYM 8 #define FLAG_CACHE 16 #define FLAG_FIB 32 #define FLAG_VERBOSE 64 - -extern int ip_masq_info(int numeric, int ext); - -extern int INET_rprint(int options); -extern int INET6_rprint(int options); -extern int DDP_rprint(int options); -extern int IPX_rprint(int options); -extern int NETROM_rprint(int options); -extern int AX25_rprint(int options); - -extern int INET_rinput(int action, int flags, char **argv); -extern int INET6_rinput(int action, int flags, char **argv); -extern int DDP_rinput(int action, int flags, char **argv); -extern int IPX_rinput(int action, int flags, char **argv); -extern int NETROM_rinput(int action, int flags, char **argv); -extern int AX25_rinput(int action, int flags, char **argv); - -int aftrans_opt (const char *arg); -void aftrans_def (char *tool, char *argv0, char *dflt); - -char * get_sname(int socknumber, char *proto, int numeric); + +extern int ip_masq_info(int numeric, int ext); + +extern int INET_rprint(int options); +extern int INET6_rprint(int options); +extern int DDP_rprint(int options); +extern int IPX_rprint(int options); +extern int NETROM_rprint(int options); +extern int AX25_rprint(int options); + +extern int INET_rinput(int action, int flags, char **argv); +extern int INET6_rinput(int action, int flags, char **argv); +extern int DDP_rinput(int action, int flags, char **argv); +extern int IPX_rinput(int action, int flags, char **argv); +extern int NETROM_rinput(int action, int flags, char **argv); +extern int AX25_rinput(int action, int flags, char **argv); + +int aftrans_opt(const char *arg); +void aftrans_def(char *tool, char *argv0, char *dflt); + +char *get_sname(int socknumber, char *proto, int numeric); extern int flag_unx; extern int flag_ipx; diff --git a/lib/netrom.c b/lib/netrom.c index fce7bfe..0f8f957 100644 --- a/lib/netrom.c +++ b/lib/netrom.c @@ -1,27 +1,27 @@ /* - * lib/netrom.c This file contains an implementation of the "NET/ROM" - * support functions for the NET-2 base distribution. + * lib/netrom.c This file contains an implementation of the "NET/ROM" + * support functions for the NET-2 base distribution. * - * Version: @(#)netrom.c 1.21 07/01/98 + * Version: $Id: netrom.c,v 1.5 1998/11/15 20:11:25 freitag Exp $ * - * NOTE: I will redo this module as soon as I got the libax25.a - * library sorted out. This library contains some useful - * and often used address conversion functions, database - * lookup stuff, and more of the like. + * NOTE: I will redo this module as soon as I got the libax25.a + * library sorted out. This library contains some useful + * and often used address conversion functions, database + * lookup stuff, and more of the like. * - * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993 MicroWalt Corporation + * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Copyright 1993 MicroWalt Corporation * * Changes: * 980701 {1.21} Arnaldo Carvalho de Melo - GNU gettext instead of catgets, * strncpy instead of strcpy for - * i18n strings + * i18n strings * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -51,156 +51,158 @@ static char netrom_errmsg[128]; extern struct aftype netrom_aftype; -static char * -NETROM_print(unsigned char *ptr) +static char *NETROM_print(unsigned char *ptr) { - static char buff[8]; - int i; + static char buff[8]; + int i; - for (i = 0; i < 6; i++) { + for (i = 0; i < 6; i++) { buff[i] = ((ptr[i] & 0377) >> 1); - if (buff[i] == ' ') buff[i] = '\0'; - } - buff[6] = '\0'; - i = ((ptr[6] & 0x1E) >> 1); - if (i != 0) sprintf(&buff[strlen(buff)], "-%d", i); - return(buff); + if (buff[i] == ' ') + buff[i] = '\0'; + } + buff[6] = '\0'; + i = ((ptr[6] & 0x1E) >> 1); + if (i != 0) + sprintf(&buff[strlen(buff)], "-%d", i); + return (buff); } /* Display an AX.25 socket address. */ -static char * -NETROM_sprint(struct sockaddr *sap, int numeric) +static char *NETROM_sprint(struct sockaddr *sap, int numeric) { - char buf[64]; - if (sap->sa_family == 0xFFFF || sap->sa_family == 0) - return strncpy (buf, _("[NONE SET]"), sizeof (buf)); - return(NETROM_print(((struct sockaddr_ax25 *)sap)->sax25_call.ax25_call)); + char buf[64]; + if (sap->sa_family == 0xFFFF || sap->sa_family == 0) + return strncpy(buf, _("[NONE SET]"), sizeof(buf)); + return (NETROM_print(((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call)); } -static int -NETROM_input(int type, char *bufp, struct sockaddr *sap) +static int NETROM_input(int type, char *bufp, struct sockaddr *sap) { - unsigned char *ptr; - char *orig, c; - unsigned int i; + unsigned char *ptr; + char *orig, c; + unsigned int i; - sap->sa_family = netrom_aftype.af; - ptr = ((struct sockaddr_ax25 *)sap)->sax25_call.ax25_call; + sap->sa_family = netrom_aftype.af; + ptr = ((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call; - /* First, scan and convert the basic callsign. */ - orig = bufp; - i = 0; - while((*bufp != '\0') && (*bufp != '-') && (i < 6)) { + /* First, scan and convert the basic callsign. */ + orig = bufp; + i = 0; + while ((*bufp != '\0') && (*bufp != '-') && (i < 6)) { c = *bufp++; - if (islower(c)) c = toupper(c); - if (! (isupper(c) || isdigit(c))) { - strncpy(netrom_errmsg, _("Invalid callsign"), sizeof(netrom_errmsg)); + if (islower(c)) + c = toupper(c); + if (!(isupper(c) || isdigit(c))) { + strncpy(netrom_errmsg, _("Invalid callsign"), sizeof(netrom_errmsg)); #ifdef DEBUG - fprintf(stderr, "netrom_input(%s): %s !\n", netrom_errmsg, orig); + fprintf(stderr, "netrom_input(%s): %s !\n", netrom_errmsg, orig); #endif - errno = EINVAL; - return(-1); + errno = EINVAL; + return (-1); } *ptr++ = (unsigned char) ((c << 1) & 0xFE); i++; - } + } - /* Callsign too long? */ - if ((i == 6) && (*bufp != '-') && (*bufp != '\0')) { + /* Callsign too long? */ + if ((i == 6) && (*bufp != '-') && (*bufp != '\0')) { strncpy(netrom_errmsg, _("Callsign too long"), sizeof(netrom_errmsg)); #ifdef DEBUG fprintf(stderr, "netrom_input(%s): %s !\n", netrom_errmsg, orig); #endif errno = E2BIG; - return(-1); - } - - /* Nope, fill out the address bytes with blanks. */ - while (i++ < sizeof(ax25_address)-1) { + return (-1); + } + /* Nope, fill out the address bytes with blanks. */ + while (i++ < sizeof(ax25_address) - 1) { *ptr++ = (unsigned char) ((' ' << 1) & 0xFE); - } + } - /* See if we need to add an SSID field. */ - if (*bufp == '-') { + /* See if we need to add an SSID field. */ + if (*bufp == '-') { i = atoi(++bufp); *ptr = (unsigned char) ((i << 1) & 0xFE); - } else { + } else { *ptr = (unsigned char) '\0'; - } + } - /* All done. */ + /* All done. */ #ifdef DEBUG - fprintf(stderr, "netrom_input(%s): ", orig); - for (i = 0; i < sizeof(ax25_address); i++) + fprintf(stderr, "netrom_input(%s): ", orig); + for (i = 0; i < sizeof(ax25_address); i++) fprintf(stderr, "%02X ", sap->sa_data[i] & 0377); - fprintf(stderr, "\n"); + fprintf(stderr, "\n"); #endif - return(0); + return (0); } /* Display an error message. */ -static void -NETROM_herror(char *text) +static void NETROM_herror(char *text) { - if (text == NULL) fprintf(stderr, "%s\n", netrom_errmsg); - else fprintf(stderr, "%s: %s\n", text, netrom_errmsg); + if (text == NULL) + fprintf(stderr, "%s\n", netrom_errmsg); + else + fprintf(stderr, "%s: %s\n", text, netrom_errmsg); } -static char * -NETROM_hprint(struct sockaddr *sap) +static char *NETROM_hprint(struct sockaddr *sap) { - if (sap->sa_family == 0xFFFF || sap->sa_family == 0) return("[NONE SET]"); - return(NETROM_print(((struct sockaddr_ax25 *)sap)->sax25_call.ax25_call)); + if (sap->sa_family == 0xFFFF || sap->sa_family == 0) + return ("[NONE SET]"); + return (NETROM_print(((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call)); } -static int -NETROM_hinput(char *bufp, struct sockaddr *sap) +static int NETROM_hinput(char *bufp, struct sockaddr *sap) { - if (NETROM_input(0, bufp, sap) < 0) return(-1); - sap->sa_family = ARPHRD_NETROM; - return(0); + if (NETROM_input(0, bufp, sap) < 0) + return (-1); + sap->sa_family = ARPHRD_NETROM; + return (0); } #if 0 /* Set the line discipline of a terminal line. */ -static int -KISS_set_disc(int fd, int disc) +static int KISS_set_disc(int fd, int disc) { - if (ioctl(fd, TIOCSETD, &disc) < 0) { + if (ioctl(fd, TIOCSETD, &disc) < 0) { fprintf(stderr, "KISS_set_disc(%d): %s\n", disc, strerror(errno)); - return(-errno); - } - return(0); + return (-errno); + } + return (0); } /* Start the KISS encapsulation on the file descriptor. */ -static int -KISS_init(int fd) +static int KISS_init(int fd) { - if (KISS_set_disc(fd, N_SLIP) < 0) return(-1); - if (ioctl(fd, SIOCSIFENCAP, 4) <0) return(-1); - return(0); + if (KISS_set_disc(fd, N_SLIP) < 0) + return (-1); + if (ioctl(fd, SIOCSIFENCAP, 4) < 0) + return (-1); + return (0); } #endif -struct hwtype netrom_hwtype = { - "netrom", NULL, /* "AMPR NET/ROM", */ ARPHRD_NETROM, 7, - NETROM_print, NETROM_hprint, NETROM_hinput, NULL +struct hwtype netrom_hwtype = +{ + "netrom", NULL, /* "AMPR NET/ROM", */ ARPHRD_NETROM, 7, + NETROM_print, NETROM_hprint, NETROM_hinput, NULL }; -struct aftype netrom_aftype = { - "netrom", NULL, /* "AMPR NET/ROM", */ AF_NETROM, 7, - NETROM_print, NETROM_sprint, NETROM_input, NETROM_herror, - NULL, NULL, NULL, - -1, - "/proc/net/nr" +struct aftype netrom_aftype = +{ + "netrom", NULL, /* "AMPR NET/ROM", */ AF_NETROM, 7, + NETROM_print, NETROM_sprint, NETROM_input, NETROM_herror, + NULL, NULL, NULL, + -1, + "/proc/net/nr" }; -#endif /* HAVE_AFNETROM */ +#endif /* HAVE_AFNETROM */ diff --git a/lib/netrom_gr.c b/lib/netrom_gr.c index 9ddf448..1ff8008 100644 --- a/lib/netrom_gr.c +++ b/lib/netrom_gr.c @@ -1,22 +1,22 @@ /* - * lib/netrom_gr.c This file contains an implementation of the NET/ROM - * route support functions. + * lib/netrom_gr.c This file contains an implementation of the NET/ROM + * route support functions. * - * Version: lib/netrom_gr.c 0.02 (1998-07-01) + * Version: $Id: netrom_gr.c,v 1.3 1998/11/15 20:11:29 freitag Exp $ * - * Author: Bernd Eckenfels, <ecki@lina.inka.de> - * Copyright 1999 Bernd Eckenfels, Germany - * base on Code from Jonathan Naylor <jsn@Cs.Nott.AC.UK> + * Author: Bernd Eckenfels, <ecki@lina.inka.de> + * Copyright 1999 Bernd Eckenfels, Germany + * base on Code from Jonathan Naylor <jsn@Cs.Nott.AC.UK> * * Changes: * 980701 {0.02} Arnaldo Carvalho de Melo GNU gettext instead of catgets * * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -32,47 +32,43 @@ int NETROM_rprint(int options) { - FILE *f1=fopen(_PATH_PROCNET_NR_NODES, "r"); - FILE *f2=fopen(_PATH_PROCNET_NR_NEIGH, "r"); - char buffer[256]; - int qual,n,w; - /*int ext = options & FLAG_EXT; - int numeric = options & FLAG_NUM;*/ + FILE *f1 = fopen(_PATH_PROCNET_NR_NODES, "r"); + FILE *f2 = fopen(_PATH_PROCNET_NR_NEIGH, "r"); + char buffer[256]; + int qual, n, w; + /*int ext = options & FLAG_EXT; + int numeric = options & FLAG_NUM; */ - if(f1==NULL||f2==NULL) - { - printf(_("NET/ROM not configured in this system.\n")); /* xxx */ - return 1; + if (f1 == NULL || f2 == NULL) { + printf(_("NET/ROM not configured in this system.\n")); /* xxx */ + return 1; + } + printf(_("Kernel NET/ROM routing table\n")); /* xxx */ + printf(_("Destination Mnemonic Quality Neighbour Iface\n")); /* xxx */ + fgets(buffer, 256, f1); + while (fgets(buffer, 256, f1)) { + buffer[9] = 0; + buffer[17] = 0; + w = atoi(buffer + 19) - 1; + printf("%-9s %-7s ", + buffer, buffer + 10); + qual = atoi(buffer + 24 + 15 * w); + n = atoi(buffer + 32 + 15 * w); + rewind(f2); + fgets(buffer, 256, f2); + while (fgets(buffer, 256, f2)) { + if (atoi(buffer) == n) { + buffer[15] = 0; + buffer[20] = 0; + printf("%3d %-9s %s\n", + qual, buffer + 6, buffer + 16); + break; + } } - printf(_("Kernel NET/ROM routing table\n")); /* xxx */ - printf(_("Destination Mnemonic Quality Neighbour Iface\n")); /* xxx */ - fgets(buffer,256,f1); - while(fgets(buffer,256,f1)) - { - buffer[9]=0; - buffer[17]=0; - w=atoi(buffer+19)-1; - printf("%-9s %-7s ", - buffer,buffer+10); - qual=atoi(buffer+24+15*w); - n=atoi(buffer+32+15*w); - rewind(f2); - fgets(buffer,256,f2); - while(fgets(buffer,256,f2)) - { - if(atoi(buffer)==n) - { - buffer[15]=0; - buffer[20]=0; - printf("%3d %-9s %s\n", - qual,buffer+6,buffer+16); - break; - } - } - } - fclose(f1); - fclose(f2); - return 0; + } + fclose(f1); + fclose(f2); + return 0; } -#endif /* HAVE_AFNETROM */ +#endif /* HAVE_AFNETROM */ diff --git a/lib/netrom_sr.c b/lib/netrom_sr.c index 7a19abf..b085344 100644 --- a/lib/netrom_sr.c +++ b/lib/netrom_sr.c @@ -23,7 +23,7 @@ #include "intl.h" #include "net-features.h" -extern struct aftype netrom_aftype; +extern struct aftype netrom_aftype; /* static int skfd = -1; */ @@ -31,17 +31,17 @@ extern struct aftype netrom_aftype; #if 0 static int usage(void) { - fprintf(stderr,_("netrom usage\n")); + fprintf(stderr, _("netrom usage\n")); - return(E_USAGE); + return (E_USAGE); } #endif int NETROM_rinput(int action, int ext, char **args) { - - fprintf(stderr,_("NET/ROM: this needs to be written\n")); - return(0); + + fprintf(stderr, _("NET/ROM: this needs to be written\n")); + return (0); } -#endif /* HAVE_AFNETROM */ +#endif /* HAVE_AFNETROM */ diff --git a/lib/nstrcmp.c b/lib/nstrcmp.c index e22faf0..8b1ff30 100644 --- a/lib/nstrcmp.c +++ b/lib/nstrcmp.c @@ -1,4 +1,5 @@ -/* Copyright 1998 by Andi Kleen. Subject to the GPL. */ +/* Copyright 1998 by Andi Kleen. Subject to the GPL. */ +/* $Id: nstrcmp.c,v 1.2 1998/11/15 20:11:38 freitag Exp $ */ #include <ctype.h> #include <stdlib.h> #include "util.h" @@ -6,26 +7,28 @@ /* like strcmp(), but knows about numbers */ int nstrcmp(const char *astr, const char *b) { - const char *a = astr; + const char *a = astr; - while (*a == *b) { - if (*a == '\0') return 0; + while (*a == *b) { + if (*a == '\0') + return 0; + a++; + b++; + } + if (isdigit(*a)) { + if (!isdigit(*b)) + return -1; + while (a > astr) { + a--; + if (!isdigit(*a)) { a++; - b++; + break; + } + if (!isdigit(*b)) + return -1; + b--; } - if (isdigit(*a)) { - if (!isdigit(*b)) return -1; - while (a > astr) { - a--; - if (!isdigit(*a)) { - a++; - break; - } - if (!isdigit(*b)) return -1; - b--; - } - return atoi(a) > atoi(b) ? 1 : -1; - } - return *a - *b; + return atoi(a) > atoi(b) ? 1 : -1; + } + return *a - *b; } - diff --git a/lib/pathnames.h b/lib/pathnames.h index 66842bc..6fbd43a 100644 --- a/lib/pathnames.h +++ b/lib/pathnames.h @@ -1,46 +1,47 @@ + /* - * lib/pathnames.h This file contains the definitions of the path - * names used by the NET-LIB. + * lib/pathnames.h This file contains the definitions of the path + * names used by the NET-LIB. * - * NET-LIB + * NET-LIB * - * Version: lib/pathnames.h 1.37 (1997-08-23) + * Version: lib/pathnames.h 1.37 (1997-08-23) * - * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> */ /* pathnames of the procfs files used by NET. */ -# define _PATH_PROCNET_TCP "/proc/net/tcp" -# define _PATH_PROCNET_TCP6 "/proc/net/tcp6" -# define _PATH_PROCNET_UDP "/proc/net/udp" -# define _PATH_PROCNET_UDP6 "/proc/net/udp6" -# define _PATH_PROCNET_RAW "/proc/net/raw" -# define _PATH_PROCNET_RAW6 "/proc/net/raw6" -# define _PATH_PROCNET_UNIX "/proc/net/unix" -# define _PATH_PROCNET_ROUTE "/proc/net/route" -# define _PATH_PROCNET_ROUTE6 "/proc/net/ipv6_route" -# define _PATH_PROCNET_RTCACHE "/proc/net/rt_cache" -# define _PATH_PROCNET_AX25_ROUTE "/proc/net/ax25_route" -# define _PATH_PROCNET_NR "/proc/net/nr" -# define _PATH_PROCNET_NR_NEIGH "/proc/net/nr_neigh" -# define _PATH_PROCNET_NR_NODES "/proc/net/nr_nodes" -# define _PATH_PROCNET_ARP "/proc/net/arp" -# define _PATH_PROCNET_AX25 "/proc/net/ax25" -# define _PATH_PROCNET_IPX "/proc/net/ipx" -# define _PATH_PROCNET_IPX_ROUTE "/proc/net/ipx_route" -# define _PATH_PROCNET_ATALK "/proc/net/appletalk" -# define _PATH_PROCNET_IP_BLK "/proc/net/ip_block" -# define _PATH_PROCNET_IP_FWD "/proc/net/ip_forward" -# define _PATH_PROCNET_IP_ACC "/proc/net/ip_acct" -# define _PATH_PROCNET_IP_MASQ "/proc/net/ip_masquerade" -# define _PATH_PROCNET_NDISC "/proc/net/ndisc" -# define _PATH_PROCNET_IFINET6 "/proc/net/if_inet6" -# define _PATH_PROCNET_DEV "/proc/net/dev" -# define _PATH_PROCNET_RARP "/proc/net/rarp" -# define _PATH_ETHERS "/etc/ethers" -# define _PATH_PROCNET_ROSE_ROUTE "/proc/net/rose_routes" +#define _PATH_PROCNET_TCP "/proc/net/tcp" +#define _PATH_PROCNET_TCP6 "/proc/net/tcp6" +#define _PATH_PROCNET_UDP "/proc/net/udp" +#define _PATH_PROCNET_UDP6 "/proc/net/udp6" +#define _PATH_PROCNET_RAW "/proc/net/raw" +#define _PATH_PROCNET_RAW6 "/proc/net/raw6" +#define _PATH_PROCNET_UNIX "/proc/net/unix" +#define _PATH_PROCNET_ROUTE "/proc/net/route" +#define _PATH_PROCNET_ROUTE6 "/proc/net/ipv6_route" +#define _PATH_PROCNET_RTCACHE "/proc/net/rt_cache" +#define _PATH_PROCNET_AX25_ROUTE "/proc/net/ax25_route" +#define _PATH_PROCNET_NR "/proc/net/nr" +#define _PATH_PROCNET_NR_NEIGH "/proc/net/nr_neigh" +#define _PATH_PROCNET_NR_NODES "/proc/net/nr_nodes" +#define _PATH_PROCNET_ARP "/proc/net/arp" +#define _PATH_PROCNET_AX25 "/proc/net/ax25" +#define _PATH_PROCNET_IPX "/proc/net/ipx" +#define _PATH_PROCNET_IPX_ROUTE "/proc/net/ipx_route" +#define _PATH_PROCNET_ATALK "/proc/net/appletalk" +#define _PATH_PROCNET_IP_BLK "/proc/net/ip_block" +#define _PATH_PROCNET_IP_FWD "/proc/net/ip_forward" +#define _PATH_PROCNET_IP_ACC "/proc/net/ip_acct" +#define _PATH_PROCNET_IP_MASQ "/proc/net/ip_masquerade" +#define _PATH_PROCNET_NDISC "/proc/net/ndisc" +#define _PATH_PROCNET_IFINET6 "/proc/net/if_inet6" +#define _PATH_PROCNET_DEV "/proc/net/dev" +#define _PATH_PROCNET_RARP "/proc/net/rarp" +#define _PATH_ETHERS "/etc/ethers" +#define _PATH_PROCNET_ROSE_ROUTE "/proc/net/rose_routes" /* pathname for the netlink device */ -# define _PATH_DEV_ROUTE "/dev/route" +#define _PATH_DEV_ROUTE "/dev/route" /* End of pathnames.h */ @@ -1,22 +1,22 @@ /* - * lib/ppp.c This file contains the SLIP support for the NET-2 base - * distribution. + * lib/ppp.c This file contains the SLIP support for the NET-2 base + * distribution. * - * Version: @(#)slip.c 1.12 01/07/98 + * Version: $Id: ppp.c,v 1.3 1998/11/15 20:11:45 freitag Exp $ * - * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993 MicroWalt Corporation + * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Copyright 1993 MicroWalt Corporation * - * Modified by Alan Cox, May 94 to cover NET-3 + * Modified by Alan Cox, May 94 to cover NET-3 * * Changes: * 980701 {1.12} Arnaldo Carvalho de Melo - GNU gettext instead of catgets * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -39,20 +39,20 @@ #include "intl.h" /* Start the PPP encapsulation on the file descriptor. */ -static int -do_ppp(int fd) +static int do_ppp(int fd) { - fprintf(stderr,_("You cannot start PPP with this program.\n")); - return -1; + fprintf(stderr, _("You cannot start PPP with this program.\n")); + return -1; } -struct hwtype ppp_hwtype = { - "ppp", NULL, /*"Point-Point Protocol",*/ ARPHRD_PPP, 0, - NULL, NULL, NULL, do_ppp +struct hwtype ppp_hwtype = +{ + "ppp", NULL, /*"Point-Point Protocol", */ ARPHRD_PPP, 0, + NULL, NULL, NULL, do_ppp }; -#endif /* HAVE_PPP */ +#endif /* HAVE_PPP */ diff --git a/lib/ppp_ac.c b/lib/ppp_ac.c index 8e6985f..3b534f9 100644 --- a/lib/ppp_ac.c +++ b/lib/ppp_ac.c @@ -1,16 +1,16 @@ /* - * lib/ppp_ac.c This file contains the activation for the - * PPP line disciplines, called from activate_ld(). + * lib/ppp_ac.c This file contains the activation for the + * PPP line disciplines, called from activate_ld(). * - * Version: ppp_ac.c 0.01 (1996-03-22) + * Version: $Id: ppp_ac.c,v 1.3 1998/11/15 20:11:50 freitag Exp $ * - * Author: Bernd 'eckes' Eckenfels + * Author: Bernd 'eckes' Eckenfels * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -35,8 +35,8 @@ /* Start the VJ-SLIP encapsulation on the file descriptor. */ int PPP_activate(int fd) { - fprintf(stderr,_("Sorry, use pppd!\n")); /* FIXME */ - return(-1); + fprintf(stderr, _("Sorry, use pppd!\n")); /* FIXME */ + return (-1); } -#endif /* HAVE_HWPPP */ +#endif /* HAVE_HWPPP */ @@ -1,46 +1,50 @@ -/* Tolerant /proc file parser. Copyright 1998 Andi Kleen */ +/* Tolerant /proc file parser. Copyright 1998 Andi Kleen */ +/* $Id: proc.c,v 1.3 1998/11/15 20:11:55 freitag Exp $ */ +/* Fixme: cannot currently cope with removed fields */ -#include <string.h> +#include <string.h> #include <stdarg.h> #include <stdio.h> #include <ctype.h> -/* Caller must free return string. */ +/* Caller must free return string. */ -char * -proc_gen_fmt(char *name, int more, FILE *fh, ...) +char *proc_gen_fmt(char *name, int more, FILE * fh,...) { - char buf[512], format[512] = ""; - char *title, *head, *hdr; - va_list ap; + char buf[512], format[512] = ""; + char *title, *head, *hdr; + va_list ap; - if (!fgets(buf, (sizeof buf)-1, fh)) - return NULL; - strcat(buf," "); + if (!fgets(buf, (sizeof buf) - 1, fh)) + return NULL; + strcat(buf, " "); - va_start(ap,fh); - title = va_arg(ap, char *); - for (hdr = buf; hdr; ) { - while (isspace(*hdr) || *hdr == '|') hdr++; - head = hdr; - hdr = strpbrk(hdr,"| \t\n"); - if (hdr) *hdr++ = 0; + va_start(ap, fh); + title = va_arg(ap, char *); + for (hdr = buf; hdr;) { + while (isspace(*hdr) || *hdr == '|') + hdr++; + head = hdr; + hdr = strpbrk(hdr, "| \t\n"); + if (hdr) + *hdr++ = 0; - if (!strcmp(title, head)) { - strcat(format, va_arg(ap, char *)); - title = va_arg(ap, char *); - if (!title || !head) break; - } else { - strcat(format, "%*s"); /* XXX */ - } - strcat(format, " "); + if (!strcmp(title, head)) { + strcat(format, va_arg(ap, char *)); + title = va_arg(ap, char *); + if (!title || !head) + break; + } else { + strcat(format, "%*s"); /* XXX */ } - va_end(ap); + strcat(format, " "); + } + va_end(ap); - if (!more && title) { - fprintf(stderr, "warning: %s does not contain required field %s\n", - name, title); - return NULL; - } - return strdup(format); + if (!more && title) { + fprintf(stderr, "warning: %s does not contain required field %s\n", + name, title); + return NULL; + } + return strdup(format); } @@ -1,4 +1,4 @@ -/* Generate a suitable scanf format for a column title line */ -char *proc_gen_fmt(char *name, int more, FILE *fh, ...); +/* Generate a suitable scanf format for a column title line */ +char *proc_gen_fmt(char *name, int more, FILE * fh,...); @@ -1,19 +1,19 @@ /* - * lib/rose.c This file contains an implementation of the "ROSE" - * support functions for the NET-2 base distribution. + * lib/rose.c This file contains an implementation of the "ROSE" + * support functions for the NET-2 base distribution. * - * Version: @(#)rose.c 1.00 03/08/97 + * Version: $Id: rose.c,v 1.5 1998/11/15 20:12:00 freitag Exp $ * - * Author: Terry Dawson, VK2KTJ, <terry@perf.no.itg.telstra.com.au> - * based on ax25.c by: - * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993 MicroWalt Corporation + * Author: Terry Dawson, VK2KTJ, <terry@perf.no.itg.telstra.com.au> + * based on ax25.c by: + * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Copyright 1993 MicroWalt Corporation * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -22,7 +22,7 @@ #include <sys/types.h> #include <sys/ioctl.h> #include <sys/socket.h> -#include <net/if_arp.h> /* ARPHRD_ROSE */ +#include <net/if_arp.h> /* ARPHRD_ROSE */ #include <stdlib.h> #include <stdio.h> #include <ctype.h> @@ -44,102 +44,102 @@ static char ROSE_errmsg[128]; extern struct aftype rose_aftype; static char * -ROSE_print(unsigned char *ptr) + ROSE_print(unsigned char *ptr) { - static char buff[12]; + static char buff[12]; - snprintf(buff,sizeof(buff),"%02x%02x%02x%02x%02x",ptr[0],ptr[1],ptr[2],ptr[3],ptr[4]); - buff[10] = '\0'; - return(buff); + snprintf(buff, sizeof(buff), "%02x%02x%02x%02x%02x", ptr[0], ptr[1], ptr[2], ptr[3], ptr[4]); + buff[10] = '\0'; + return (buff); } /* Display a ROSE socket address. */ static char * -ROSE_sprint(struct sockaddr *sap, int numeric) + ROSE_sprint(struct sockaddr *sap, int numeric) { - if (sap->sa_family == 0xFFFF || sap->sa_family == 0) - return _("[NONE SET]"); + if (sap->sa_family == 0xFFFF || sap->sa_family == 0) + return _("[NONE SET]"); - return(ROSE_print(((struct sockaddr_rose *)sap)->srose_addr.rose_addr)); + return (ROSE_print(((struct sockaddr_rose *) sap)->srose_addr.rose_addr)); } -static int -ROSE_input(int type, char *bufp, struct sockaddr *sap) +static int ROSE_input(int type, char *bufp, struct sockaddr *sap) { - char *ptr; - int i,o; + char *ptr; + int i, o; - sap->sa_family = rose_aftype.af; - ptr = ((struct sockaddr_rose *)sap)->srose_addr.rose_addr; + sap->sa_family = rose_aftype.af; + ptr = ((struct sockaddr_rose *) sap)->srose_addr.rose_addr; - /* Node address the correct length ? */ - if (strlen(bufp)!=10) { + /* Node address the correct length ? */ + if (strlen(bufp) != 10) { strcpy(ROSE_errmsg, _("Node address must be ten digits")); #ifdef DEBUG fprintf(stderr, "rose_input(%s): %s !\n", ROSE_errmsg, orig); #endif errno = EINVAL; - return(-1); - } - - /* Ok, lets set it */ - for (i=0, o=0; i<5; i++) { - o=i*2; - ptr[i]=(((bufp[o]-'0')<<4) | (bufp[o+1]-'0')); - } - - /* All done. */ + return (-1); + } + /* Ok, lets set it */ + for (i = 0, o = 0; i < 5; i++) { + o = i * 2; + ptr[i] = (((bufp[o] - '0') << 4) | (bufp[o + 1] - '0')); + } + + /* All done. */ #ifdef DEBUG - fprintf(stderr, "rose_input(%s): ", orig); - for (i = 0; i < sizeof(rose_address); i++) + fprintf(stderr, "rose_input(%s): ", orig); + for (i = 0; i < sizeof(rose_address); i++) fprintf(stderr, "%02X ", sap->sa_data[i] & 0377); - fprintf(stderr, "\n"); + fprintf(stderr, "\n"); #endif - return(0); + return (0); } /* Display an error message. */ -static void -ROSE_herror(char *text) +static void ROSE_herror(char *text) { - if (text == NULL) fprintf(stderr, "%s\n", ROSE_errmsg); - else fprintf(stderr, "%s: %s\n", text, ROSE_errmsg); + if (text == NULL) + fprintf(stderr, "%s\n", ROSE_errmsg); + else + fprintf(stderr, "%s: %s\n", text, ROSE_errmsg); } static char * -ROSE_hprint(struct sockaddr *sap) + ROSE_hprint(struct sockaddr *sap) { - if (sap->sa_family == 0xFFFF || sap->sa_family == 0) - return _("[NONE SET]"); + if (sap->sa_family == 0xFFFF || sap->sa_family == 0) + return _("[NONE SET]"); - return(ROSE_print(((struct sockaddr_rose *)sap)->srose_addr.rose_addr)); + return (ROSE_print(((struct sockaddr_rose *) sap)->srose_addr.rose_addr)); } -static int -ROSE_hinput(char *bufp, struct sockaddr *sap) +static int ROSE_hinput(char *bufp, struct sockaddr *sap) { - if (ROSE_input(0, bufp, sap) < 0) return(-1); - sap->sa_family = ARPHRD_ROSE; - return(0); + if (ROSE_input(0, bufp, sap) < 0) + return (-1); + sap->sa_family = ARPHRD_ROSE; + return (0); } -struct hwtype rose_hwtype = { - "rose", NULL, /*"AMPR ROSE",*/ ARPHRD_ROSE, 10, - ROSE_print, ROSE_hprint, ROSE_hinput, NULL +struct hwtype rose_hwtype = +{ + "rose", NULL, /*"AMPR ROSE", */ ARPHRD_ROSE, 10, + ROSE_print, ROSE_hprint, ROSE_hinput, NULL }; -struct aftype rose_aftype = { - "rose", NULL, /*"AMPR ROSE",*/ AF_ROSE, 10, - ROSE_print, ROSE_sprint, ROSE_input, ROSE_herror, - NULL, NULL, NULL, - -1, - "/proc/net/rose" +struct aftype rose_aftype = +{ + "rose", NULL, /*"AMPR ROSE", */ AF_ROSE, 10, + ROSE_print, ROSE_sprint, ROSE_input, ROSE_herror, + NULL, NULL, NULL, + -1, + "/proc/net/rose" }; -#endif /* HAVE_xxROSE */ - +#endif /* HAVE_xxROSE */ diff --git a/lib/rose_gr.c b/lib/rose_gr.c index 182c720..e67750b 100644 --- a/lib/rose_gr.c +++ b/lib/rose_gr.c @@ -1,20 +1,21 @@ + /* - * lib/rose_gr.c This file contains an implementation of the "ROSE" - * route print support functions. + * lib/rose_gr.c This file contains an implementation of the "ROSE" + * route print support functions. * - * Version: lib/rose_gr.c 1.00 03/08/97 + * Version: $Id: rose_gr.c,v 1.3 1998/11/15 20:12:03 freitag Exp $ * - * Author: Terry Dawson, VK2KTJ, <terry@perf.no.itg.telstra.com.au> - * based on ax25_gr.c by: - * Bernd Eckenfels, <ecki@lina.inka.de> - * Copyright 1999 Bernd Eckenfels, Germany - * base on Code from Jonathan Naylor <jsn@Cs.Nott.AC.UK> + * Author: Terry Dawson, VK2KTJ, <terry@perf.no.itg.telstra.com.au> + * based on ax25_gr.c by: + * Bernd Eckenfels, <ecki@lina.inka.de> + * Copyright 1999 Bernd Eckenfels, Germany + * base on Code from Jonathan Naylor <jsn@Cs.Nott.AC.UK> * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -24,7 +25,7 @@ #include <sys/ioctl.h> #include <linux/rose.h> #include <sys/socket.h> -#include <net/if_arp.h> /* ARPHRD_ROSE */ +#include <net/if_arp.h> /* ARPHRD_ROSE */ #include <ctype.h> #include <errno.h> #include <fcntl.h> @@ -40,28 +41,26 @@ int ROSE_rprint(int options) { - FILE *f=fopen(_PATH_PROCNET_ROSE_ROUTE, "r"); - char buffer[256]; - int use; + FILE *f = fopen(_PATH_PROCNET_ROSE_ROUTE, "r"); + char buffer[256]; + int use; - if(f==NULL) - { - printf(_("ROSE not configured in this system.\n")); /* xxx */ - return 1; - } - printf(_("Kernel ROSE routing table\n")); /* xxx */ - printf(_("Destination Iface Use\n")); /* xxx */ - fgets(buffer,256,f); - while(fgets(buffer,256,f)) - { - buffer[9]=0; - buffer[14]=0; - use=atoi(buffer+15); - printf("%-9s %-5s %5d\n", - buffer,buffer+10,use); - } - fclose(f); - return 0; + if (f == NULL) { + printf(_("ROSE not configured in this system.\n")); /* xxx */ + return 1; + } + printf(_("Kernel ROSE routing table\n")); /* xxx */ + printf(_("Destination Iface Use\n")); /* xxx */ + fgets(buffer, 256, f); + while (fgets(buffer, 256, f)) { + buffer[9] = 0; + buffer[14] = 0; + use = atoi(buffer + 15); + printf("%-9s %-5s %5d\n", + buffer, buffer + 10, use); + } + fclose(f); + return 0; } -#endif /* HAVE_AFROSE */ +#endif /* HAVE_AFROSE */ diff --git a/lib/setroute.c b/lib/setroute.c index 482f1c1..9a8b9d6 100644 --- a/lib/setroute.c +++ b/lib/setroute.c @@ -1,28 +1,28 @@ /* - * lib/setroute.c This file contains a small interface function to - * use the AF specific input routine for the routing - * table. + * lib/setroute.c This file contains a small interface function to + * use the AF specific input routine for the routing + * table. * - * NET-LIB A collection of functions used from the base set of the - * NET-3 Networking Distribution for the LINUX operating - * system. (net-tools, net-drivers) + * NET-LIB A collection of functions used from the base set of the + * NET-3 Networking Distribution for the LINUX operating + * system. (net-tools, net-drivers) * - * Version: lib/setroute.c 0.02 (1996-04-13) + * Version: $Id: setroute.c,v 1.3 1998/11/15 20:12:07 freitag Exp $ * - * Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de> - * Copyright 1999 Bernd Eckenfels, Germany + * Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de> + * Copyright 1999 Bernd Eckenfels, Germany * * Modifications: * - *960221 {0.01} Bernd Eckenfels: generated from getroute.c - *960413 {0.02} Bernd Eckenfels: new RTACTION support + *960221 {0.01} Bernd Eckenfels: generated from getroute.c + *960413 {0.02} Bernd Eckenfels: new RTACTION support *960809 Frank Strauss: INET6 * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include <stdio.h> #include <string.h> @@ -32,57 +32,53 @@ #include "config.h" #include "intl.h" -extern struct aftype unspec_aftype; -extern struct aftype unix_aftype; -extern struct aftype inet_aftype; -extern struct aftype inet6_aftype; -extern struct aftype ax25_aftype; -extern struct aftype netrom_aftype; -extern struct aftype ipx_aftype; -extern struct aftype ddp_aftype; +extern struct aftype unspec_aftype; +extern struct aftype unix_aftype; +extern struct aftype inet_aftype; +extern struct aftype inet6_aftype; +extern struct aftype ax25_aftype; +extern struct aftype netrom_aftype; +extern struct aftype ipx_aftype; +extern struct aftype ddp_aftype; -void -setroute_init(void) +void setroute_init(void) { #if HAVE_AFINET - inet_aftype.rinput = INET_rinput; + inet_aftype.rinput = INET_rinput; #endif #if HAVE_AFINET6 - inet6_aftype.rinput = INET6_rinput; + inet6_aftype.rinput = INET6_rinput; #endif #if HAVE_AFNETROM - netrom_aftype.rinput = NETROM_rinput; + netrom_aftype.rinput = NETROM_rinput; #endif #if HAVE_AFIPX - ipx_aftype.rinput = IPX_rinput; + ipx_aftype.rinput = IPX_rinput; #endif #if 0 #if HAVE_AFAX25 - ax25_aftype.rinput = AX25_rinput; + ax25_aftype.rinput = AX25_rinput; #endif #if HAVE_AFATALK - ddp_aftype.rinput = DDP_rinput; + ddp_aftype.rinput = DDP_rinput; #endif #endif } -int -route_edit(int action, const char *afname, int options, char **argv) +int route_edit(int action, const char *afname, int options, char **argv) { - struct aftype *ap; - - ap = get_aftype(afname); + struct aftype *ap; - if (!ap) { - fprintf(stderr,_("Address family `%s' not supported.\n"),afname); - return(E_OPTERR); - } + ap = get_aftype(afname); - if (!ap->rinput) { - fprintf(stderr,_("No routing for address family `%s'.\n"),ap->name); - return(E_OPTERR); - } - - return(ap->rinput(action, options, argv)); + if (!ap) { + fprintf(stderr, _("Address family `%s' not supported.\n"), afname); + return (E_OPTERR); + } + if (!ap->rinput) { + fprintf(stderr, _("No routing for address family `%s'.\n"), ap->name); + return (E_OPTERR); + } + return (ap->rinput(action, options, argv)); } @@ -1,18 +1,18 @@ /* - * lib/sit.c This file contains the SIT HW-type support. + * lib/sit.c This file contains the SIT HW-type support. * - * Version: sit.c 0.01 (1996-08-08) + * Version: $Id: sit.c,v 1.3 1998/11/15 20:12:12 freitag Exp $ * - * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993 MicroWalt Corporation + * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Copyright 1993 MicroWalt Corporation * - * Based on slip.c, modified by Frank Strauss, Aug 1996 + * Based on slip.c, modified by Frank Strauss, Aug 1996 * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -33,9 +33,10 @@ #include "net-support.h" #include "pathnames.h" -struct hwtype sit_hwtype = { - "sit", NULL, /*"IPv6-in-IPv4",*/ ARPHRD_SIT, 0, - NULL, NULL, NULL, NULL +struct hwtype sit_hwtype = +{ + "sit", NULL, /*"IPv6-in-IPv4", */ ARPHRD_SIT, 0, + NULL, NULL, NULL, NULL }; -#endif /* HAVE_HWSIT */ +#endif /* HAVE_HWSIT */ @@ -1,18 +1,18 @@ /* - * lib/slip.c This file contains the SLIP HW-type support. + * lib/slip.c This file contains the SLIP HW-type support. * - * Version: slip.c 1.20 (1996-03-22) + * Version: $Id: slip.c,v 1.3 1998/11/15 20:12:16 freitag Exp $ * - * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993 MicroWalt Corporation + * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Copyright 1993 MicroWalt Corporation * - * Modified by Alan Cox, May 94 to cover NET-3 + * Modified by Alan Cox, May 94 to cover NET-3 * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -34,24 +34,29 @@ #include "pathnames.h" -struct hwtype slip_hwtype = { - "slip", NULL, /*"Serial Line IP",*/ ARPHRD_SLIP, 0, - NULL, NULL, NULL, NULL +struct hwtype slip_hwtype = +{ + "slip", NULL, /*"Serial Line IP", */ ARPHRD_SLIP, 0, + NULL, NULL, NULL, NULL }; -struct hwtype cslip_hwtype = { - "cslip", NULL, /*"VJ Serial Line IP",*/ ARPHRD_CSLIP, 0, - NULL, NULL, NULL, NULL +struct hwtype cslip_hwtype = +{ + "cslip", NULL, /*"VJ Serial Line IP", */ ARPHRD_CSLIP, 0, + NULL, NULL, NULL, NULL }; -struct hwtype slip6_hwtype = { - "slip6", NULL, /*"6-bit Serial Line IP",*/ ARPHRD_SLIP6, 0, - NULL, NULL, NULL, NULL +struct hwtype slip6_hwtype = +{ + "slip6", NULL, /*"6-bit Serial Line IP", */ ARPHRD_SLIP6, 0, + NULL, NULL, NULL, NULL }; -struct hwtype cslip6_hwtype = { - "cslip6", NULL, /*"VJ 6-bit Serial Line IP",*/ ARPHRD_CSLIP6, 0, - NULL, NULL, NULL, NULL +struct hwtype cslip6_hwtype = +{ + "cslip6", NULL, /*"VJ 6-bit Serial Line IP", */ ARPHRD_CSLIP6, 0, + NULL, NULL, NULL, NULL }; -struct hwtype adaptive_hwtype = { - "adaptive", NULL, /*"Adaptive Serial Line IP",*/ ARPHRD_ADAPT,0, - NULL, NULL, NULL, NULL +struct hwtype adaptive_hwtype = +{ + "adaptive", NULL, /*"Adaptive Serial Line IP", */ ARPHRD_ADAPT, 0, + NULL, NULL, NULL, NULL }; -#endif /* HAVE_HWSLIP */ +#endif /* HAVE_HWSLIP */ diff --git a/lib/slip_ac.c b/lib/slip_ac.c index 2d78efb..c48937b 100644 --- a/lib/slip_ac.c +++ b/lib/slip_ac.c @@ -1,20 +1,20 @@ /* - * lib/slip_ac.c This file contains the activation for the - * SLIP line disciplines, called from activate_ld(). + * lib/slip_ac.c This file contains the activation for the + * SLIP line disciplines, called from activate_ld(). * - * Version: slip.c 0.11 (1996-03-22) + * Version: $Id: slip_ac.c,v 1.3 1998/11/15 20:12:20 freitag Exp $ * - * Author: Bernd 'eckes' Eckenfels - * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993 MicroWalt Corporation + * Author: Bernd 'eckes' Eckenfels + * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Copyright 1993 MicroWalt Corporation * - * Modified by Alan Cox, May 94 to cover NET-3 + * Modified by Alan Cox, May 94 to cover NET-3 * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -37,70 +37,78 @@ /* Set the line discipline of a terminal line. */ -static int -SLIP_set_disc(int fd, int disc) +static int SLIP_set_disc(int fd, int disc) { - if (ioctl(fd, TIOCSETD, &disc) < 0) { + if (ioctl(fd, TIOCSETD, &disc) < 0) { fprintf(stderr, "SLIP_set_disc(%d): %s\n", disc, strerror(errno)); - return(-errno); - } - return(0); + return (-errno); + } + return (0); } /* Set the encapsulation type of a terminal line. */ -static int -SLIP_set_encap(int fd, int encap) +static int SLIP_set_encap(int fd, int encap) { - if (ioctl(fd, SIOCSIFENCAP, &encap) < 0) { + if (ioctl(fd, SIOCSIFENCAP, &encap) < 0) { fprintf(stderr, "SLIP_set_encap(%d): %s\n", encap, strerror(errno)); - return(-errno); - } - return(0); + return (-errno); + } + return (0); } /* Start the SLIP encapsulation on the file descriptor. */ int SLIP_activate(int fd) { - if (SLIP_set_disc(fd, N_SLIP) < 0) return(-1); - if (SLIP_set_encap(fd, 0) < 0) return(-1); - return(0); + if (SLIP_set_disc(fd, N_SLIP) < 0) + return (-1); + if (SLIP_set_encap(fd, 0) < 0) + return (-1); + return (0); } /* Start the VJ-SLIP encapsulation on the file descriptor. */ int CSLIP_activate(int fd) { - if (SLIP_set_disc(fd, N_SLIP) < 0) return(-1); - if (SLIP_set_encap(fd, 1) < 0) return(-1); - return(0); + if (SLIP_set_disc(fd, N_SLIP) < 0) + return (-1); + if (SLIP_set_encap(fd, 1) < 0) + return (-1); + return (0); } /* Start the SLIP-6 encapsulation on the file descriptor. */ int SLIP6_activate(int fd) { - if (SLIP_set_disc(fd, N_SLIP) < 0) return(-1); - if (SLIP_set_encap(fd, 2) < 0) return(-1); - return(0); + if (SLIP_set_disc(fd, N_SLIP) < 0) + return (-1); + if (SLIP_set_encap(fd, 2) < 0) + return (-1); + return (0); } /* Start the VJ-SLIP-6 encapsulation on the file descriptor. */ int CSLIP6_activate(int fd) { - if (SLIP_set_disc(fd, N_SLIP) < 0) return(-1); - if (SLIP_set_encap(fd, 3) < 0) return(-1); - return(0); + if (SLIP_set_disc(fd, N_SLIP) < 0) + return (-1); + if (SLIP_set_encap(fd, 3) < 0) + return (-1); + return (0); } /* Start adaptive encapsulation on the file descriptor. */ int ADAPTIVE_activate(int fd) { - if (SLIP_set_disc(fd, N_SLIP) < 0) return(-1); - if (SLIP_set_encap(fd, 8) < 0) return(-1); - return(0); + if (SLIP_set_disc(fd, N_SLIP) < 0) + return (-1); + if (SLIP_set_encap(fd, 8) < 0) + return (-1); + return (0); } -#endif /* HAVE_HWSLIP */ +#endif /* HAVE_HWSLIP */ @@ -1,17 +1,17 @@ /* - * lib/tr.c This file contains an implementation of the "Ethernet" - * support functions for the NET-2 base distribution. + * lib/tr.c This file contains an implementation of the "Tokenring" + * support functions. * - * Version: @(#)tr.c 1.10 10/07/93 + * Version: $Id: tr.c,v 1.3 1998/11/15 20:12:25 freitag Exp $ * - * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993 MicroWalt Corporation + * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Copyright 1993 MicroWalt Corporation * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" @@ -33,105 +33,105 @@ extern struct hwtype tr_hwtype; - -/* Display an Ethernet address in readable format. */ -static char * -pr_tr(unsigned char *ptr) +static char *pr_tr(unsigned char *ptr) { - static char buff[64]; + static char buff[64]; - snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X", - (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), - (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) - ); - return(buff); + snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X", + (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), + (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) + ); + return (buff); } -/* Display an Ethernet socket address. */ -static char * -pr_str(struct sockaddr *sap) +static char *pr_str(struct sockaddr *sap) { - if (sap->sa_family == 0xFFFF || sap->sa_family == 0) return("[NONE SET]"); - return(pr_tr(sap->sa_data)); + if (sap->sa_family == 0xFFFF || sap->sa_family == 0) + return ("[NONE SET]"); + return (pr_tr(sap->sa_data)); } -/* Input an Ethernet address and convert to binary. */ -static int -in_tr(char *bufp, struct sockaddr *sap) +static int in_tr(char *bufp, struct sockaddr *sap) { - unsigned char *ptr; - char c, *orig; - int i, val; + unsigned char *ptr; + char c, *orig; + int i, val; - sap->sa_family = tr_hwtype.type; - ptr = sap->sa_data; + sap->sa_family = tr_hwtype.type; + ptr = sap->sa_data; - i = 0; - orig = bufp; - while((*bufp != '\0') && (i < TR_ALEN)) { + i = 0; + orig = bufp; + while ((*bufp != '\0') && (i < TR_ALEN)) { val = 0; c = *bufp++; - if (isdigit(c)) val = c - '0'; - else if (c >= 'a' && c <= 'f') val = c - 'a' + 10; - else if (c >= 'A' && c <= 'F') val = c - 'A' + 10; - else { + if (isdigit(c)) + val = c - '0'; + else if (c >= 'a' && c <= 'f') + val = c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + val = c - 'A' + 10; + else { #ifdef DEBUG - fprintf(stderr, _("in_tr(%s): invalid token ring address!\n"), orig); + fprintf(stderr, _("in_tr(%s): invalid token ring address!\n"), orig); #endif - errno = EINVAL; - return(-1); + errno = EINVAL; + return (-1); } val <<= 4; c = *bufp++; - if (isdigit(c)) val |= c - '0'; - else if (c >= 'a' && c <= 'f') val |= c - 'a' + 10; - else if (c >= 'A' && c <= 'F') val |= c - 'A' + 10; - else { + if (isdigit(c)) + val |= c - '0'; + else if (c >= 'a' && c <= 'f') + val |= c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + val |= c - 'A' + 10; + else { #ifdef DEBUG - fprintf(stderr, _("in_tr(%s): invalid token ring address!\n"), orig); + fprintf(stderr, _("in_tr(%s): invalid token ring address!\n"), orig); #endif - errno = EINVAL; - return(-1); + errno = EINVAL; + return (-1); } *ptr++ = (unsigned char) (val & 0377); i++; /* We might get a semicolon here - not required. */ if (*bufp == ':') { - if (i == TR_ALEN) { + if (i == TR_ALEN) { #ifdef DEBUG - fprintf(stderr, _("in_tr(%s): trailing : ignored!\n"), - orig) + fprintf(stderr, _("in_tr(%s): trailing : ignored!\n"), + orig) #endif - ; /* nothing */ - } - bufp++; + ; /* nothing */ + } + bufp++; } - } + } - /* That's it. Any trailing junk? */ - if ((i == TR_ALEN) && (*bufp != '\0')) { + /* That's it. Any trailing junk? */ + if ((i == TR_ALEN) && (*bufp != '\0')) { #ifdef DEBUG fprintf(stderr, _("in_tr(%s): trailing junk!\n"), orig); errno = EINVAL; - return(-1); + return (-1); #endif - } - + } #ifdef DEBUG - fprintf(stderr, "in_tr(%s): %s\n", orig, pr_tr(sap->sa_data)); + fprintf(stderr, "in_tr(%s): %s\n", orig, pr_tr(sap->sa_data)); #endif - return(0); + return (0); } -struct hwtype tr_hwtype = { - "tr", "16/4 Mbps TR", ARPHRD_IEEE802, TR_ALEN, - pr_tr, pr_str, in_tr, NULL +struct hwtype tr_hwtype = +{ + "tr", "16/4 Mbps TR", ARPHRD_IEEE802, TR_ALEN, + pr_tr, pr_str, in_tr, NULL }; -#endif /* HAVE_HWTR */ +#endif /* HAVE_HWTR */ diff --git a/lib/tunnel.c b/lib/tunnel.c index 4a72d8f..2e8cf4b 100644 --- a/lib/tunnel.c +++ b/lib/tunnel.c @@ -1,8 +1,8 @@ /* - * Tunnel.c, Alan Cox 1995. + * Tunnel.c, Alan Cox 1995. * */ - + #include "config.h" #if HAVE_HWTUNNEL @@ -21,31 +21,29 @@ extern struct hwtype ether_hwtype; - -static char * -pr_tunnel(unsigned char *ptr) +static char *pr_tunnel(unsigned char *ptr) { - return(""); + return (""); } static char *pr_stunnel(struct sockaddr *sap) { - return(""); + return (""); } -static int -in_tunnel(char *bufp, struct sockaddr *sap) +static int in_tunnel(char *bufp, struct sockaddr *sap) { - return(-1); + return (-1); } -struct hwtype tunnel_hwtype = { - "tunnel", NULL, /*"IPIP Tunnel",*/ ARPHRD_TUNNEL, 0, - pr_tunnel, pr_stunnel, in_tunnel, NULL +struct hwtype tunnel_hwtype = +{ + "tunnel", NULL, /*"IPIP Tunnel", */ ARPHRD_TUNNEL, 0, + pr_tunnel, pr_stunnel, in_tunnel, NULL }; -#endif /* HAVE_HWTUNNEL */ +#endif /* HAVE_HWTUNNEL */ @@ -1,23 +1,23 @@ /* - * lib/unix.c This file contains the general hardware types. + * lib/unix.c This file contains the general hardware types. * - * Version: @(#)unix.c 1.10 10/07/93 + * Version: $Id: unix.c,v 1.4 1998/11/15 20:12:31 freitag Exp $ * - * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> - * Copyright 1993 MicroWalt Corporation + * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> + * Copyright 1993 MicroWalt Corporation * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at - * your option) any later version. + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. */ #include "config.h" #include <sys/types.h> #include <sys/socket.h> #if HAVE_AFUNIX -# include <sys/un.h> +#include <sys/un.h> #endif #include <stdlib.h> #include <stdio.h> @@ -31,68 +31,66 @@ /* Display an UNSPEC address. */ -static char * -UNSPEC_print(unsigned char *ptr) +static char *UNSPEC_print(unsigned char *ptr) { - static char buff[64]; - char *pos; - unsigned int i; + static char buff[64]; + char *pos; + unsigned int i; - pos = buff; - for(i = 0; i < sizeof(struct sockaddr); i++) { + pos = buff; + for (i = 0; i < sizeof(struct sockaddr); i++) { pos += sprintf(pos, "%02X-", (*ptr++ & 0377)); - } - buff[strlen(buff) - 1] = '\0'; - return(buff); + } + buff[strlen(buff) - 1] = '\0'; + return (buff); } /* Display an UNSPEC socket address. */ -static char * -UNSPEC_sprint(struct sockaddr *sap, int numeric) +static char *UNSPEC_sprint(struct sockaddr *sap, int numeric) { - static char buf[64]; + static char buf[64]; - if (sap->sa_family == 0xFFFF || sap->sa_family == 0) - return strncpy (buf, _("[NONE SET]"), sizeof(buf)); - return(UNSPEC_print(sap->sa_data)); + if (sap->sa_family == 0xFFFF || sap->sa_family == 0) + return strncpy(buf, _("[NONE SET]"), sizeof(buf)); + return (UNSPEC_print(sap->sa_data)); } #if HAVE_AFUNIX /* Display a UNIX domain address. */ -static char * -UNIX_print(unsigned char *ptr) +static char *UNIX_print(unsigned char *ptr) { - return(ptr); + return (ptr); } /* Display a UNIX domain address. */ -static char * -UNIX_sprint(struct sockaddr *sap, int numeric) +static char *UNIX_sprint(struct sockaddr *sap, int numeric) { - static char buf[64]; + static char buf[64]; - if (sap->sa_family == 0xFFFF || sap->sa_family == 0) - return strncpy (buf, _("[NONE SET]"), sizeof(buf)); - return(UNIX_print(sap->sa_data)); + if (sap->sa_family == 0xFFFF || sap->sa_family == 0) + return strncpy(buf, _("[NONE SET]"), sizeof(buf)); + return (UNIX_print(sap->sa_data)); } -struct aftype unix_aftype = { - "unix", NULL, /*"UNIX Domain",*/ AF_UNIX, 0, - UNIX_print, UNIX_sprint, NULL, NULL, - NULL, NULL, NULL, - -1, - "/proc/net/unix" +struct aftype unix_aftype = +{ + "unix", NULL, /*"UNIX Domain", */ AF_UNIX, 0, + UNIX_print, UNIX_sprint, NULL, NULL, + NULL, NULL, NULL, + -1, + "/proc/net/unix" }; -#endif /* HAVE_AFUNIX */ +#endif /* HAVE_AFUNIX */ -struct aftype unspec_aftype = { - "unspec", NULL, /*"UNSPEC",*/ AF_UNSPEC, 0, - UNSPEC_print, UNSPEC_sprint, NULL, NULL, - NULL, +struct aftype unspec_aftype = +{ + "unspec", NULL, /*"UNSPEC", */ AF_UNSPEC, 0, + UNSPEC_print, UNSPEC_sprint, NULL, NULL, + NULL, }; @@ -1,38 +1,40 @@ +/* Copyright 1998 by Andi Kleen. Subject to the GPL. */ +/* $Id: util.c,v 1.3 1998/11/15 20:12:35 freitag Exp $ */ #include <stdio.h> #include <stdlib.h> #include "util.h" #include <sys/utsname.h> static void oom(void) -{ - fprintf(stderr, "out of virtual memory\n"); - exit(2); +{ + fprintf(stderr, "out of virtual memory\n"); + exit(2); } void *xmalloc(size_t sz) { - void *p = calloc(sz,1); - if (!p) - oom(); - return p; + void *p = calloc(sz, 1); + if (!p) + oom(); + return p; } void *xrealloc(void *oldp, size_t sz) { - void *p = realloc(oldp,sz); - if (!p) - oom(); - return p; + void *p = realloc(oldp, sz); + if (!p) + oom(); + return p; } int kernel_version(void) { - struct utsname uts; - int major, minor, patch; + struct utsname uts; + int major, minor, patch; - if (uname(&uts) < 0) - return -1; - if (sscanf(uts.release, "%d.%d.%d", &major, &minor, &patch) != 3) - return -1; - return KRELEASE(major,minor,patch); + if (uname(&uts) < 0) + return -1; + if (sscanf(uts.release, "%d.%d.%d", &major, &minor, &patch) != 3) + return -1; + return KRELEASE(major, minor, patch); } @@ -1,13 +1,13 @@ #include <stddef.h> -void *xmalloc(size_t sz); -void *xrealloc(void *p, size_t sz); +void *xmalloc(size_t sz); +void *xrealloc(void *p, size_t sz); #define new(p) ((p) = xmalloc(sizeof(*(p)))) - -int kernel_version(void); -#define KRELEASE(maj,min,patch) ((maj) * 10000 + (min)*1000 + (patch)) +int kernel_version(void); +#define KRELEASE(maj,min,patch) ((maj) * 10000 + (min)*1000 + (patch)) -int nstrcmp(const char *, const char *); + +int nstrcmp(const char *, const char *); |