Remove duplicate definitions, run through indent

This commit is contained in:
Glenn L McGrath 2002-08-22 19:35:36 +00:00
parent 4534af2763
commit 1ed9dd9d06

View File

@ -15,7 +15,7 @@
* that either displays or sets the characteristics of
* one or more of the system's networking interfaces.
*
* Version: $Id: interface.c,v 1.8 2002/07/03 11:46:36 andersen Exp $
* Version: $Id: interface.c,v 1.9 2002/08/22 19:35:36 bug1 Exp $
*
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
* and others. Copyright 1993 MicroWalt Corporation
@ -159,11 +159,10 @@ struct aftype {
char *flag_file;
};
static struct aftype *aftypes[];
#ifdef KEEP_UNUSED
static int flag_unx;
#ifdef HAVE_AFIPX
static int flag_ipx;
#endif
@ -177,6 +176,7 @@ static int flag_ddp;
static int flag_netrom;
#endif
static int flag_inet;
#ifdef HAVE_AFINET6
static int flag_inet6;
#endif
@ -199,69 +199,53 @@ static struct aftrans_t {
#ifdef HAVE_AFX25
{
"ax25", "ax25", &flag_ax25
},
"ax25", "ax25", &flag_ax25},
#endif
{
"ip", "inet", &flag_inet
},
"ip", "inet", &flag_inet},
#ifdef HAVE_AFINET6
{
"ip6", "inet6", &flag_inet6
},
"ip6", "inet6", &flag_inet6},
#endif
#ifdef HAVE_AFIPX
{
"ipx", "ipx", &flag_ipx
},
"ipx", "ipx", &flag_ipx},
#endif
#ifdef HAVE_AFATALK
{
"appletalk", "ddp", &flag_ddp
},
"appletalk", "ddp", &flag_ddp},
#endif
#ifdef HAVE_AFNETROM
{
"netrom", "netrom", &flag_netrom
},
"netrom", "netrom", &flag_netrom},
#endif
{
"inet", "inet", &flag_inet
},
"inet", "inet", &flag_inet},
#ifdef HAVE_AFINET6
{
"inet6", "inet6", &flag_inet6
},
"inet6", "inet6", &flag_inet6},
#endif
#ifdef HAVE_AFATALK
{
"ddp", "ddp", &flag_ddp
},
"ddp", "ddp", &flag_ddp},
#endif
{
"unix", "unix", &flag_unx
},
{
"tcpip", "inet", &flag_inet
},
"unix", "unix", &flag_unx}, {
"tcpip", "inet", &flag_inet},
#ifdef HAVE_AFECONET
{
"econet", "ec", &flag_econet
},
"econet", "ec", &flag_econet},
#endif
#ifdef HAVE_AFX25
{
"x25", "x25", &flag_x25
},
"x25", "x25", &flag_x25},
#endif
#ifdef HAVE_AFASH
{
"ash", "ash", &flag_ash
},
"ash", "ash", &flag_ash},
#endif
{
0, 0, 0
}
0, 0, 0}
};
static char afname[256] = "";
@ -287,8 +271,7 @@ static char *UNIX_sprint(struct sockaddr *sap, int numeric)
}
static struct aftype unix_aftype =
{
static struct aftype unix_aftype = {
"unix", "UNIX Domain", AF_UNIX, 0,
UNIX_print, UNIX_sprint, NULL, NULL,
NULL, NULL, NULL,
@ -417,8 +400,7 @@ static int INET_getnetmask(char *adr, struct sockaddr *m, char *name)
}
#endif /* KEEP_UNUSED */
static struct aftype inet_aftype =
{
static struct aftype inet_aftype = {
"inet", "DARPA Internet", AF_INET, sizeof(unsigned long),
NULL /* UNUSED INET_print */ , INET_sprint,
NULL /* UNUSED INET_input */ , NULL /* UNUSED INET_reserror */ ,
@ -456,7 +438,8 @@ static char *INET6_sprint(struct sockaddr *sap, int numeric)
if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff));
if (INET6_rresolve(buff, sizeof(buff), (struct sockaddr_in6 *) sap, numeric) != 0)
if (INET6_rresolve
(buff, sizeof(buff), (struct sockaddr_in6 *) sap, numeric) != 0)
return safe_strncpy(buff, _("[UNKNOWN]"), sizeof(buff));
return (buff);
}
@ -487,8 +470,7 @@ static int INET6_input(int type, char *bufp, struct sockaddr *sap)
}
#endif /* KEEP_UNUSED */
static struct aftype inet6_aftype =
{
static struct aftype inet6_aftype = {
"inet6", "IPv6", AF_INET6, sizeof(struct in6_addr),
NULL /* UNUSED INET6_print */ , INET6_sprint,
NULL /* UNUSED INET6_input */ , NULL /* UNUSED INET6_reserror */ ,
@ -528,15 +510,13 @@ static char *UNSPEC_sprint(struct sockaddr *sap, int numeric)
return (UNSPEC_print(sap->sa_data));
}
static struct aftype unspec_aftype =
{
static struct aftype unspec_aftype = {
"unspec", "UNSPEC", AF_UNSPEC, 0,
UNSPEC_print, UNSPEC_sprint, NULL, NULL,
NULL,
};
static struct aftype *aftypes[] =
{
static struct aftype *aftypes[] = {
#if HAVE_AFUNIX
&unix_aftype,
#endif
@ -712,7 +692,8 @@ static struct aftype *get_aftype(const char *name)
afp++;
}
if (strchr(name, ','))
fprintf(stderr, _("Please don't supply more than one address family.\n"));
fprintf(stderr,
_("Please don't supply more than one address family.\n"));
return (NULL);
}
#endif /* KEEP_UNUSED */
@ -757,7 +738,8 @@ static int get_socket_for_af(int af)
#ifdef KEEP_UNUSED
/* type: 0=all, 1=getroute */
static void print_aflist(int type) {
static void print_aflist(int type)
{
int count = 0;
char *txt;
struct aftype **afp;
@ -770,10 +752,14 @@ static void print_aflist(int type) {
afp = aftypes;
while (*afp != NULL) {
if ((type == 1 && ((*afp)->rprint == NULL)) || ((*afp)->af == 0)) {
afp++; continue;
afp++;
continue;
}
if ((count % 3) == 0) fprintf(stderr,count?"\n ":" ");
txt = (*afp)->name; if (!txt) txt = "..";
if ((count % 3) == 0)
fprintf(stderr, count ? "\n " : " ");
txt = (*afp)->name;
if (!txt)
txt = "..";
fprintf(stderr, "%s (%s) ", txt, _((*afp)->title));
count++;
afp++;
@ -875,6 +861,7 @@ static int sockets_open(int family)
for (aft = aftypes; *aft; aft++) {
struct aftype *af = *aft;
int type = SOCK_DGRAM;
if (af->af == AF_UNSPEC)
continue;
if (family && family != af->af)
@ -940,6 +927,7 @@ static struct interface *add_interface(char *name)
for (ife = int_last; ife; ife = ife->prev) {
int n = nstrcmp(ife->name, name);
if (n == 0)
return ife;
if (n < 0)
@ -1017,6 +1005,7 @@ static char *get_name(char *name, char *p)
break;
if (*p == ':') { /* could be an alias */
char *dot = p, *dotname = name;
*name++ = *p++;
while (isdigit(*p))
*name++ = *p++;
@ -1049,15 +1038,13 @@ static int get_dev_fields(char *bp, struct interface *ife)
&ife->stats.rx_frame_errors,
&ife->stats.rx_compressed,
&ife->stats.rx_multicast,
&ife->stats.tx_bytes,
&ife->stats.tx_packets,
&ife->stats.tx_errors,
&ife->stats.tx_dropped,
&ife->stats.tx_fifo_errors,
&ife->stats.collisions,
&ife->stats.tx_carrier_errors,
&ife->stats.tx_compressed);
&ife->stats.tx_carrier_errors, &ife->stats.tx_compressed);
break;
case 2:
sscanf(bp, "%Lu %Lu %lu %lu %lu %lu %Lu %Lu %lu %lu %lu %lu %lu",
@ -1067,14 +1054,12 @@ static int get_dev_fields(char *bp, struct interface *ife)
&ife->stats.rx_dropped,
&ife->stats.rx_fifo_errors,
&ife->stats.rx_frame_errors,
&ife->stats.tx_bytes,
&ife->stats.tx_packets,
&ife->stats.tx_errors,
&ife->stats.tx_dropped,
&ife->stats.tx_fifo_errors,
&ife->stats.collisions,
&ife->stats.tx_carrier_errors);
&ife->stats.collisions, &ife->stats.tx_carrier_errors);
ife->stats.rx_multicast = 0;
break;
case 1:
@ -1084,13 +1069,11 @@ static int get_dev_fields(char *bp, struct interface *ife)
&ife->stats.rx_dropped,
&ife->stats.rx_fifo_errors,
&ife->stats.rx_frame_errors,
&ife->stats.tx_packets,
&ife->stats.tx_errors,
&ife->stats.tx_dropped,
&ife->stats.tx_fifo_errors,
&ife->stats.collisions,
&ife->stats.tx_carrier_errors);
&ife->stats.collisions, &ife->stats.tx_carrier_errors);
ife->stats.rx_bytes = 0;
ife->stats.tx_bytes = 0;
ife->stats.rx_multicast = 0;
@ -1131,8 +1114,7 @@ static int if_readlist_proc(char *target)
fgets(buf, sizeof buf, fh);
#if 0 /* pretty, but can't cope with missing fields */
fmt = proc_gen_fmt(_PATH_PROCNET_DEV, 1, fh,
"face", "", /* parsed separately */
fmt = proc_gen_fmt(_PATH_PROCNET_DEV, 1, fh, "face", "", /* parsed separately */
"bytes", "%lu",
"packets", "%lu",
"errs", "%lu",
@ -1147,9 +1129,7 @@ static int if_readlist_proc(char *target)
"drop", "%lu",
"fifo", "%lu",
"colls", "%lu",
"carrier", "%lu",
"compressed", "%lu",
NULL);
"carrier", "%lu", "compressed", "%lu", NULL);
if (!fmt)
return -1;
#else
@ -1159,6 +1139,7 @@ static int if_readlist_proc(char *target)
err = 0;
while (fgets(buf, sizeof buf, fh)) {
char *s, name[IFNAMSIZ];
s = get_name(name, buf);
ife = add_interface(name);
get_dev_fields(s, ife);
@ -1171,7 +1152,6 @@ static int if_readlist_proc(char *target)
err = -1;
proc_read = 0;
}
#if 0
free(fmt);
#endif
@ -1182,12 +1162,14 @@ static int if_readlist_proc(char *target)
static int if_readlist(void)
{
int err = if_readlist_proc(NULL);
if (!err)
err = if_readconf();
return err;
}
static int for_all_interfaces(int (*doit) (struct interface *, void *), void *cookie)
static int for_all_interfaces(int (*doit) (struct interface *, void *),
void *cookie)
{
struct interface *ife;
@ -1195,6 +1177,7 @@ static int for_all_interfaces(int (*doit) (struct interface *, void *), void *co
return -1;
for (ife = int_list; ife; ife = ife->next) {
int err = doit(ife, cookie);
if (err)
return err;
}
@ -1377,6 +1360,7 @@ static int do_if_fetch(struct interface *ife)
{
if (if_fetch(ife) < 0) {
char *errmsg;
if (errno == ENODEV) {
/* Give better error message for this case. */
errmsg = _("Device not found");
@ -1402,14 +1386,12 @@ struct hwtype {
int suppress_null_addr;
};
static struct hwtype unspec_hwtype =
{
static struct hwtype unspec_hwtype = {
"unspec", "UNSPEC", -1, 0,
UNSPEC_print, NULL, NULL
};
static struct hwtype loop_hwtype =
{
static struct hwtype loop_hwtype = {
"loop", "Local Loopback", ARPHRD_LOOPBACK, 0,
NULL, NULL, NULL
};
@ -1418,8 +1400,6 @@ static struct hwtype loop_hwtype =
#include <net/if_arp.h>
#include <linux/if_ether.h>
static struct hwtype ether_hwtype;
/* Display an Ethernet address in readable format. */
static char *pr_ether(unsigned char *ptr)
{
@ -1457,7 +1437,8 @@ static int in_ether(char *bufp, struct sockaddr *sap)
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);
@ -1474,7 +1455,8 @@ static int in_ether(char *bufp, struct sockaddr *sap)
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);
@ -1514,8 +1496,7 @@ static int in_ether(char *bufp, struct sockaddr *sap)
#endif /* KEEP_UNUSED */
static struct hwtype ether_hwtype =
{
static struct hwtype ether_hwtype = {
"ether", "Ethernet", ARPHRD_ETHER, ETH_ALEN,
pr_ether, NULL /* UNUSED in_ether */ , NULL
};
@ -1537,8 +1518,7 @@ static int do_ppp(int fd)
}
#endif /* KEEP_UNUSED */
static struct hwtype ppp_hwtype =
{
static struct hwtype ppp_hwtype = {
"ppp", "Point-Point Protocol", ARPHRD_PPP, 0,
NULL, NULL, NULL /* UNUSED do_ppp */ , 0
};
@ -1546,8 +1526,7 @@ static struct hwtype ppp_hwtype =
#endif /* HAVE_PPP */
static struct hwtype *hwtypes[] =
{
static struct hwtype *hwtypes[] = {
&loop_hwtype,
@ -1696,8 +1675,7 @@ static void hwinit()
#endif /* KEEP_UNUSED */
#ifdef IFF_PORTSEL
static const char *if_port_text[][4] =
{
static const char *if_port_text[][4] = {
/* Keep in step with <linux/netdevice.h> */
{"unknown", NULL, NULL, NULL},
{"10base2", "bnc", "coax", NULL},
@ -1734,6 +1712,7 @@ static int hw_null_address(struct hwtype *hw, void *ap)
{
unsigned int i;
unsigned char *address = (unsigned char *) ap;
for (i = 0; i < hw->alen; i++)
if (address[i])
return 0;
@ -1849,18 +1828,21 @@ static void ife_print(struct interface *ptr)
#define IPV6_ADDR_RESERVED 0x2000U /* reserved address space */
if ((f = fopen(_PATH_PROCNET_IFINET6, "r")) != NULL) {
while (fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n",
addr6p[0], addr6p[1], addr6p[2], addr6p[3],
addr6p[4], addr6p[5], addr6p[6], addr6p[7],
&if_idx, &plen, &scope, &dad_status, devname) != EOF) {
while (fscanf
(f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n",
addr6p[0], addr6p[1], addr6p[2], addr6p[3], addr6p[4],
addr6p[5], addr6p[6], addr6p[7], &if_idx, &plen, &scope,
&dad_status, devname) != EOF) {
if (!strcmp(devname, ptr->name)) {
sprintf(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]);
inet_pton(AF_INET6, addr6, (struct sockaddr *) &sap.sin6_addr);
inet_pton(AF_INET6, addr6,
(struct sockaddr *) &sap.sin6_addr);
sap.sin6_family = AF_INET6;
printf(_(" inet6 addr: %s/%d"),
inet6_aftype.sprint((struct sockaddr *) &sap, 1), plen);
inet6_aftype.sprint((struct sockaddr *) &sap, 1),
plen);
printf(_(" Scope:"));
switch (scope & IPV6_ADDR_SCOPE_MASK) {
case 0:
@ -1913,7 +1895,8 @@ static void ife_print(struct interface *ptr)
ddptype = get_afntype(AF_APPLETALK);
if (ddptype != NULL) {
if (ptr->has_ddp)
printf(_(" EtherTalk Phase 2 addr:%s\n"), ddptype->sprint(&ptr->ddpaddr, 1));
printf(_(" EtherTalk Phase 2 addr:%s\n"),
ddptype->sprint(&ptr->ddpaddr, 1));
}
#endif
@ -1922,7 +1905,8 @@ static void ife_print(struct interface *ptr)
ectype = get_afntype(AF_ECONET);
if (ectype != NULL) {
if (ptr->has_econet)
printf(_(" econet addr:%s\n"), ectype->sprint(&ptr->ecaddr, 1));
printf(_(" econet addr:%s\n"),
ectype->sprint(&ptr->ecaddr, 1));
}
#endif
@ -1961,12 +1945,10 @@ static void ife_print(struct interface *ptr)
printf(_("DYNAMIC "));
#endif
/* DONT FORGET TO ADD THE FLAGS IN ife_print_short */
printf(_(" MTU:%d Metric:%d"),
ptr->mtu, ptr->metric ? ptr->metric : 1);
printf(_(" MTU:%d Metric:%d"), ptr->mtu, ptr->metric ? ptr->metric : 1);
#ifdef SIOCSKEEPALIVE
if (ptr->outfill || ptr->keepalive)
printf(_(" Outfill:%d Keepalive:%d"),
ptr->outfill, ptr->keepalive);
printf(_(" Outfill:%d Keepalive:%d"), ptr->outfill, ptr->keepalive);
#endif
printf("\n");
@ -1979,14 +1961,17 @@ static void ife_print(struct interface *ptr)
*/
printf(" ");
printf(_("RX packets:%Lu errors:%lu dropped:%lu overruns:%lu frame:%lu\n"),
printf(_
("RX packets:%Lu errors:%lu dropped:%lu overruns:%lu frame:%lu\n"),
ptr->stats.rx_packets, ptr->stats.rx_errors,
ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors,
ptr->stats.rx_frame_errors);
if (can_compress)
printf(_(" compressed:%lu\n"), ptr->stats.rx_compressed);
printf(_(" compressed:%lu\n"),
ptr->stats.rx_compressed);
printf(" ");
printf(_("TX packets:%Lu errors:%lu dropped:%lu overruns:%lu carrier:%lu\n"),
printf(_
("TX packets:%Lu errors:%lu dropped:%lu overruns:%lu carrier:%lu\n"),
ptr->stats.tx_packets, ptr->stats.tx_errors,
ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors,
ptr->stats.tx_carrier_errors);
@ -2008,9 +1993,11 @@ static void ife_print(struct interface *ptr)
printf(_("Interrupt:%d "), ptr->map.irq);
if (ptr->map.base_addr >= 0x100) /* Only print devices using it for
I/O maps */
printf(_("Base address:0x%lx "), (unsigned long)ptr->map.base_addr);
printf(_("Base address:0x%lx "),
(unsigned long) ptr->map.base_addr);
if (ptr->map.mem_start) {
printf(_("Memory:%lx-%lx "), ptr->map.mem_start, ptr->map.mem_end);
printf(_("Memory:%lx-%lx "), ptr->map.mem_start,
ptr->map.mem_end);
}
if (ptr->map.dma)
printf(_("DMA chan:%x "), ptr->map.dma);