Commit 49d6a000 authored by Klaas Freitag's avatar Klaas Freitag

Yow. This is net-tools completely reindented.

Some other cleanups:
- lib/net-string.c removed because it was not used and had a copyright notice
that conflicted with the GPL.
- Minor cleanups.
- Fix an potential buffer overflow in ax25.
- Switch to CVS $Id$ for versioning consistently
parent 72c29c95
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/* Sanitised ipx.h for net-tools. */
#ifndef _IPX_H_
......@@ -6,8 +7,7 @@
#define IPX_NODE_LEN 6
#define IPX_MTU 576
struct sockaddr_ipx
{
struct sockaddr_ipx {
#if LINUX_VERSION_CODE > 131328 /* 2.1.0 or later */
sa_family_t sipx_family;
#else
......@@ -18,7 +18,7 @@ struct sockaddr_ipx
unsigned char sipx_node[IPX_NODE_LEN];
unsigned char sipx_type;
unsigned char sipx_zero; /* 16 byte fill */
};
};
#define IPX_FRAME_NONE 0
#define IPX_FRAME_SNAP 1
......
/* Code to manipulate interface information, shared between ifconfig and
netstat.
10/1998 partly rewriten by Andi Kleen to support interface list.
10/1998 partly rewriten by Andi Kleen to support an interface list.
I don't claim that the list operations are efficient @).
$Id: interface.c,v 1.9 1998/11/15 18:58:40 freitag Exp $
$Id: interface.c,v 1.10 1998/11/15 20:07:52 freitag Exp $
*/
#include "config.h"
......@@ -71,14 +71,13 @@ struct interface *lookup_interface(char *name)
if (!int_list && (if_readlist()) < 0)
return NULL;
for (ife = int_list; ife; ife = ife->next) {
if (!strcmp(ife->name,name))
if (!strcmp(ife->name, name))
break;
}
return ife;
}
int
for_all_interfaces(int (*doit)(struct interface *, void *), void *cookie)
int for_all_interfaces(int (*doit) (struct interface *, void *), void *cookie)
{
struct interface *ife;
......@@ -108,7 +107,6 @@ static int if_readconf(void)
strerror(errno));
return -1;
}
ifc.ifc_buf = NULL;
for (;;) {
ifc.ifc_len = sizeof(struct ifreq) * numreqs;
......@@ -118,8 +116,7 @@ static int if_readconf(void)
perror("SIOCGIFCONF");
goto out;
}
if (ifc.ifc_len == sizeof(struct ifreq)*numreqs) {
if (ifc.ifc_len == sizeof(struct ifreq) * numreqs) {
/* assume it overflowed and try again */
numreqs += 10;
continue;
......@@ -127,7 +124,7 @@ static int if_readconf(void)
break;
}
for (ifr = ifc.ifc_req,n = 0; n < ifc.ifc_len;
for (ifr = ifc.ifc_req, n = 0; n < ifc.ifc_len;
n += sizeof(struct ifreq), ifr++) {
struct interface *ife;
......@@ -141,14 +138,15 @@ static int if_readconf(void)
}
err = 0;
out:
out:
free(ifc.ifc_buf);
return err;
}
static char *get_name(char *name, char *p)
{
while (isspace(*p)) p++;
while (isspace(*p))
p++;
while (*p) {
if (isspace(*p))
break;
......@@ -161,7 +159,8 @@ static char *get_name(char *name, char *p)
p = dot;
name = dotname;
}
if (*p == '\0') return NULL;
if (*p == '\0')
return NULL;
p++;
break;
}
......@@ -173,15 +172,15 @@ static char *get_name(char *name, char *p)
static int procnetdev_version(char *buf)
{
if (strstr(buf,"compressed"))
if (strstr(buf, "compressed"))
return 3;
if (strstr(buf,"bytes"))
if (strstr(buf, "bytes"))
return 2;
return 1;
}
static int get_dev_fields(char *bp, struct interface *ife)
{
{
switch (procnetdev_vsn) {
case 3:
sscanf(bp,
......@@ -251,14 +250,13 @@ int if_readlist(void)
struct interface *ife;
int err;
fh = fopen(_PATH_PROCNET_DEV,"r");
fh = fopen(_PATH_PROCNET_DEV, "r");
if (!fh) {
perror(_PATH_PROCNET_DEV);
return -1;
}
fgets(buf,sizeof buf,fh); /* eat line */
fgets(buf,sizeof buf,fh);
fgets(buf, sizeof buf, fh); /* eat line */
fgets(buf, sizeof buf, fh);
#if 0 /* pretty, but can't cope with missing fields */
fmt = proc_gen_fmt(_PATH_PROCNET_DEV, 1, fh,
......@@ -287,7 +285,7 @@ int if_readlist(void)
#endif
err = 0;
while (fgets(buf,sizeof buf,fh)) {
while (fgets(buf, sizeof buf, fh)) {
char *s;
new(ife);
......@@ -302,7 +300,6 @@ int if_readlist(void)
perror(_PATH_PROCNET_DEV);
err = -1;
}
if (!err)
err = if_readconf();
......@@ -317,29 +314,29 @@ int if_readlist(void)
#if HAVE_AFIPX
static int ipx_getaddr(int sock, int ft, struct ifreq *ifr)
{
((struct sockaddr_ipx *)&ifr->ifr_addr)->sipx_type=ft;
((struct sockaddr_ipx *) &ifr->ifr_addr)->sipx_type = ft;
return ioctl(sock, SIOCGIFADDR, ifr);
}
#endif
/* Fetch the interface configuration from the kernel. */
int
if_fetch(char *ifname, struct interface *ife)
int if_fetch(char *ifname, struct interface *ife)
{
struct ifreq ifr;
int fd;
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) return(-1);
if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0)
return (-1);
ife->flags = ifr.ifr_flags;
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFHWADDR, &ifr) < 0)
memset(ife->hwaddr, 0, 32);
else
memcpy(ife->hwaddr,ifr.ifr_hwaddr.sa_data,8);
memcpy(ife->hwaddr, ifr.ifr_hwaddr.sa_data, 8);
ife->type=ifr.ifr_hwaddr.sa_family;
ife->type = ifr.ifr_hwaddr.sa_family;
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFMETRIC, &ifr) < 0)
......@@ -353,30 +350,29 @@ if_fetch(char *ifname, struct interface *ife)
else
ife->mtu = ifr.ifr_mtu;
if (ife->type==ARPHRD_SLIP || ife->type==ARPHRD_CSLIP ||
ife->type==ARPHRD_SLIP6 || ife->type==ARPHRD_CSLIP6 ||
ife->type==ARPHRD_ADAPT) {
if (ife->type == ARPHRD_SLIP || ife->type == ARPHRD_CSLIP ||
ife->type == ARPHRD_SLIP6 || ife->type == ARPHRD_CSLIP6 ||
ife->type == ARPHRD_ADAPT) {
#ifdef SIOCGOUTFILL
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGOUTFILL, &ifr) < 0)
ife->outfill = 0;
else
ife->outfill = (unsigned int)ifr.ifr_data;
ife->outfill = (unsigned int) ifr.ifr_data;
#endif
#ifdef SIOCGKEEPALIVE
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGKEEPALIVE, &ifr) < 0)
ife->keepalive = 0;
else
ife->keepalive = (unsigned int)ifr.ifr_data;
ife->keepalive = (unsigned int) ifr.ifr_data;
#endif
}
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0)
memset(&ife->map, 0, sizeof(struct ifmap));
else
memcpy(&ife->map,&ifr.ifr_map,sizeof(struct ifmap));
memcpy(&ife->map, &ifr.ifr_map, sizeof(struct ifmap));
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0)
......@@ -429,8 +425,8 @@ if_fetch(char *ifname, struct interface *ife)
if (fd >= 0) {
strcpy(ifr.ifr_name, ifname);
if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
ife->ddpaddr=ifr.ifr_addr;
ife->has_ddp=1;
ife->ddpaddr = ifr.ifr_addr;
ife->has_ddp = 1;
}
}
#endif
......@@ -441,23 +437,23 @@ if_fetch(char *ifname, struct interface *ife)
if (fd >= 0) {
strcpy(ifr.ifr_name, ifname);
if (!ipx_getaddr(fd, IPX_FRAME_ETHERII, &ifr)) {
ife->has_ipx_bb=1;
ife->ipxaddr_bb=ifr.ifr_addr;
ife->has_ipx_bb = 1;
ife->ipxaddr_bb = ifr.ifr_addr;
}
strcpy(ifr.ifr_name, ifname);
if (!ipx_getaddr(fd, IPX_FRAME_SNAP, &ifr)) {
ife->has_ipx_sn=1;
ife->ipxaddr_sn=ifr.ifr_addr;
ife->has_ipx_sn = 1;
ife->ipxaddr_sn = ifr.ifr_addr;
}
strcpy(ifr.ifr_name, ifname);
if(!ipx_getaddr(fd, IPX_FRAME_8023, &ifr)) {
ife->has_ipx_e3=1;
ife->ipxaddr_e3=ifr.ifr_addr;
if (!ipx_getaddr(fd, IPX_FRAME_8023, &ifr)) {
ife->has_ipx_e3 = 1;
ife->ipxaddr_e3 = ifr.ifr_addr;
}
strcpy(ifr.ifr_name, ifname);
if(!ipx_getaddr(fd, IPX_FRAME_8022, &ifr)) {
ife->has_ipx_e2=1;
ife->ipxaddr_e2=ifr.ifr_addr;
if (!ipx_getaddr(fd, IPX_FRAME_8022, &ifr)) {
ife->has_ipx_e2 = 1;
ife->ipxaddr_e2 = ifr.ifr_addr;
}
}
#endif
......
struct user_net_device_stats
{
struct user_net_device_stats {
unsigned long rx_packets; /* total packets received */
unsigned long tx_packets; /* total packets transmitted */
unsigned long rx_bytes; /* total bytes received */
......@@ -83,5 +82,5 @@ extern int if_readlist(void);
#define HAVE_DYNAMIC
#ifndef IFF_DYNAMIC
#define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses*/
#define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses */
#endif
......@@ -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)
......
......@@ -7,7 +7,7 @@
* 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
......@@ -45,8 +45,7 @@ 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;
......@@ -67,12 +66,12 @@ int activate_ld(const char *hwname, int fd)
hw = get_hwtype(hwname);
if (!hw) {
fprintf(stderr,_("Hardware type `%s' not supported.\n"),hwname);
return(E_NOSUPP);
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);
fprintf(stderr, _("Cannot change line discipline to `%s'.\n"), hw->name);
return (E_OPTERR);
}
return(hw->activate(fd));
return (hw->activate(fd));
}
......@@ -2,7 +2,7 @@
* 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
......@@ -41,23 +41,50 @@ 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}
} 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;
......@@ -71,7 +98,8 @@ extern struct aftype ec_aftype;
static short sVafinit = 0;
struct aftype *aftypes[] = {
struct aftype *aftypes[] =
{
#if HAVE_AFUNIX
&unix_aftype,
#endif
......@@ -100,7 +128,7 @@ struct aftype *aftypes[] = {
NULL
};
void afinit ()
void afinit()
{
unspec_aftype.title = _("UNSPEC");
#if HAVE_AFINET
......@@ -131,8 +159,7 @@ void afinit ()
}
/* set the default AF list from the program name or a constant value */
void
aftrans_def(char *tool, char *argv0, char *dflt)
void aftrans_def(char *tool, char *argv0, char *dflt)
{
char *tmp;
char *buf;
......@@ -151,18 +178,17 @@ aftrans_def(char *tool, char *argv0, char *dflt)
free(buf);
return;
}
tmp = buf+(strlen(tmp)-strlen(tool));
tmp = buf + (strlen(tmp) - strlen(tool));
if (strcmp(tmp, tool)!=0) {
if (strcmp(tmp, tool) != 0) {
free(buf);
return;
}
*tmp = '\0';
if ((tmp = strchr(buf,'_')))
if ((tmp = strchr(buf, '_')))
*tmp = '\0';
afname[0]='\0';
afname[0] = '\0';
if (aftrans_opt(buf))
strcpy(afname, buf);
......@@ -171,54 +197,54 @@ aftrans_def(char *tool, char *argv0, char *dflt)
/* 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 ();
afinit();
afp = aftypes;
while (*afp != NULL) {
if (!strcmp((*afp)->name, name)) return(*afp);
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 ();
afinit();
afp = aftypes;
while (*afp != NULL) {
if ((*afp)->af == af) return(*afp);
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 ();
afinit();
afp = aftypes;
while (*afp != NULL) {
if ((*afp)->af == af) return (*afp)->fd;
if ((*afp)->af == af)
return (*afp)->fd;
afp++;
}
return -1;
......@@ -230,39 +256,39 @@ int aftrans_opt(const char *arg)
char *tmp1, *tmp2;
char buf[256];
strncpy(buf,arg,sizeof(buf));
buf[sizeof(buf)-1]='\0';
strncpy(buf, arg, sizeof(buf));
buf[sizeof(buf) - 1] = '\0';
tmp1=buf;
tmp1 = buf;
while(tmp1) {
while (tmp1) {
tmp2=index(tmp1,',');
tmp2 = index(tmp1, ',');
if (tmp2)
*(tmp2++)='\0';
*(tmp2++) = '\0';
paft=aftrans;
for(paft=aftrans;paft->alias;paft++) {
if (strcmp(tmp1,paft->alias))
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 (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);
strcat(afname, ",");
strcat(afname, paft->name);
break;
}
if (!paft->alias) {
fprintf(stderr,_("Unknown address family `%s'.\n"),tmp1);
return(1);
fprintf(stderr, _("Unknown address family `%s'.\n"), tmp1);
return (1);
}
tmp1=tmp2;
tmp1 = tmp2;
}
return(0);
return (0);
}
......@@ -2,7 +2,7 @@
* 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
......@@ -34,31 +34,28 @@ 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];
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];
if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return strncpy (buf, _("[NONE SET]"), sizeof (buf));
return(pr_arcnet(sap->sa_data));
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;
......@@ -69,30 +66,36 @@ in_arcnet(char *bufp, struct sockaddr *sap)
i = 0;
orig = bufp;
while((*bufp != '\0') && (i < 1)) {
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;
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);
#endif
errno = EINVAL;
return(-1);
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;
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);
#endif
errno = EINVAL;
return(-1);
return (-1);
}
*ptr++ = (unsigned char) (val & 0377);
i++;
......@@ -115,20 +118,20 @@ in_arcnet(char *bufp, struct sockaddr *sap)
#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));
#endif
return(0);
return (0);
}
struct hwtype arcnet_hwtype = {
"arcnet", NULL, /*"2.5Mbps ARCnet",*/ ARPHRD_ARCNET, 1,
struct hwtype arcnet_hwtype =
{
"arcnet", NULL, /*"2.5Mbps ARCnet", */ ARPHRD_ARCNET, 1,
pr_arcnet, pr_sarcnet, in_arcnet, NULL
};
......
/*
* 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,16 +30,16 @@
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++;
p[0] = '[';
p++;
while (ptr[i] != 0xc9 && ptr[i] != 0xff && (i < ASH_ALEN))
sprintf (p++, "%1x", ptr[i++]);
sprintf(p++, "%1x", ptr[i++]);
*(p++) = ']';
*p = 0;
......@@ -46,14 +47,13 @@ pr_ash(unsigned char *ptr)
}
/* Display an Ash socket address. */
static char *
pr_sash(struct sockaddr *sap)
static char *pr_sash(struct sockaddr *sap)
{
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);
return strncpy(buf, "[NONE SET]", 64);
return pr_ash(sap->sa_data);
}
static unsigned char hamming[16] =
......@@ -63,8 +63,7 @@ static unsigned char hamming[16] =
};
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;
......@@ -74,7 +73,7 @@ in_ash(char *bufp, struct sockaddr *sap)
while (bufp && i < ASH_ALEN) {
char *next;
int hop = strtol (bufp, &next, 16);
int hop = strtol(bufp, &next, 16);
ptr[i++] = hamming[hop];
switch (*next) {
case ':':
......@@ -84,8 +83,8 @@ in_ash(char *bufp, struct sockaddr *sap)
bufp = NULL;
break;
default:
fprintf (stderr, _("Malformed Ash address"));
memset (ptr, 0xc9, ASH_ALEN);
fprintf(stderr, _("Malformed Ash address"));
memset(ptr, 0xc9, ASH_ALEN);
return -1;
}
}
......@@ -97,7 +96,8 @@ in_ash(char *bufp, struct sockaddr *sap)
}
struct hwtype ash_hwtype = {
struct hwtype ash_hwtype =
{
"ash", NULL, ARPHRD_ASH, ASH_ALEN,
pr_ash, pr_sash, in_ash, NULL
};
......
/*
* lib/ax25.c This file contains an implementation of the "AX.25"
* support functions for the NET-2 base distribution.
* 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
......@@ -44,62 +44,62 @@
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;
for (i = 0; i < 6; i++) {
buff[i] = ((ptr[i] & 0377) >> 1);
if (buff[i] == ' ') buff[i] = '\0';
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 (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];
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));
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;
sap->sa_family = ax25_aftype.af;
ptr = ((struct sockaddr_ax25 *)sap)->sax25_call.ax25_call;
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)) {
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);
#endif
errno = EINVAL;
return(-1);
return (-1);
}
*ptr++ = (unsigned char) ((c << 1) & 0xFE);
i++;
......@@ -112,11 +112,10 @@ AX25_input(int type, char *bufp, struct sockaddr *sap)
fprintf(stderr, "ax25_input(%s): %s !\n", AX25_errmsg, orig);
#endif
errno = E2BIG;
return(-1);
return (-1);
}
/* Nope, fill out the address bytes with blanks. */
while (i++ < sizeof(ax25_address)-1) {
while (i++ < sizeof(ax25_address) - 1) {
*ptr++ = (unsigned char) ((' ' << 1) & 0xFE);
}
......@@ -136,68 +135,70 @@ AX25_input(int type, char *bufp, struct sockaddr *sap)
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];
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));
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);
if (AX25_input(0, bufp, sap) < 0)
return (-1);
sap->sa_family = ARPHRD_AX25;
return(0);
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) {
fprintf(stderr, "KISS_set_disc(%d): %s\n", disc, strerror(errno));
return(-errno);
return (-errno);
}
return(0);
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,
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,
struct aftype ax25_aftype =
{
"ax25", NULL, /*"AMPR AX.25", */ AF_AX25, 7,
AX25_print, AX25_sprint, AX25_input, AX25_herror,
NULL, NULL, NULL,
-1,
......
......@@ -2,7 +2,7 @@
* 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
......@@ -38,25 +38,23 @@
int AX25_rprint(int options)
{
FILE *f=fopen(_PATH_PROCNET_AX25_ROUTE, "r");
FILE *f = fopen(_PATH_PROCNET_AX25_ROUTE, "r");
char buffer[256];
int use;
if(f==NULL)
{
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);
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);
buffer, buffer + 10, use);
}
fclose(f);
return 0;
......
......@@ -4,6 +4,8 @@
*
* Alan Cox <Alan.Cox@linux.org>
*
* $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
......@@ -29,32 +31,31 @@
#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);
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];
if (sap->sa_family != AF_APPLETALK)
return strncpy (buf, _("[NONE SET]"), sizeof (buf));
return(ddp_print(sap->sa_data));
return strncpy(buf, _("[NONE SET]"), sizeof(buf));
return (ddp_print(sap->sa_data));
}
struct aftype ddp_aftype = {
"ddp", NULL, /*"Appletalk DDP",*/ AF_APPLETALK, 0,
struct aftype ddp_aftype =
{
"ddp", NULL, /*"Appletalk DDP", */ AF_APPLETALK, 0,
ddp_print, ddp_sprint, NULL, NULL,
NULL/*DDP_rprint*/, NULL, NULL,
NULL /*DDP_rprint */ , NULL, NULL,
-1,
"/proc/net/appletalk"
};
......
......@@ -19,6 +19,6 @@
int DDP_rprint(int options)
{
fprintf(stderr, _("Routing table for `ddp' not yet supported.\n"));
return(1);
return (1);
}
#endif
......@@ -3,7 +3,7 @@
* 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>
*
......@@ -33,34 +33,32 @@
/* 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);
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]");
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;
struct sockaddr_ec *sec = (struct sockaddr_ec *) sap;
int net, stn;
switch (sscanf(bufp, "%d.%d", &net, &stn))
{
switch (sscanf(bufp, "%d.%d", &net, &stn)) {
case 2:
sec->addr.station = stn;
sec->addr.net = net;
......@@ -75,7 +73,8 @@ ec_input(int type, char *bufp, struct sockaddr *sap)
return -1;
}
struct aftype ec_aftype = {
struct aftype ec_aftype =
{
"ec", NULL, AF_ECONET, 0,
ec_print, ec_sprint, ec_input, NULL,
NULL, NULL, NULL,
......
/*
* lib/ether.c This file contains an implementation of the "Ethernet"
* support functions for the NET-2 base distribution.
* 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
......@@ -34,8 +34,7 @@ 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];
......@@ -43,25 +42,23 @@ pr_ether(unsigned char *ptr)
(ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
(ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
);
return(buff);
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];
if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return strncpy (buf, _("[NONE SET]"), sizeof (buf));
return(pr_ether(sap->sa_data));
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;
......@@ -73,33 +70,41 @@ in_ether(char *bufp, struct sockaddr *sap)
i = 0;
orig = bufp;
while((*bufp != '\0') && (i < ETH_ALEN)) {
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;
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);
#endif
errno = EINVAL;
return(-1);
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;
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);
#endif
errno = EINVAL;
return(-1);
return (-1);
}
if (c != 0) bufp++;
if (c != 0)
bufp++;
*ptr++ = (unsigned char) (val & 0377);
i++;
......@@ -121,20 +126,20 @@ in_ether(char *bufp, struct sockaddr *sap)
#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));
#endif
return(0);
return (0);
}
struct hwtype ether_hwtype = {
"ether", NULL, /*"10Mbps Ethernet",*/ ARPHRD_ETHER, ETH_ALEN,
struct hwtype ether_hwtype =
{
"ether", NULL, /*"10Mbps Ethernet", */ ARPHRD_ETHER, ETH_ALEN,
pr_ether, pr_sether, in_ether, NULL
};
......
/*
* lib/fddi.c This file contains an implementation of the "FDDI"
* support functions for the NET-2 base distribution.
* 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>
*
......@@ -45,8 +45,7 @@ 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];
......@@ -54,25 +53,23 @@ pr_fddi(unsigned char *ptr)
(ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
(ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
);
return(buff);
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];
if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return strncpy (buf, _("[NONE SET]"), sizeof (buf));
return(pr_fddi(sap->sa_data));
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;
......@@ -83,30 +80,36 @@ in_fddi(char *bufp, struct sockaddr *sap)
i = 0;
orig = bufp;
while((*bufp != '\0') && (i < FDDI_K_ALEN)) {
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;
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);
#endif
errno = EINVAL;
return(-1);
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;
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);
#endif
errno = EINVAL;
return(-1);
return (-1);
}
*ptr++ = (unsigned char) (val & 0377);
i++;
......@@ -129,20 +132,20 @@ in_fddi(char *bufp, struct sockaddr *sap)
#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));
#endif
return(0);
return (0);
}
struct hwtype fddi_hwtype = {
"fddi", NULL, /*"Fiber Distributed Data Interface (FDDI)",*/ ARPHRD_FDDI, FDDI_K_ALEN,
struct hwtype fddi_hwtype =
{
"fddi", NULL, /*"Fiber Distributed Data Interface (FDDI)", */ ARPHRD_FDDI, FDDI_K_ALEN,
pr_fddi, pr_sfddi, in_fddi, NULL
};
......
/*
* 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>
*
......@@ -41,17 +41,19 @@ char *pr_dlci(unsigned char *ptr)
{
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,
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,
struct hwtype frad_hwtype =
{
"frad", NULL, /*"Frame Relay Access Device", */ ARPHRD_FRAD, 0,
NULL, NULL, NULL, NULL
};
#endif /* HAVE_HWFR */
/*
* 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
......@@ -27,10 +27,10 @@
/* Split the input string into multiple fields. */
int
getargs(char *string, char *arguments[])
int getargs(char *string, char *arguments[])
{
char temp[1024];
int len = strlen(string);
char temp[len+1];
char *sp, *ptr;
int i, argc;
char want;
......@@ -39,7 +39,8 @@ getargs(char *string, char *arguments[])
* Copy the string into a buffer. We may have to modify
* the original string because of all the quoting...
*/
sp = string; i = 0;
sp = string;
i = 0;
strcpy(temp, string);
ptr = temp;
......@@ -49,7 +50,8 @@ getargs(char *string, char *arguments[])
*/
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;
......@@ -62,7 +64,7 @@ getargs(char *string, char *arguments[])
* as it if was not there.
*/
want = *ptr++;
while(*ptr != '\0') {
while (*ptr != '\0') {
if (*ptr == want && *(ptr - 1) != '\\') {
ptr++;
break;
......@@ -71,17 +73,19 @@ getargs(char *string, char *arguments[])
}
} else {
/* Just copy the string up to any whitespace. */
while(*ptr != '\0' && *ptr != ' ' && *ptr != '\t')
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);
while (i < 32)
arguments[i++] = (char *) NULL;
return (argc);
}
......@@ -7,7 +7,7 @@
* 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
......@@ -46,8 +46,7 @@ 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;
......@@ -69,49 +68,46 @@ getroute_init(void)
#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 *tmp1, *tmp2;
int found = E_NOTFOUND, rc;
char buf[256];
strncpy(buf,afname,sizeof(buf));
buf[sizeof(buf)-1]='\0';
strncpy(buf, afname, sizeof(buf));
buf[sizeof(buf) - 1] = '\0';
tmp1=buf;
tmp1 = buf;
while(tmp1) {
while (tmp1) {
ap=NULL;
ap = NULL;
if ((tmp2=index(tmp1,',')))
*tmp2++='\0';
if ((tmp2 = index(tmp1, ',')))
*tmp2++ = '\0';
if (!tmp1[0]) {
tmp1=tmp2;
tmp1 = tmp2;
continue;
}
ap = get_aftype(tmp1);
if (!ap) {
fprintf(stderr,_("Address family `%s' not supported.\n"),tmp1);
return(E_OPTERR);
fprintf(stderr, _("Address family `%s' not supported.\n"), tmp1);
return (E_OPTERR);
}
tmp1=tmp2;
tmp1 = tmp2;
if (!ap->rprint) {
fprintf(stderr,_("No routing for address family `%s'.\n"),ap->name);
return(E_OPTERR);
fprintf(stderr, _("No routing for address family `%s'.\n"), ap->name);
return (E_OPTERR);
}
found = 0;
if ((rc = ap->rprint(options)))
return(rc);
return (rc);
}
return(found);
return (found);
}
......@@ -3,7 +3,7 @@
* 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>
......@@ -36,12 +36,14 @@
#include "net-support.h"
#include "pathnames.h"
struct hwtype hdlc_hwtype = {
"hdlc", NULL, /*"(Cisco) HDLC",*/ ARPHRD_HDLC, 0,
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,
struct hwtype lapb_hwtype =
{
"lapb", NULL, /*"LAPB", */ ARPHRD_LAPB, 0,
NULL, NULL, NULL, NULL,
};
......
......@@ -2,7 +2,7 @@
* 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
......@@ -45,8 +45,7 @@ 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];
......@@ -54,25 +53,24 @@ pr_hippi(unsigned char *ptr)
(ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
(ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
);
return(buff);
return (buff);
}
/* Display an HIPPI socket address. */
static char *
pr_shippi(struct sockaddr *sap)
pr_shippi(struct sockaddr *sap)
{
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));
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;
......@@ -83,30 +81,36 @@ in_hippi(char *bufp, struct sockaddr *sap)
i = 0;
orig = bufp;
while((*bufp != '\0') && (i < HIPPI_ALEN)) {
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;
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);
#endif
errno = EINVAL;
return(-1);
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;
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);
#endif
errno = EINVAL;
return(-1);
return (-1);
}
*ptr++ = (unsigned char) (val & 0377);
i++;
......@@ -128,20 +132,20 @@ in_hippi(char *bufp, struct sockaddr *sap)
#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));
#endif
return(0);
return (0);
}
struct hwtype hippi_hwtype = {
"hippi", NULL, /*"HIPPI",*/ ARPHRD_HIPPI, HIPPI_ALEN,
struct hwtype hippi_hwtype =
{
"hippi", NULL, /*"HIPPI", */ ARPHRD_HIPPI, HIPPI_ALEN,
pr_hippi, pr_shippi, in_hippi, NULL
};
......
/*
* lib/hw.c This file contains the top-level part of the hardware
* support functions module for the NET-2 base distribution.
* 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>
*
......@@ -63,7 +63,8 @@ extern struct hwtype lapb_hwtype;
extern struct hwtype sit_hwtype;
static struct hwtype *hwtypes[] = {
static struct hwtype *hwtypes[] =
{
&loop_hwtype,
......@@ -124,7 +125,7 @@ static struct hwtype *hwtypes[] = {
static short sVhwinit = 0;
void hwinit ()
void hwinit()
{
loop_hwtype.title = _("Local Loopback");
unspec_hwtype.title = _("UNSPEC");
......@@ -180,8 +181,7 @@ void hwinit ()
}
/* 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;
......@@ -190,16 +190,16 @@ get_hwtype(const char *name)
hwp = hwtypes;
while (*hwp != NULL) {
if (!strcmp((*hwp)->name, name)) return(*hwp);
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;
......@@ -208,8 +208,9 @@ get_hwntype(int type)
hwp = hwtypes;
while (*hwp != NULL) {
if ((*hwp)->type == type) return(*hwp);
if ((*hwp)->type == type)
return (*hwp);
hwp++;
}
return(NULL);
return (NULL);
}
......@@ -3,7 +3,7 @@
* 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
......@@ -57,16 +57,13 @@ struct service {
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 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;
......@@ -78,27 +75,24 @@ INET_resolve(char *name, struct sockaddr_in *sin)
/* Default is special, meaning 0.0.0.0. */
if (!strcmp(name, "default")) {
sin->sin_addr.s_addr = INADDR_ANY;
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) {
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;
#endif
if ((hp = gethostbyname(name)) == (struct hostent *)NULL) {
if ((hp = gethostbyname(name)) == (struct hostent *) NULL) {
errno = h_errno;
return -1;
}
......@@ -108,8 +102,7 @@ INET_resolve(char *name, struct sockaddr_in *sin)
}
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;
......@@ -122,22 +115,22 @@ INET_rresolve(char *name, struct sockaddr_in *sin, int numeric)
fprintf(stderr, _("rresolve: unsupport address family %d !\n"), sin->sin_family);
#endif
errno = EAFNOSUPPORT;
return(-1);
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);
strcpy(name, inet_ntoa(sin->sin_addr));
return (0);
}
#if 0
INET_nn = NULL;
#endif
......@@ -145,7 +138,7 @@ INET_rresolve(char *name, struct sockaddr_in *sin, int numeric)
while (pn != NULL) {
if (pn->addr.sin_addr.s_addr == ad) {
strcpy(name, pn->name);
return(0);
return (0);
}
pn = pn->next;
}
......@@ -164,52 +157,48 @@ INET_rresolve(char *name, struct sockaddr_in *sin, int numeric)
}
}
if ((ent == NULL) && (np == NULL)) {
strcpy(name,inet_ntoa (sin->sin_addr));
strcpy(name, inet_ntoa(sin->sin_addr));
}
pn = (struct addr *)malloc(sizeof(struct 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);
return (0);
}
static void
INET_reserror(char *text)
static void INET_reserror(char *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];
if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return strncpy (buff, _("[NONE SET]"), sizeof(buff));
return strncpy(buff, _("[NONE SET]"), sizeof(buff));
if (INET_rresolve(buff, (struct sockaddr_in *) sap, numeric) != 0)
return(NULL);
return(buff);
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;
char *sp = bufp, *bp;
unsigned int i;
unsigned val;
struct sockaddr_in *sin;
......@@ -219,7 +208,7 @@ INET_getsock(char *bufp, struct sockaddr *sap)
sin->sin_port = 0;
val = 0;
bp=(char *)&val;
bp = (char *) &val;
for (i = 0; i < sizeof(sin->sin_addr.s_addr); i++) {
*sp = toupper(*sp);
......@@ -228,7 +217,7 @@ INET_getsock(char *bufp, struct sockaddr *sap)
else if ((*sp >= '0') && (*sp <= '9'))
bp[i] |= (int) (*sp - '0');
else
return(-1);
return (-1);
bp[i] <<= 4;
sp++;
......@@ -239,29 +228,28 @@ INET_getsock(char *bufp, struct sockaddr *sap)
else if ((*sp >= '0') && (*sp <= '9'))
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) {
switch (type) {
case 1:
return(INET_getsock(bufp,sap));
return (INET_getsock(bufp, sap));
default:
return(INET_resolve(bufp, (struct sockaddr_in *) sap));
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;
struct sockaddr_in *mask = (struct sockaddr_in *) m;
char *slash, *end;
int prefix;
......@@ -269,24 +257,24 @@ static int INET_getnetmask(char *adr, struct sockaddr *m, char *name)
return 0;
*slash++ = '\0';
prefix = strtoul(slash,&end,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),
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*/,
NULL /*INET_rprint */ , NULL /*INET_rinput */ ,
INET_getnetmask,
-1,
NULL
......@@ -296,8 +284,7 @@ struct aftype inet_aftype = {
#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) {
*namebase = item;
......@@ -309,76 +296,76 @@ add2list(struct service **namebase, struct service *item)
}
static struct service *
searchlist(struct service *servicebase, int number)
static struct service *searchlist(struct service *servicebase, int number)
{
struct service *item;
for(item = servicebase; item != NULL; item = item->next) {
if (item->number == number) return(item);
for (item = servicebase; item != NULL; item = item->next) {
if (item->number == number)
return (item);
}
return(NULL);
return (NULL);
}
static int
read_services(void)
static int read_services(void)
{
struct servent *se;
struct service *item;
setservent(1);
while((se=getservent())) {
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);
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;
static char buffer[64], init = 0;
struct service *item;
if (socknumber == 0) return("*");
if (socknumber == 0)
return ("*");
if (numeric) {
sprintf(buffer, "%d", ntohs(socknumber));
return(buffer);
return (buffer);
}
if (!init) {
(void)read_services();
init=1;
(void) read_services();
init = 1;
}
buffer[0]='\0';
if (! strcmp(proto, "tcp")) {
buffer[0] = '\0';
if (!strcmp(proto, "tcp")) {
if ((item = searchlist(tcp_name, socknumber)) != NULL)
sprintf(buffer, "%s", item->name);
} else if (! strcmp(proto, "udp")) {
} else if (!strcmp(proto, "udp")) {
if ((item = searchlist(udp_name, socknumber)) != NULL)
sprintf(buffer, "%s", item->name);
} else if (! strcmp(proto, "raw")) {
} else if (!strcmp(proto, "raw")) {
if ((item = searchlist(raw_name, socknumber)) != NULL)
sprintf(buffer, "%s", item->name);
}
if (!buffer[0])
sprintf(buffer, "%d", ntohs(socknumber));
return(buffer);
return (buffer);
}
#endif /* HAVE_AFINET || HAVE_AFINET6 */
......@@ -3,7 +3,7 @@
* 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
......@@ -42,8 +42,7 @@
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;
......@@ -53,17 +52,15 @@ INET6_resolve(char *name, struct sockaddr_in6 *sin6)
fprintf(stderr, "getaddrinfo: %s: %s\n", name, gai_strerror(s));
return -1;
}
memcpy(sin6, ai->ai_addr, sizeof(struct sockaddr_in6));
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;
......@@ -74,59 +71,52 @@ INET6_rresolve(char *name, struct sockaddr_in6 *sin6, int numeric)
sin6->sin6_family);
#endif
errno = EAFNOSUPPORT;
return(-1);
return (-1);
}
if (numeric & 0x7FFF) {
inet_ntop(AF_INET6, &sin6->sin6_addr, name, 80);
return(0);
return (0);
}
if ((s = getnameinfo((struct sockaddr *)sin6, sizeof(struct sockaddr_in6),
name, 255 /* !! */, NULL, 0, 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 (0);
}
static void
INET6_reserror(char *text)
static void INET6_reserror(char *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];
inet_ntop(AF_INET6, (struct in6_addr *)ptr, name, 80);
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];
if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return strncpy (buff, _("[NONE SET]"), sizeof (buff));
return strncpy(buff, _("[NONE SET]"), sizeof(buff));
if (INET6_rresolve(buff, (struct sockaddr_in6 *) sap, numeric) != 0)
return(NULL);
return(buff);
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;
......@@ -135,25 +125,25 @@ INET6_getsock(char *bufp, struct sockaddr *sap)
sin6->sin6_port = 0;
if (inet_pton(AF_INET6, bufp, sin6->sin6_addr.s6_addr) <= 0)
return(-1);
return (-1);
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) {
switch (type) {
case 1:
return(INET6_getsock(bufp, sap));
return (INET6_getsock(bufp, sap));
default:
return(INET6_resolve(bufp, (struct sockaddr_in6 *) sap));
return (INET6_resolve(bufp, (struct sockaddr_in6 *) sap));
}
}
struct aftype inet6_aftype = {
"inet6", NULL, /*"IPv6",*/ AF_INET6, sizeof(struct in6_addr),
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,
......
......@@ -2,7 +2,7 @@
Modifications:
1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets,
snprintf instead of sprintf
*/
*/
#include "config.h"
......@@ -70,22 +70,20 @@ int rprint_fib6(int ext, int numeric)
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");
FILE *fp = fopen(_PATH_PROCNET_ROUTE6, "r");
char addr6p[8][5], saddr6p[8][5], naddr6p[8][5];
if (!fp) {
ESYSNOT("getroute","INET6 FIB");
ESYSNOT("getroute", "INET6 FIB");
return 1;
}
printf(_("Kernel IPv6 routing table\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,33 +95,40 @@ 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);
inet6_aftype.input(1, addr6, (struct sockaddr *) &saddr6);
snprintf(addr6, sizeof(addr6), "%s/%d",
inet6_aftype.sprint((struct sockaddr *)&saddr6, 1),
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);
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",
......@@ -131,7 +136,7 @@ int rprint_fib6(int ext, int numeric)
}
(void) fclose(fp);
return(0);
return (0);
}
int rprint_cache6(int ext, int numeric)
......@@ -139,16 +144,15 @@ 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");
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");
ESYSNOT("nd_print", "ND Table");
return 1;
}
printf(_("Kernel IPv6 Neighbour Cache\n"));
if (ext == 2)
......@@ -161,8 +165,7 @@ int rprint_cache6(int ext, int numeric)
"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],
......@@ -174,52 +177,58 @@ int rprint_cache6(int ext, int numeric)
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);
inet6_aftype.input(1, addr6, (struct sockaddr *) &saddr6);
snprintf(addr6, sizeof(addr6), "%s/%d",
inet6_aftype.sprint((struct sockaddr *)&saddr6, numeric),
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");
strcpy(statestr, "NONE");
break;
case NUD_INCOMPLETE:
strcpy(statestr,"INCOMPLETE");
strcpy(statestr, "INCOMPLETE");
break;
case NUD_REACHABLE:
strcpy(statestr,"REACHABLE");
strcpy(statestr, "REACHABLE");
break;
case NUD_STALE:
strcpy(statestr,"STALE");
strcpy(statestr, "STALE");
break;
case NUD_DELAY:
strcpy(statestr,"DELAY");
strcpy(statestr, "DELAY");
break;
case NUD_PROBE:
strcpy(statestr,"PROBE");
strcpy(statestr, "PROBE");
break;
case NUD_FAILED:
strcpy(statestr,"FAILED");
strcpy(statestr, "FAILED");
break;
case NUD_IN_TIMER:
strcpy(statestr,"IN TIMER");
strcpy(statestr, "IN TIMER");
break;
default:
snprintf(statestr,sizeof (statestr),"UNKNOWN %02x",state);
snprintf(statestr, sizeof(statestr), "UNKNOWN %02x", state);
break;
}
......@@ -227,38 +236,38 @@ int rprint_cache6(int ext, int numeric)
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);
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(" %-7ld ", delete / HZ);
}
printf("\n");
}
(void) fclose(fp);
return(0);
return (0);
}
int INET6_rprint(int options)
{
int ext = options & FLAG_EXT;
int numeric = options & (FLAG_NUM|FLAG_SYM);
int numeric = options & (FLAG_NUM | FLAG_SYM);
int rc = E_INTERN;
if (options & FLAG_FIB)
if ((rc = rprint_fib6(ext,numeric)))
return(rc);
if ((rc = rprint_fib6(ext, numeric)))
return (rc);
if (options & FLAG_CACHE)
if ((rc = rprint_cache6(ext,numeric)))
return(rc);
return(rc);
if ((rc = rprint_cache6(ext, numeric)))
return (rc);
return (rc);
}
#endif /* HAVE_AFINET6 */
/*
Modifications:
1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets
*/
*/
#include "config.h"
......@@ -40,10 +40,10 @@ 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);
}
......@@ -58,12 +58,13 @@ static int INET6_setroute(int action, int options, char **args)
char *cp;
if (*args == NULL)
return(usage());
return (usage());
strcpy(target, *args++);
if ((cp = strchr(target, '/'))) {
prefix_len = atol(cp+1);
if ((prefix_len < 0) || (prefix_len > 128)) usage();
prefix_len = atol(cp + 1);
if ((prefix_len < 0) || (prefix_len > 128))
usage();
*cp = 0;
} else {
prefix_len = 128;
......@@ -72,7 +73,7 @@ static int INET6_setroute(int action, int options, char **args)
/* Clean out the RTREQ structure. */
memset((char *) &rt, 0, sizeof(struct in6_rtmsg));
if (inet6_aftype.input(1, target, (struct sockaddr *)&sa6) < 0) {
if (inet6_aftype.input(1, target, (struct sockaddr *) &sa6) < 0) {
inet6_aftype.herror(target);
return (1);
}
......@@ -90,21 +91,21 @@ static int INET6_setroute(int action, int options, char **args)
args++;
if (!*args || !isdigit(**args))
return(usage());
return (usage());
metric = atoi(*args);
rt.rtmsg_metric = metric;
args++;
continue;
}
if (!strcmp(*args,"gw") || !strcmp(*args,"gateway")) {
if (!strcmp(*args, "gw") || !strcmp(*args, "gateway")) {
args++;
if (!*args)
return(usage());
return (usage());
if (rt.rtmsg_flags & RTF_GATEWAY)
return(usage());
return (usage());
strcpy(gateway, *args);
if (inet6_aftype.input(1, gateway,
(struct sockaddr *)&sa6) < 0) {
(struct sockaddr *) &sa6) < 0) {
inet6_aftype.herror(gateway);
return (E_LOOKUP);
}
......@@ -114,23 +115,22 @@ static int INET6_setroute(int action, int options, char **args)
args++;
continue;
}
if (!strcmp(*args,"mod")) {
if (!strcmp(*args, "mod")) {
args++;
rt.rtmsg_flags |= RTF_MODIFIED;
continue;
}
if (!strcmp(*args,"dyn")) {
if (!strcmp(*args, "dyn")) {
args++;
rt.rtmsg_flags |= RTF_DYNAMIC;
continue;
}
if (!strcmp(*args,"device") || !strcmp(*args,"dev")) {
if (!strcmp(*args, "device") || !strcmp(*args, "dev")) {
args++;
if (!*args)
return(usage());
} else
if (args[1])
return(usage());
return (usage());
} else if (args[1])
return (usage());
devname = *args;
args++;
......@@ -139,52 +139,49 @@ static int INET6_setroute(int action, int options, char **args)
/* Create a socket to the INET6 kernel. */
if ((skfd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
perror("socket");
return(E_SOCK);
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);
return (E_SOCK);
}
rt.rtmsg_ifindex = ifr.ifr_ifindex;
}
else
} else
rt.rtmsg_ifindex = 0;
/* Tell the kernel to accept this route. */
if (action==RTACTION_DEL) {
if (action == RTACTION_DEL) {
if (ioctl(skfd, SIOCDELRT, &rt) < 0) {
perror("SIOCDELRT");
close(skfd);
return(E_SOCK);
return (E_SOCK);
}
} else {
if (ioctl(skfd, SIOCADDRT, &rt) < 0) {
perror("SIOCADDRT");
close(skfd);
return(E_SOCK);
return (E_SOCK);
}
}
/* Close the socket. */
(void) close(skfd);
return(0);
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());
fprintf(stderr, _("Flushing `inet6' routing table not supported\n"));
return (usage());
}
if ((*args == NULL) || (action == RTACTION_HELP))
return(usage());
return (usage());
return(INET6_setroute(action, options, args));
return (INET6_setroute(action, options, args));
}
#endif /* HAVE_AFINET6 */
/*
$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"
......@@ -37,14 +39,13 @@ int rprint_fib(int ext, int numeric)
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");
FILE *fp = fopen(_PATH_PROCNET_ROUTE, "r");
char *fmt;
if (!fp) {
ESYSNOT("getroute","INET FIB");
ESYSNOT("getroute", "INET FIB");
return 1;
}
printf(_("Kernel IP routing table\n"));
if (ext == 1)
......@@ -58,9 +59,9 @@ int rprint_fib(int ext, int numeric)
"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",
......@@ -80,39 +81,45 @@ int rprint_fib(int ext, int numeric)
if (!fmt)
return 1;
while (fgets(buff, 1023, fp))
{
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;
&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
......@@ -151,7 +158,7 @@ int rprint_fib(int ext, int numeric)
free(fmt);
(void) fclose(fp);
return(0);
return (0);
}
int rprint_cache(int ext, int numeric)
......@@ -163,13 +170,12 @@ int rprint_cache(int ext, int numeric)
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");
ESYSNOT("getroute", "INET CACHE");
return 1;
}
if (ext == 1)
printf(_("Destination Gateway Source "
"Flags Metric Ref Use Iface\n"));
......@@ -196,45 +202,52 @@ int rprint_cache(int ext, int numeric)
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;
&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
......@@ -273,22 +286,22 @@ int rprint_cache(int ext, int numeric)
free(fmt);
(void) fclose(fp);
return(0);
return (0);
}
int INET_rprint(int options)
{
int ext = options & FLAG_EXT;
int numeric = options & (FLAG_NUM|FLAG_SYM);
int numeric = options & (FLAG_NUM | FLAG_SYM);
int rc = E_INTERN;
if (options & FLAG_FIB)
if ((rc = rprint_fib(ext,numeric)))
return(rc);
if ((rc = rprint_fib(ext, numeric)))
return (rc);
if (options & FLAG_CACHE)
rc = rprint_cache(ext,numeric);
rc = rprint_cache(ext, numeric);
return(rc);
return (rc);
}
#endif /* HAVE_AFINET */
This diff is collapsed.
......@@ -41,61 +41,58 @@
#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);
struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) (ptr - 2);
int t;
for(t=IPX_NODE_LEN;t;t--)
if (sipx->sipx_node[t-1])
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]);
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));
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]);
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);
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];
if (sap->sa_family != AF_IPX)
return strncpy (buf, _("[NONE SET]"), sizeof (buf));
return(IPX_print(sap->sa_data));
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;
char *sp = bufp, *bp;
unsigned int i;
unsigned char val;
struct sockaddr_ipx *sipx=(struct sockaddr_ipx *) sap;
struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) sap;
sipx->sipx_port = 0;
val = 0;
bp=(char *)sipx->sipx_node;
bp = (char *) sipx->sipx_node;
for (i = 0; i < sizeof(sipx->sipx_node); i++) {
*sp = toupper(*sp);
......@@ -104,7 +101,7 @@ IPX_getsock(char *bufp, struct sockaddr *sap)
else if ((*sp >= '0') && (*sp <= '9'))
bp[i] |= (int) (*sp - '0');
else
return(-1);
return (-1);
bp[i] <<= 4;
sp++;
......@@ -115,23 +112,22 @@ IPX_getsock(char *bufp, struct sockaddr *sap)
else if ((*sp >= '0') && (*sp <= '9'))
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 (-1);
return(0);
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;
struct sockaddr_ipx *sai = (struct sockaddr_ipx *) sap;
unsigned long netnum;
char *ep;
int nbo;
......@@ -149,9 +145,9 @@ IPX_input(int type, char *bufp, struct sockaddr *sap)
type &= 3;
if (type <= 1) {
netnum = strtoul(bufp,&ep,16);
netnum = strtoul(bufp, &ep, 16);
if ((netnum == 0xffffffffL) || (netnum == 0L))
return(-1);
return (-1);
if (nbo)
sai->sipx_network = netnum;
else
......@@ -159,22 +155,23 @@ IPX_input(int type, char *bufp, struct sockaddr *sap)
}
if (type == 1) {
if (*ep != '\0')
return(-2);
return(0);
return (-2);
return (0);
}
if (type == 0) {
if (*ep != ':')
return(-3);
bufp=ep+1;
return (-3);
bufp = ep + 1;
}
return(IPX_getsock(bufp,sap));
return (IPX_getsock(bufp, sap));
}
struct aftype ipx_aftype = {
"ipx", NULL, /*"IPX",*/ AF_IPX, 0,
struct aftype ipx_aftype =
{
"ipx", NULL, /*"IPX", */ AF_IPX, 0,
IPX_print, IPX_sprint, IPX_input, NULL,
NULL/*IPX_rprint*/, NULL, NULL,
NULL /*IPX_rprint */ , NULL, NULL,
-1,
"/proc/net/ipx"
};
......
......@@ -3,7 +3,7 @@
Modifications:
1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets,
snprintf instead of sprintf
*/
*/
#include "config.h"
......@@ -45,41 +45,39 @@ int IPX_rprint(int options)
printf(_("Kernel IPX routing table\n")); /* xxx */
if ((ap = get_afntype(AF_IPX)) == NULL) {
EINTERN("lib/ipx_rt.c","AF_IPX missing");
return(-1);
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) {
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;
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);
return (0);
}
#endif /* HAVE_AFIPX */
......@@ -27,19 +27,10 @@ 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 */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -2,7 +2,7 @@
* 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
*
......@@ -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 */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment