Commit 5c9e1e76 authored by Mike Frysinger's avatar Mike Frysinger

use sockaddr_storage everywhere

Not all sockaddr structs have the same alignment.  Instead, it depends
on the fields contained in it.  The way net-tools has written things
though, it accepts sockaddr* everywhere which has 16bit alignment, even
though it will cast it to other sockaddr types that have higher alignment.
For example, `route` can crash on alpha because it declares sockaddr on
the stack, but then casts it up to sockaddr_in6 (which has 32bits).

It's also bad storage wise as we might try to cast the sockaddr to a type
that is larger than sockaddr which means clobbering the stack.

Instead, lets rewrite all the APIs to take a sockaddr_storage.  This is
guaranteed to have both the maximum alignment and size requirements for
all other sockaddr types.  Now we can safely cast that pointer to any
other sockaddr type and not worry about it.  It also has the nice effect
of deleting a lot of casts in a lot of places when we only need the type
of family.

The vast majority of changes here are mechanical.  There are a few places
where we have to memcpy between a dedicated sockaddr_storage and a smaller
struct because we're using an external embedded type (like arpreq).

URL: https://bugs.gentoo.org/558436
parent 27e4308d
...@@ -101,7 +101,7 @@ static int arp_del(char **args) ...@@ -101,7 +101,7 @@ static int arp_del(char **args)
char host[128]; char host[128];
struct arpreq req; struct arpreq req;
struct sockaddr_storage ss; struct sockaddr_storage ss;
struct sockaddr *sa; struct sockaddr *sa = (struct sockaddr *)&ss;
int flags = 0; int flags = 0;
int deleted = 0; int deleted = 0;
...@@ -113,8 +113,7 @@ static int arp_del(char **args) ...@@ -113,8 +113,7 @@ static int arp_del(char **args)
return (-1); return (-1);
} }
safe_strncpy(host, *args, (sizeof host)); safe_strncpy(host, *args, (sizeof host));
sa = (struct sockaddr *)&ss; if (ap->input(0, host, &ss) < 0) {
if (ap->input(0, host, sa) < 0) {
ap->herror(host); ap->herror(host);
return (-1); return (-1);
} }
...@@ -179,7 +178,7 @@ static int arp_del(char **args) ...@@ -179,7 +178,7 @@ static int arp_del(char **args)
usage(); usage();
if (strcmp(*args, "255.255.255.255") != 0) { if (strcmp(*args, "255.255.255.255") != 0) {
safe_strncpy(host, *args, (sizeof host)); safe_strncpy(host, *args, (sizeof host));
if (ap->input(0, host, sa) < 0) { if (ap->input(0, host, &ss) < 0) {
ap->herror(host); ap->herror(host);
return (-1); return (-1);
} }
...@@ -269,7 +268,7 @@ static int arp_set(char **args) ...@@ -269,7 +268,7 @@ static int arp_set(char **args)
char host[128]; char host[128];
struct arpreq req; struct arpreq req;
struct sockaddr_storage ss; struct sockaddr_storage ss;
struct sockaddr *sa; struct sockaddr *sa = (struct sockaddr *)&ss;
int flags; int flags;
memset((char *) &req, 0, sizeof(req)); memset((char *) &req, 0, sizeof(req));
...@@ -280,8 +279,7 @@ static int arp_set(char **args) ...@@ -280,8 +279,7 @@ static int arp_set(char **args)
return (-1); return (-1);
} }
safe_strncpy(host, *args++, (sizeof host)); safe_strncpy(host, *args++, (sizeof host));
sa = (struct sockaddr *)&ss; if (ap->input(0, host, &ss) < 0) {
if (ap->input(0, host, sa) < 0) {
ap->herror(host); ap->herror(host);
return (-1); return (-1);
} }
...@@ -297,10 +295,11 @@ static int arp_set(char **args) ...@@ -297,10 +295,11 @@ static int arp_set(char **args)
if (arp_getdevhw(*args++, &req.arp_ha, hw_set ? hw : NULL) < 0) if (arp_getdevhw(*args++, &req.arp_ha, hw_set ? hw : NULL) < 0)
return (-1); return (-1);
} else { } else {
if (hw->input(*args++, &req.arp_ha) < 0) { if (hw->input(*args++, &ss) < 0) {
fprintf(stderr, _("arp: invalid hardware address\n")); fprintf(stderr, _("arp: invalid hardware address\n"));
return (-1); return (-1);
} }
memcpy(&req.arp_ha, sa, sizeof(*sa));
} }
/* Check out any modifiers. */ /* Check out any modifiers. */
...@@ -356,7 +355,7 @@ static int arp_set(char **args) ...@@ -356,7 +355,7 @@ static int arp_set(char **args)
usage(); usage();
if (strcmp(*args, "255.255.255.255") != 0) { if (strcmp(*args, "255.255.255.255") != 0) {
safe_strncpy(host, *args, (sizeof host)); safe_strncpy(host, *args, (sizeof host));
if (ap->input(0, host, sa) < 0) { if (ap->input(0, host, &ss) < 0) {
ap->herror(host); ap->herror(host);
return (-1); return (-1);
} }
...@@ -530,7 +529,6 @@ static int arp_show(char *name) ...@@ -530,7 +529,6 @@ static int arp_show(char *name)
{ {
char host[100]; char host[100];
struct sockaddr_storage ss; struct sockaddr_storage ss;
struct sockaddr *sa;
char ip[100]; char ip[100];
char hwa[100]; char hwa[100];
char mask[100]; char mask[100];
...@@ -543,15 +541,14 @@ static int arp_show(char *name) ...@@ -543,15 +541,14 @@ static int arp_show(char *name)
host[0] = '\0'; host[0] = '\0';
sa = (struct sockaddr *)&ss;
if (name != NULL) { if (name != NULL) {
/* Resolve the host name. */ /* Resolve the host name. */
safe_strncpy(host, name, (sizeof host)); safe_strncpy(host, name, (sizeof host));
if (ap->input(0, host, sa) < 0) { if (ap->input(0, host, &ss) < 0) {
ap->herror(host); ap->herror(host);
return (-1); return (-1);
} }
safe_strncpy(host, ap->sprint(sa, 1), sizeof(host)); safe_strncpy(host, ap->sprint(&ss, 1), sizeof(host));
} }
/* Open the PROCps kernel table. */ /* Open the PROCps kernel table. */
if ((fp = fopen(_PATH_PROCNET_ARP, "r")) == NULL) { if ((fp = fopen(_PATH_PROCNET_ARP, "r")) == NULL) {
...@@ -587,10 +584,10 @@ static int arp_show(char *name) ...@@ -587,10 +584,10 @@ static int arp_show(char *name)
if (opt_n) if (opt_n)
hostname = "?"; hostname = "?";
else { else {
if (ap->input(0, ip, sa) < 0) if (ap->input(0, ip, &ss) < 0)
hostname = ip; hostname = ip;
else else
hostname = ap->sprint(sa, opt_n | 0x8000); hostname = ap->sprint(&ss, opt_n | 0x8000);
if (strcmp(hostname, ip) == 0) if (strcmp(hostname, ip) == 0)
hostname = "?"; hostname = "?";
} }
......
...@@ -255,7 +255,7 @@ int main(int argc, char **argv) ...@@ -255,7 +255,7 @@ int main(int argc, char **argv)
struct sockaddr_storage _sa, _samask; struct sockaddr_storage _sa, _samask;
struct sockaddr *sa = (struct sockaddr *)&_sa; struct sockaddr *sa = (struct sockaddr *)&_sa;
struct sockaddr *samask = (struct sockaddr *)&_samask; struct sockaddr *samask = (struct sockaddr *)&_samask;
struct sockaddr_in *sin = (struct sockaddr_in *)sa; struct sockaddr_in *sin = (struct sockaddr_in *)&_sa;
char host[128]; char host[128];
const struct aftype *ap; const struct aftype *ap;
const struct hwtype *hw; const struct hwtype *hw;
...@@ -265,7 +265,7 @@ int main(int argc, char **argv) ...@@ -265,7 +265,7 @@ int main(int argc, char **argv)
int fd; int fd;
#if HAVE_AFINET6 #if HAVE_AFINET6
extern struct aftype inet6_aftype; extern struct aftype inet6_aftype;
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&_sa;
struct in6_ifreq ifr6; struct in6_ifreq ifr6;
unsigned long prefix_len; unsigned long prefix_len;
char *cp; char *cp;
...@@ -518,7 +518,7 @@ int main(int argc, char **argv) ...@@ -518,7 +518,7 @@ int main(int argc, char **argv)
if (!strcmp(*spp, "broadcast")) { if (!strcmp(*spp, "broadcast")) {
if (*++spp != NULL) { if (*++spp != NULL) {
safe_strncpy(host, *spp, (sizeof host)); safe_strncpy(host, *spp, (sizeof host));
if (ap->input(0, host, sa) < 0) { if (ap->input(0, host, &_sa) < 0) {
if (ap->herror) if (ap->herror)
ap->herror(host); ap->herror(host);
else else
...@@ -542,7 +542,7 @@ int main(int argc, char **argv) ...@@ -542,7 +542,7 @@ int main(int argc, char **argv)
if (*++spp == NULL) if (*++spp == NULL)
usage(); usage();
safe_strncpy(host, *spp, (sizeof host)); safe_strncpy(host, *spp, (sizeof host));
if (ap->input(0, host, sa) < 0) { if (ap->input(0, host, &_sa) < 0) {
if (ap->herror) if (ap->herror)
ap->herror(host); ap->herror(host);
else else
...@@ -564,7 +564,7 @@ int main(int argc, char **argv) ...@@ -564,7 +564,7 @@ int main(int argc, char **argv)
if (*++spp == NULL || didnetmask) if (*++spp == NULL || didnetmask)
usage(); usage();
safe_strncpy(host, *spp, (sizeof host)); safe_strncpy(host, *spp, (sizeof host));
if (ap->input(0, host, sa) < 0) { if (ap->input(0, host, &_sa) < 0) {
if (ap->herror) if (ap->herror)
ap->herror(host); ap->herror(host);
else else
...@@ -654,7 +654,7 @@ int main(int argc, char **argv) ...@@ -654,7 +654,7 @@ int main(int argc, char **argv)
if (*(spp + 1) != NULL) { if (*(spp + 1) != NULL) {
spp++; spp++;
safe_strncpy(host, *spp, (sizeof host)); safe_strncpy(host, *spp, (sizeof host));
if (ap->input(0, host, sa)) { if (ap->input(0, host, &_sa)) {
if (ap->herror) if (ap->herror)
ap->herror(host); ap->herror(host);
else else
...@@ -689,7 +689,7 @@ int main(int argc, char **argv) ...@@ -689,7 +689,7 @@ int main(int argc, char **argv)
if (*++spp == NULL) if (*++spp == NULL)
usage(); usage();
safe_strncpy(host, *spp, (sizeof host)); safe_strncpy(host, *spp, (sizeof host));
if (hw->input(host, sa) < 0) { if (hw->input(host, &_sa) < 0) {
fprintf(stderr, _("%s: invalid %s address.\n"), host, hw->name); fprintf(stderr, _("%s: invalid %s address.\n"), host, hw->name);
goterr = 1; goterr = 1;
spp++; spp++;
...@@ -724,7 +724,7 @@ int main(int argc, char **argv) ...@@ -724,7 +724,7 @@ int main(int argc, char **argv)
prefix_len = 128; prefix_len = 128;
} }
safe_strncpy(host, *spp, (sizeof host)); safe_strncpy(host, *spp, (sizeof host));
if (inet6_aftype.input(1, host, sa) < 0) { if (inet6_aftype.input(1, host, &_sa) < 0) {
if (inet6_aftype.herror) if (inet6_aftype.herror)
inet6_aftype.herror(host); inet6_aftype.herror(host);
else else
...@@ -763,7 +763,7 @@ int main(int argc, char **argv) ...@@ -763,7 +763,7 @@ int main(int argc, char **argv)
{ /* ipv4 address a.b.c.d */ { /* ipv4 address a.b.c.d */
in_addr_t ip, nm, bc; in_addr_t ip, nm, bc;
safe_strncpy(host, *spp, (sizeof host)); safe_strncpy(host, *spp, (sizeof host));
if (inet_aftype.input(0, host, sa) < 0) { if (inet_aftype.input(0, host, &_sa) < 0) {
ap->herror(host); ap->herror(host);
goterr = 1; goterr = 1;
spp++; spp++;
...@@ -815,7 +815,7 @@ int main(int argc, char **argv) ...@@ -815,7 +815,7 @@ int main(int argc, char **argv)
prefix_len = 128; prefix_len = 128;
} }
safe_strncpy(host, *spp, (sizeof host)); safe_strncpy(host, *spp, (sizeof host));
if (inet6_aftype.input(1, host, sa) < 0) { if (inet6_aftype.input(1, host, &_sa) < 0) {
inet6_aftype.herror(host); inet6_aftype.herror(host);
goterr = 1; goterr = 1;
spp++; spp++;
...@@ -856,7 +856,7 @@ int main(int argc, char **argv) ...@@ -856,7 +856,7 @@ int main(int argc, char **argv)
/* ipv4 address a.b.c.d */ /* ipv4 address a.b.c.d */
in_addr_t ip, nm, bc; in_addr_t ip, nm, bc;
safe_strncpy(host, *spp, (sizeof host)); safe_strncpy(host, *spp, (sizeof host));
if (inet_aftype.input(0, host, sa) < 0) { if (inet_aftype.input(0, host, &_sa) < 0) {
ap->herror(host); ap->herror(host);
goterr = 1; goterr = 1;
spp++; spp++;
...@@ -906,7 +906,7 @@ int main(int argc, char **argv) ...@@ -906,7 +906,7 @@ int main(int argc, char **argv)
prefix_len = 128; prefix_len = 128;
} }
safe_strncpy(host, *spp, (sizeof host)); safe_strncpy(host, *spp, (sizeof host));
if (inet6_aftype.input(1, host, sa) < 0) { if (inet6_aftype.input(1, host, &_sa) < 0) {
inet6_aftype.herror(host); inet6_aftype.herror(host);
goterr = 1; goterr = 1;
spp++; spp++;
...@@ -946,7 +946,7 @@ int main(int argc, char **argv) ...@@ -946,7 +946,7 @@ int main(int argc, char **argv)
/* FIXME: sa is too small for INET6 addresses, inet6 should use that too, /* FIXME: sa is too small for INET6 addresses, inet6 should use that too,
broadcast is unexpected */ broadcast is unexpected */
if (ap->getmask) { if (ap->getmask) {
switch (ap->getmask(host, samask, NULL)) { switch (ap->getmask(host, &_samask, NULL)) {
case -1: case -1:
usage(); usage();
break; break;
...@@ -963,7 +963,7 @@ int main(int argc, char **argv) ...@@ -963,7 +963,7 @@ int main(int argc, char **argv)
fprintf(stderr, _("ifconfig: Cannot set address for this protocol family.\n")); fprintf(stderr, _("ifconfig: Cannot set address for this protocol family.\n"));
exit(1); exit(1);
} }
if (ap->input(0, host, sa) < 0) { if (ap->input(0, host, &_sa) < 0) {
if (ap->herror) if (ap->herror)
ap->herror(host); ap->herror(host);
else else
...@@ -1083,7 +1083,7 @@ static int do_ifcmd(struct interface *x, struct ifcmd *ptr) ...@@ -1083,7 +1083,7 @@ static int do_ifcmd(struct interface *x, struct ifcmd *ptr)
searcher[i] = 1; searcher[i] = 1;
/* copy */ /* copy */
sin = (struct sockaddr_in *)&x->dstaddr; sin = (struct sockaddr_in *)&x->dstaddr_sas;
if (sin->sin_addr.s_addr != ptr->addr) { if (sin->sin_addr.s_addr != ptr->addr) {
return 0; return 0;
} }
...@@ -1113,9 +1113,9 @@ static int get_nmbc_parent(char *parent, ...@@ -1113,9 +1113,9 @@ static int get_nmbc_parent(char *parent,
return -1; return -1;
if (do_if_fetch(i) < 0) if (do_if_fetch(i) < 0)
return 0; return 0;
sin = (struct sockaddr_in *)&i->netmask; sin = (struct sockaddr_in *)&i->netmask_sas;
memcpy(nm, &sin->sin_addr.s_addr, sizeof(*nm)); memcpy(nm, &sin->sin_addr.s_addr, sizeof(*nm));
sin = (struct sockaddr_in *)&i->broadaddr; sin = (struct sockaddr_in *)&i->broadaddr_sas;
memcpy(bc, &sin->sin_addr.s_addr, sizeof(*bc)); memcpy(bc, &sin->sin_addr.s_addr, sizeof(*bc));
return 0; return 0;
} }
......
...@@ -35,16 +35,46 @@ struct interface { ...@@ -35,16 +35,46 @@ struct interface {
int mtu; /* MTU value */ int mtu; /* MTU value */
int tx_queue_len; /* transmit queue length */ int tx_queue_len; /* transmit queue length */
struct ifmap map; /* hardware setup */ struct ifmap map; /* hardware setup */
struct sockaddr addr; /* IP address */ union {
struct sockaddr dstaddr; /* P-P IP address */ struct sockaddr_storage addr_sas;
struct sockaddr broadaddr; /* IP broadcast address */ struct sockaddr addr; /* IP address */
struct sockaddr netmask; /* IP network mask */ };
struct sockaddr ipxaddr_bb; /* IPX network address */ union {
struct sockaddr ipxaddr_sn; /* IPX network address */ struct sockaddr_storage dstaddr_sas;
struct sockaddr ipxaddr_e3; /* IPX network address */ struct sockaddr dstaddr; /* P-P IP address */
struct sockaddr ipxaddr_e2; /* IPX network address */ };
struct sockaddr ddpaddr; /* Appletalk DDP address */ union {
struct sockaddr ecaddr; /* Econet address */ struct sockaddr_storage broadaddr_sas;
struct sockaddr broadaddr; /* IP broadcast address */
};
union {
struct sockaddr_storage netmask_sas;
struct sockaddr netmask; /* IP network mask */
};
union {
struct sockaddr_storage ipxaddr_bb_sas;
struct sockaddr ipxaddr_bb; /* IPX network address */
};
union {
struct sockaddr_storage ipxaddr_sn_sas;
struct sockaddr ipxaddr_sn; /* IPX network address */
};
union {
struct sockaddr_storage ipxaddr_e3_sas;
struct sockaddr ipxaddr_e3; /* IPX network address */
};
union {
struct sockaddr_storage ipxaddr_e2_sas;
struct sockaddr ipxaddr_e2; /* IPX network address */
};
union {
struct sockaddr_storage ddpaddr_sas;
struct sockaddr ddpaddr; /* Appletalk DDP address */
};
union {
struct sockaddr_storage ecaddr_sas;
struct sockaddr ecaddr; /* Econet address */
};
int has_ip; int has_ip;
int has_ipx_bb; int has_ipx_bb;
int has_ipx_sn; int has_ipx_sn;
......
...@@ -50,8 +50,9 @@ static const char *pr_arcnet(const char *ptr) ...@@ -50,8 +50,9 @@ static const char *pr_arcnet(const char *ptr)
#endif #endif
/* Input an ARCnet address and convert to binary. */ /* 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_storage *sasp)
{ {
struct sockaddr *sap = (struct sockaddr *)sasp;
char *ptr; char *ptr;
char c, *orig; char c, *orig;
int i, val; int i, val;
......
...@@ -58,8 +58,9 @@ pr_ash(const char *ptr) ...@@ -58,8 +58,9 @@ pr_ash(const char *ptr)
struct hwtype ash_hwtype; struct hwtype ash_hwtype;
static int static int
in_ash(char *bufp, struct sockaddr *sap) in_ash(char *bufp, struct sockaddr_storage *sasp)
{ {
struct sockaddr *sap = (struct sockaddr *)sasp;
char *ptr; char *ptr;
unsigned int i = 0; unsigned int i = 0;
...@@ -103,8 +104,9 @@ struct hwtype ash_hwtype = ...@@ -103,8 +104,9 @@ struct hwtype ash_hwtype =
/* Display an Ash socket address. */ /* Display an Ash socket address. */
static const char * static const char *
pr_sash(const struct sockaddr *sap, int numeric) pr_sash(const struct sockaddr_storage *sasp, int numeric)
{ {
const struct sockaddr *sap = (const struct sockaddr *)sasp;
static char buf[64]; static char buf[64];
if (sap->sa_family != AF_ASH) if (sap->sa_family != AF_ASH)
......
...@@ -67,13 +67,14 @@ static const char *AX25_print(const char *ptr) ...@@ -67,13 +67,14 @@ static const char *AX25_print(const char *ptr)
/* Display an AX.25 socket address. */ /* Display an AX.25 socket address. */
static const char * static const char *
AX25_sprint(const struct sockaddr *sap, int numeric) AX25_sprint(const struct sockaddr_storage *sasp, int numeric)
{ {
const struct sockaddr *sap = (const struct sockaddr *)sasp;
static char buf[64]; static char buf[64];
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf)); return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf));
return (AX25_print(((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call)); return (AX25_print(((const struct sockaddr_ax25 *) sasp)->sax25_call.ax25_call));
} }
#ifdef DEBUG #ifdef DEBUG
...@@ -82,14 +83,15 @@ static const char * ...@@ -82,14 +83,15 @@ static const char *
#define _DEBUG 0 #define _DEBUG 0
#endif #endif
static int AX25_input(int type, char *bufp, struct sockaddr *sap) static int AX25_input(int type, char *bufp, struct sockaddr_storage *sasp)
{ {
struct sockaddr *sap = (struct sockaddr *)sasp;
char *ptr; char *ptr;
char *orig, c; char *orig, c;
int i; int i;
sap->sa_family = ax25_aftype.af; sap->sa_family = ax25_aftype.af;
ptr = ((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call; ptr = ((struct sockaddr_ax25 *) sasp)->sax25_call.ax25_call;
/* First, scan and convert the basic callsign. */ /* First, scan and convert the basic callsign. */
orig = bufp; orig = bufp;
...@@ -152,9 +154,10 @@ static void AX25_herror(const char *text) ...@@ -152,9 +154,10 @@ static void AX25_herror(const char *text)
} }
static int AX25_hinput(char *bufp, struct sockaddr *sap) static int AX25_hinput(char *bufp, struct sockaddr_storage *sasp)
{ {
if (AX25_input(0, bufp, sap) < 0) struct sockaddr *sap = (struct sockaddr *)sasp;
if (AX25_input(0, bufp, sasp) < 0)
return (-1); return (-1);
sap->sa_family = ARPHRD_AX25; sap->sa_family = ARPHRD_AX25;
return (0); return (0);
......
...@@ -42,8 +42,9 @@ static const char *ddp_print(const char *ptr) ...@@ -42,8 +42,9 @@ static const char *ddp_print(const char *ptr)
/* Display a ddp domain address. */ /* Display a ddp domain address. */
static const char *ddp_sprint(const struct sockaddr *sap, int numeric) static const char *ddp_sprint(const struct sockaddr_storage *sasp, int numeric)
{ {
const struct sockaddr *sap = (const struct sockaddr *)sasp;
static char buf[64]; static char buf[64];
if (sap->sa_family != AF_APPLETALK) if (sap->sa_family != AF_APPLETALK)
......
...@@ -44,20 +44,20 @@ ec_print(const char *ptr) ...@@ -44,20 +44,20 @@ ec_print(const char *ptr)
/* Display an Econet socket address */ /* Display an Econet socket address */
static const char * static const char *
ec_sprint(const struct sockaddr *sap, int numeric) ec_sprint(const struct sockaddr_storage *sasp, int numeric)
{ {
struct sockaddr_ec *sec = (struct sockaddr_ec *) sap; const struct sockaddr_ec *sec = (const struct sockaddr_ec *)sasp;
if (sap->sa_family != AF_ECONET) if (sasp->ss_family != AF_ECONET)
return _("[NONE SET]"); return _("[NONE SET]");
return ec_print((const char *) &sec->addr); return ec_print((const char *) &sec->addr);
} }
static int static int
ec_input(int type, char *bufp, struct sockaddr *sap) ec_input(int type, char *bufp, struct sockaddr_storage *sasp)
{ {
struct sockaddr_ec *sec = (struct sockaddr_ec *) sap; struct sockaddr_ec *sec = (struct sockaddr_ec *) sasp;
int net, stn; int net, stn;
switch (sscanf(bufp, "%d.%d", &net, &stn)) { switch (sscanf(bufp, "%d.%d", &net, &stn)) {
case 2: case 2:
......
...@@ -53,8 +53,9 @@ static const char *pr_ether(const char *ptr) ...@@ -53,8 +53,9 @@ static const char *pr_ether(const char *ptr)
#endif #endif
/* Input an Ethernet address and convert to binary. */ /* 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_storage *sasp)
{ {
struct sockaddr *sap = (struct sockaddr *)sasp;
char *ptr; char *ptr;
char c, *orig; char c, *orig;
int i; int i;
......
...@@ -67,8 +67,9 @@ static const char *pr_eui64(const char *ptr) ...@@ -67,8 +67,9 @@ static const char *pr_eui64(const char *ptr)
#endif #endif
/* Start the PPP encapsulation on the file descriptor. */ /* Start the PPP encapsulation on the file descriptor. */
static int in_eui64( char *bufp, struct sockaddr *sap ) static int in_eui64(char *bufp, struct sockaddr_storage *sasp)
{ {
struct sockaddr *sap = (struct sockaddr *)sasp;
char *ptr; char *ptr;
char c, *orig; char c, *orig;
int i; int i;
......
...@@ -64,8 +64,9 @@ static const char *pr_fddi(const char *ptr) ...@@ -64,8 +64,9 @@ static const char *pr_fddi(const char *ptr)
#endif #endif
/* Input an FDDI address and convert to binary. */ /* 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_storage *sasp)
{ {
struct sockaddr *sap = (struct sockaddr *)sasp;
char *ptr; char *ptr;
char c, *orig; char c, *orig;
int i, val; int i, val;
......
...@@ -64,8 +64,9 @@ static const char *pr_hippi(const char *ptr) ...@@ -64,8 +64,9 @@ static const char *pr_hippi(const char *ptr)
#endif #endif
/* Input an HIPPI address and convert to binary. */ /* 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_storage *sasp)
{ {
struct sockaddr *sap = (struct sockaddr *)sasp;
char *ptr; char *ptr;
char c, *orig; char c, *orig;
int i, val; int i, val;
......
...@@ -63,8 +63,9 @@ static const char *pr_ib(const char *ptr) ...@@ -63,8 +63,9 @@ static const char *pr_ib(const char *ptr)
#endif #endif
/* Input an Infiniband address and convert to binary. */ /* Input an Infiniband address and convert to binary. */
static int in_ib(char *bufp, struct sockaddr *sap) static int in_ib(char *bufp, struct sockaddr_storage *sasp)
{ {
struct sockaddr *sap = (struct sockaddr *)sasp;
char *ptr; char *ptr;
char c, *orig; char c, *orig;
int i; int i;
......
...@@ -74,8 +74,9 @@ static struct service *tcp_name = NULL, *udp_name = NULL, *raw_name = NULL; ...@@ -74,8 +74,9 @@ static struct service *tcp_name = NULL, *udp_name = NULL, *raw_name = NULL;
static struct addr *INET_nn = NULL; /* addr-to-name cache */ static struct addr *INET_nn = NULL; /* addr-to-name cache */
static int INET_resolve(char *name, struct sockaddr_in *sin, int hostfirst) static int INET_resolve(char *name, struct sockaddr_storage *sasp, int hostfirst)
{ {
struct sockaddr_in *sin = (struct sockaddr_in *)sasp;
struct hostent *hp; struct hostent *hp;
struct netent *np; struct netent *np;
...@@ -138,9 +139,10 @@ static int INET_resolve(char *name, struct sockaddr_in *sin, int hostfirst) ...@@ -138,9 +139,10 @@ static int INET_resolve(char *name, struct sockaddr_in *sin, int hostfirst)
* & 0x4000: host instead of net, * & 0x4000: host instead of net,
* & 0x0fff: don't resolve * & 0x0fff: don't resolve
*/ */
static int INET_rresolve(char *name, size_t len, struct sockaddr_in *sin, static int INET_rresolve(char *name, size_t len, const struct sockaddr_storage *sasp,
int numeric, unsigned int netmask) int numeric, unsigned int netmask)
{ {
const struct sockaddr_in *sin = (const struct sockaddr_in *)sasp;
struct hostent *ent; struct hostent *ent;
struct netent *np; struct netent *np;
struct addr *pn; struct addr *pn;
...@@ -249,42 +251,39 @@ static const char *INET_print(const char *ptr) ...@@ -249,42 +251,39 @@ static const char *INET_print(const char *ptr)
/* Display an Internet socket address. */ /* Display an Internet socket address. */
static const char *INET_sprint(const struct sockaddr *sap, int numeric) static const char *INET_sprint(const struct sockaddr_storage *sasp, int numeric)
{ {
static char buff[128]; static char buff[128];
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) if (sasp->ss_family == 0xFFFF || sasp->ss_family == 0)
return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff)); return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff));
if (INET_rresolve(buff, sizeof(buff), (struct sockaddr_in *) sap, if (INET_rresolve(buff, sizeof(buff), sasp, numeric, 0xffffff00) != 0)
numeric, 0xffffff00) != 0)
return (NULL); return (NULL);
return (buff); return (buff);
} }
char *INET_sprintmask(struct sockaddr *sap, int numeric, char *INET_sprintmask(const struct sockaddr_storage *sasp, int numeric,
unsigned int netmask) unsigned int netmask)
{ {
static char buff[128]; static char buff[128];
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) if (sasp->ss_family == 0xFFFF || sasp->ss_family == 0)
return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff)); return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff));
if (INET_rresolve(buff, sizeof(buff), (struct sockaddr_in *) sap, if (INET_rresolve(buff, sizeof(buff), sasp, numeric, netmask) != 0)
numeric, netmask) != 0)
return (NULL); return (NULL);
return (buff); return (buff);
} }
static int INET_getsock(char *bufp, struct sockaddr *sap) static int INET_getsock(char *bufp, struct sockaddr_storage *sasp)
{ {
char *sp = bufp, *bp; char *sp = bufp, *bp;
unsigned int i; unsigned int i;
unsigned val; unsigned val;
struct sockaddr_in *sin; struct sockaddr_in *sin = (struct sockaddr_in *)sasp;
sin = (struct sockaddr_in *) sap;
sin->sin_family = AF_INET; sin->sin_family = AF_INET;
sin->sin_port = 0; sin->sin_port = 0;
...@@ -318,19 +317,19 @@ static int INET_getsock(char *bufp, struct sockaddr *sap) ...@@ -318,19 +317,19 @@ static int INET_getsock(char *bufp, struct sockaddr *sap)
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_storage *sasp)
{ {
switch (type) { switch (type) {
case 1: case 1:
return (INET_getsock(bufp, sap)); return INET_getsock(bufp, sasp);
case 256: case 256:
return (INET_resolve(bufp, (struct sockaddr_in *) sap, 1)); return INET_resolve(bufp, sasp, 1);
default: default:
return (INET_resolve(bufp, (struct sockaddr_in *) sap, 0)); return INET_resolve(bufp, sasp, 0);
} }
} }
static int INET_getnetmask(char *adr, struct sockaddr *m, char *name) static int INET_getnetmask(char *adr, struct sockaddr_storage *m, char *name)
{ {
struct sockaddr_in *mask = (struct sockaddr_in *) m; struct sockaddr_in *mask = (struct sockaddr_in *) m;
char *slash, *end; char *slash, *end;
......
...@@ -59,7 +59,7 @@ static char *fix_v4_address(char *buf, const struct in6_addr *in6) ...@@ -59,7 +59,7 @@ static char *fix_v4_address(char *buf, const struct in6_addr *in6)
return buf; return buf;
} }
static int INET6_resolve(char *name, struct sockaddr_in6 *sin6) static int INET6_resolve(char *name, struct sockaddr_storage *sasp)
{ {
struct addrinfo req, *ai; struct addrinfo req, *ai;
int s; int s;
...@@ -70,7 +70,7 @@ static int INET6_resolve(char *name, struct sockaddr_in6 *sin6) ...@@ -70,7 +70,7 @@ static int INET6_resolve(char *name, struct sockaddr_in6 *sin6)
fprintf(stderr, "getaddrinfo: %s: %d\n", name, s); fprintf(stderr, "getaddrinfo: %s: %d\n", name, s);
return -1; return -1;
} }
memcpy(sin6, ai->ai_addr, sizeof(struct sockaddr_in6)); memcpy(sasp, ai->ai_addr, sizeof(struct sockaddr_in6));
freeaddrinfo(ai); freeaddrinfo(ai);
...@@ -85,8 +85,9 @@ static int INET6_resolve(char *name, struct sockaddr_in6 *sin6) ...@@ -85,8 +85,9 @@ static int INET6_resolve(char *name, struct sockaddr_in6 *sin6)
static int INET6_rresolve(char *name, size_t namelen, static int INET6_rresolve(char *name, size_t namelen,
struct sockaddr_in6 *sin6, int numeric) const struct sockaddr_storage *sasp, int numeric)
{ {
const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sasp;
/* Grmpf. -FvK */ /* Grmpf. -FvK */
if (sin6->sin6_family != AF_INET6) { if (sin6->sin6_family != AF_INET6) {
#ifdef DEBUG #ifdef DEBUG
...@@ -108,7 +109,7 @@ static int INET6_rresolve(char *name, size_t namelen, ...@@ -108,7 +109,7 @@ static int INET6_rresolve(char *name, size_t namelen,
return (0); return (0);
} }
if (getnameinfo((struct sockaddr *) sin6, sizeof(struct sockaddr_in6), if (getnameinfo((const struct sockaddr *)sasp, sizeof(struct sockaddr_in6),
name, namelen , NULL, 0, 0)) { name, namelen , NULL, 0, 0)) {
inet_ntop( AF_INET6, &sin6->sin6_addr, name, namelen); inet_ntop( AF_INET6, &sin6->sin6_addr, name, namelen);
} }
...@@ -136,25 +137,24 @@ static const char *INET6_print(const char *ptr) ...@@ -136,25 +137,24 @@ static const char *INET6_print(const char *ptr)
/* Display an Internet socket address. */ /* Display an Internet socket address. */
/* dirty! struct sockaddr usually doesn't suffer for inet6 addresses, fst. */ /* dirty! struct sockaddr usually doesn't suffer for inet6 addresses, fst. */
static const char *INET6_sprint(const struct sockaddr *sap, int numeric) static const char *INET6_sprint(const struct sockaddr_storage *sasp, int numeric)
{ {
static char buff[128]; static char buff[128];
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) if (sasp->ss_family == 0xFFFF || sasp->ss_family == 0)
return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff)); return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff));
if (INET6_rresolve(buff, sizeof(buff), if (INET6_rresolve(buff, sizeof(buff), sasp, numeric) != 0)
(struct sockaddr_in6 *) sap, numeric) != 0)
return safe_strncpy(buff, _("[UNKNOWN]"), sizeof(buff)); return safe_strncpy(buff, _("[UNKNOWN]"), sizeof(buff));
return (fix_v4_address(buff, &((struct sockaddr_in6 *)sap)->sin6_addr)); return (fix_v4_address(buff, &((struct sockaddr_in6 *)sasp)->sin6_addr));
} }
static int INET6_getsock(char *bufp, struct sockaddr *sap) static int INET6_getsock(char *bufp, struct sockaddr_storage *sasp)
{ {
struct sockaddr_in6 *sin6; struct sockaddr_in6 *sin6;
char *p; char *p;
sin6 = (struct sockaddr_in6 *) sap; sin6 = (struct sockaddr_in6 *) sasp;
sin6->sin6_family = AF_INET6; sin6->sin6_family = AF_INET6;
sin6->sin6_port = 0; sin6->sin6_port = 0;
sin6->sin6_scope_id = 0; sin6->sin6_scope_id = 0;
...@@ -168,13 +168,13 @@ static int INET6_getsock(char *bufp, struct sockaddr *sap) ...@@ -168,13 +168,13 @@ static int INET6_getsock(char *bufp, struct sockaddr *sap)
return 16; /* ?;) */ return 16; /* ?;) */
} }
static int INET6_input(int type, char *bufp, struct sockaddr *sap) static int INET6_input(int type, char *bufp, struct sockaddr_storage *sasp)
{ {
switch (type) { switch (type) {
case 1: case 1:
return (INET6_getsock(bufp, sap)); return INET6_getsock(bufp, sasp);
default: default:
return (INET6_resolve(bufp, (struct sockaddr_in6 *) sap)); return INET6_resolve(bufp, sasp);
} }
} }
......
...@@ -58,7 +58,7 @@ int rprint_fib6(int ext, int numeric) ...@@ -58,7 +58,7 @@ int rprint_fib6(int ext, int numeric)
{ {
char buff[4096], iface[16], flags[16]; char buff[4096], iface[16], flags[16];
char addr6[128], naddr6[128]; char addr6[128], naddr6[128];
struct sockaddr_in6 saddr6, snaddr6; struct sockaddr_storage sas, sasn;
int num, iflags, metric, refcnt, use, prefix_len, slen; int num, iflags, metric, refcnt, use, prefix_len, slen;
FILE *fp = fopen(_PATH_PROCNET_ROUTE6, "r"); FILE *fp = fopen(_PATH_PROCNET_ROUTE6, "r");
...@@ -104,18 +104,18 @@ int rprint_fib6(int ext, int numeric) ...@@ -104,18 +104,18 @@ int rprint_fib6(int ext, int numeric)
snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s", snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s",
addr6p[0], addr6p[1], addr6p[2], addr6p[3], addr6p[0], addr6p[1], addr6p[2], addr6p[3],
addr6p[4], addr6p[5], addr6p[6], addr6p[7]); addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
inet6_aftype.input(1, addr6, (struct sockaddr *) &saddr6); inet6_aftype.input(1, addr6, &sas);
snprintf(addr6, sizeof(addr6), "%s/%d", snprintf(addr6, sizeof(addr6), "%s/%d",
inet6_aftype.sprint((struct sockaddr *) &saddr6, numeric), inet6_aftype.sprint(&sas, numeric),
prefix_len); prefix_len);
/* Fetch and resolve the nexthop address. */ /* Fetch and resolve the nexthop address. */
snprintf(naddr6, sizeof(naddr6), "%s:%s:%s:%s:%s:%s:%s:%s", snprintf(naddr6, sizeof(naddr6), "%s:%s:%s:%s:%s:%s:%s:%s",
naddr6p[0], naddr6p[1], naddr6p[2], naddr6p[3], naddr6p[0], naddr6p[1], naddr6p[2], naddr6p[3],
naddr6p[4], naddr6p[5], naddr6p[6], naddr6p[7]); naddr6p[4], naddr6p[5], naddr6p[6], naddr6p[7]);
inet6_aftype.input(1, naddr6, (struct sockaddr *) &snaddr6); inet6_aftype.input(1, naddr6, &sasn);
snprintf(naddr6, sizeof(naddr6), "%s", snprintf(naddr6, sizeof(naddr6), "%s",
inet6_aftype.sprint((struct sockaddr *) &snaddr6, numeric)); inet6_aftype.sprint(&sasn, numeric));
/* Decode the flags. */ /* Decode the flags. */
...@@ -158,7 +158,7 @@ int rprint_cache6(int ext, int numeric) ...@@ -158,7 +158,7 @@ int rprint_cache6(int ext, int numeric)
{ {
char buff[4096], iface[16], flags[16]; char buff[4096], iface[16], flags[16];
char addr6[128], haddr[20], statestr[20]; char addr6[128], haddr[20], statestr[20];
struct sockaddr_in6 saddr6; struct sockaddr_storage sas;
int type, refcnt, prefix_len, location, state, gc; int type, refcnt, prefix_len, location, state, gc;
long tstamp, expire, ndflags, reachable, stale, delete; long tstamp, expire, ndflags, reachable, stale, delete;
FILE *fp = fopen(_PATH_PROCNET_NDISC, "r"); FILE *fp = fopen(_PATH_PROCNET_NDISC, "r");
...@@ -192,9 +192,9 @@ int rprint_cache6(int ext, int numeric) ...@@ -192,9 +192,9 @@ int rprint_cache6(int ext, int numeric)
snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s", snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s",
addr6p[0], addr6p[1], addr6p[2], addr6p[3], addr6p[0], addr6p[1], addr6p[2], addr6p[3],
addr6p[4], addr6p[5], addr6p[6], addr6p[7]); addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
inet6_aftype.input(1, addr6, (struct sockaddr *) &saddr6); inet6_aftype.input(1, addr6, &sas);
snprintf(addr6, sizeof(addr6), "%s/%d", snprintf(addr6, sizeof(addr6), "%s/%d",
inet6_aftype.sprint((struct sockaddr *) &saddr6, numeric), inet6_aftype.sprint(&sas, numeric),
prefix_len); prefix_len);
/* Fetch the hardware address. */ /* Fetch the hardware address. */
......
...@@ -55,7 +55,8 @@ static int INET6_setroute(int action, int options, char **args) ...@@ -55,7 +55,8 @@ static int INET6_setroute(int action, int options, char **args)
{ {
struct in6_rtmsg rt; struct in6_rtmsg rt;
struct ifreq ifr; struct ifreq ifr;
struct sockaddr_in6 sa6; struct sockaddr_storage sas;
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&sas;
char target[128], gateway[128] = "NONE"; char target[128], gateway[128] = "NONE";
int metric, prefix_len; int metric, prefix_len;
char *devname = NULL; char *devname = NULL;
...@@ -67,7 +68,7 @@ static int INET6_setroute(int action, int options, char **args) ...@@ -67,7 +68,7 @@ static int INET6_setroute(int action, int options, char **args)
safe_strncpy(target, *args++, sizeof(target)); safe_strncpy(target, *args++, sizeof(target));
if (!strcmp(target, "default")) { if (!strcmp(target, "default")) {
prefix_len = 0; prefix_len = 0;
memset(&sa6, 0, sizeof(sa6)); memset(&sas, 0, sizeof(sas));
} else { } else {
if ((cp = strchr(target, '/'))) { if ((cp = strchr(target, '/'))) {
prefix_len = atol(cp + 1); prefix_len = atol(cp + 1);
...@@ -77,8 +78,8 @@ static int INET6_setroute(int action, int options, char **args) ...@@ -77,8 +78,8 @@ static int INET6_setroute(int action, int options, char **args)
} else { } else {
prefix_len = 128; prefix_len = 128;
} }
if (inet6_aftype.input(1, target, (struct sockaddr *) &sa6) < 0 if (inet6_aftype.input(1, target, &sas) < 0
&& inet6_aftype.input(0, target, (struct sockaddr *) &sa6) < 0) { && inet6_aftype.input(0, target, &sas) < 0) {
inet6_aftype.herror(target); inet6_aftype.herror(target);
return (1); return (1);
} }
...@@ -87,7 +88,7 @@ static int INET6_setroute(int action, int options, char **args) ...@@ -87,7 +88,7 @@ static int INET6_setroute(int action, int options, char **args)
/* Clean out the RTREQ structure. */ /* Clean out the RTREQ structure. */
memset((char *) &rt, 0, sizeof(struct in6_rtmsg)); memset((char *) &rt, 0, sizeof(struct in6_rtmsg));
memcpy(&rt.rtmsg_dst, sa6.sin6_addr.s6_addr, sizeof(struct in6_addr)); memcpy(&rt.rtmsg_dst, sin6->sin6_addr.s6_addr, sizeof(struct in6_addr));
/* Fill in the other fields. */ /* Fill in the other fields. */
rt.rtmsg_flags = RTF_UP; rt.rtmsg_flags = RTF_UP;
...@@ -114,12 +115,11 @@ static int INET6_setroute(int action, int options, char **args) ...@@ -114,12 +115,11 @@ static int INET6_setroute(int action, int options, char **args)
if (rt.rtmsg_flags & RTF_GATEWAY) if (rt.rtmsg_flags & RTF_GATEWAY)
return usage(E_OPTERR); return usage(E_OPTERR);
safe_strncpy(gateway, *args, sizeof(gateway)); safe_strncpy(gateway, *args, sizeof(gateway));
if (inet6_aftype.input(1, gateway, if (inet6_aftype.input(1, gateway, &sas) < 0) {
(struct sockaddr *) &sa6) < 0) {
inet6_aftype.herror(gateway); inet6_aftype.herror(gateway);
return (E_LOOKUP); return (E_LOOKUP);
} }
memcpy(&rt.rtmsg_gateway, sa6.sin6_addr.s6_addr, memcpy(&rt.rtmsg_gateway, sin6->sin6_addr.s6_addr,
sizeof(struct in6_addr)); sizeof(struct in6_addr));
rt.rtmsg_flags |= RTF_GATEWAY; rt.rtmsg_flags |= RTF_GATEWAY;
args++; args++;
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include "util.h" #include "util.h"
extern struct aftype inet_aftype; extern struct aftype inet_aftype;
extern char *INET_sprintmask(struct sockaddr *sap, int numeric, extern char *INET_sprintmask(const struct sockaddr_storage *sap, int numeric,
unsigned int netmask); unsigned int netmask);
int rprint_fib(int ext, int numeric) int rprint_fib(int ext, int numeric)
...@@ -87,7 +87,7 @@ int rprint_fib(int ext, int numeric) ...@@ -87,7 +87,7 @@ int rprint_fib(int ext, int numeric)
return 1; return 1;
while (fgets(buff, 1023, fp)) { while (fgets(buff, 1023, fp)) {
struct sockaddr snet_target, snet_gateway, snet_mask; struct sockaddr_storage snet_target, snet_gateway, snet_mask;
struct sockaddr_in *sin_netmask; struct sockaddr_in *sin_netmask;
num = sscanf(buff, fmt, num = sscanf(buff, fmt,
...@@ -210,7 +210,7 @@ int rprint_cache(int ext, int numeric) ...@@ -210,7 +210,7 @@ int rprint_cache(int ext, int numeric)
char buff[1024], iface[17], flags[64]; char buff[1024], iface[17], flags[64];
char gate_addr[128], dest_addr[128], specdst[128]; char gate_addr[128], dest_addr[128], specdst[128];
char src_addr[128]; char src_addr[128];
struct sockaddr snet; struct sockaddr_storage snet;
unsigned int iflags; unsigned int iflags;
int num, format, metric, refcnt, use, mss, window, irtt, hh, hhref, hhuptod, arp, tos; int num, format, metric, refcnt, use, mss, window, irtt, hh, hhref, hhuptod, arp, tos;
char *fmt = NULL; char *fmt = NULL;
......
...@@ -65,6 +65,7 @@ static int INET_setroute(int action, int options, char **args) ...@@ -65,6 +65,7 @@ static int INET_setroute(int action, int options, char **args)
char target[128], gateway[128] = "NONE", netmask[128] = "default"; char target[128], gateway[128] = "NONE", netmask[128] = "default";
int xflag, isnet; int xflag, isnet;
long clk_tck = ticks_per_second(); long clk_tck = ticks_per_second();
struct sockaddr_storage sas;
xflag = 0; xflag = 0;
...@@ -86,12 +87,13 @@ static int INET_setroute(int action, int options, char **args) ...@@ -86,12 +87,13 @@ static int INET_setroute(int action, int options, char **args)
/* Special hack for /prefix syntax */ /* Special hack for /prefix syntax */
{ {
union { union {
struct sockaddr_storage sas;
struct sockaddr_in m; struct sockaddr_in m;
struct sockaddr d; struct sockaddr d;
} mask; } mask;
int n; int n;
n = inet_aftype.getmask(target, &mask.d, netmask); n = inet_aftype.getmask(target, &mask.sas, netmask);
if (n < 0) if (n < 0)
return usage(E_OPTERR); return usage(E_OPTERR);
else if (n) else if (n)
...@@ -99,10 +101,11 @@ static int INET_setroute(int action, int options, char **args) ...@@ -99,10 +101,11 @@ static int INET_setroute(int action, int options, char **args)
} }
/* Prefer hostname lookup is -host flag was given */ /* Prefer hostname lookup is -host flag was given */
if ((isnet = inet_aftype.input((xflag!=2? 0: 256), target, &rt.rt_dst)) < 0) { if ((isnet = inet_aftype.input((xflag!=2? 0: 256), target, &sas)) < 0) {
inet_aftype.herror(target); inet_aftype.herror(target);
return (E_LOOKUP); return (E_LOOKUP);
} }
memcpy(&rt.rt_dst, &sas, sizeof(rt.rt_dst));
switch (xflag) { switch (xflag) {
case 1: case 1:
isnet = 1; break; isnet = 1; break;
...@@ -132,31 +135,34 @@ static int INET_setroute(int action, int options, char **args) ...@@ -132,31 +135,34 @@ static int INET_setroute(int action, int options, char **args)
continue; continue;
} }
if (!strcmp(*args, "netmask")) { if (!strcmp(*args, "netmask")) {
struct sockaddr mask; struct sockaddr_storage sas;
struct sockaddr *mask = (struct sockaddr *)&sas;
args++; args++;
if (!*args || mask_in_addr(rt)) if (!*args || mask_in_addr(rt))
return usage(E_OPTERR); return usage(E_OPTERR);
safe_strncpy(netmask, *args, (sizeof netmask)); safe_strncpy(netmask, *args, (sizeof netmask));
if ((isnet = inet_aftype.input(0, netmask, &mask)) < 0) { if ((isnet = inet_aftype.input(0, netmask, &sas)) < 0) {
inet_aftype.herror(netmask); inet_aftype.herror(netmask);
return (E_LOOKUP); return (E_LOOKUP);
} }
rt.rt_genmask = full_mask(mask); rt.rt_genmask = full_mask(*mask);
args++; args++;
continue; continue;
} }
if (!strcmp(*args, "gw") || !strcmp(*args, "gateway")) { if (!strcmp(*args, "gw") || !strcmp(*args, "gateway")) {
struct sockaddr_storage sas;
args++; args++;
if (!*args) if (!*args)
return usage(E_OPTERR); return usage(E_OPTERR);
if (rt.rt_flags & RTF_GATEWAY) if (rt.rt_flags & RTF_GATEWAY)
return usage(E_OPTERR); return usage(E_OPTERR);
safe_strncpy(gateway, *args, (sizeof gateway)); safe_strncpy(gateway, *args, (sizeof gateway));
if ((isnet = inet_aftype.input(256, gateway, &rt.rt_gateway)) < 0) { if ((isnet = inet_aftype.input(256, gateway, &sas)) < 0) {
inet_aftype.herror(gateway); inet_aftype.herror(gateway);
return (E_LOOKUP); return (E_LOOKUP);
} }
memcpy(&rt.rt_gateway, &sas, sizeof(rt.rt_gateway));
if (isnet) { if (isnet) {
fprintf(stderr, _("route: %s: cannot use a NETWORK as gateway!\n"), fprintf(stderr, _("route: %s: cannot use a NETWORK as gateway!\n"),
gateway); gateway);
......
...@@ -667,7 +667,7 @@ void ife_print_long(struct interface *ptr) ...@@ -667,7 +667,7 @@ void ife_print_long(struct interface *ptr)
#if HAVE_AFINET6 #if HAVE_AFINET6
FILE *f; FILE *f;
char addr6[40], devname[21]; char addr6[40], devname[21];
struct sockaddr_in6 sap; struct sockaddr_storage sas;
int plen, scope, dad_status, if_idx; int plen, scope, dad_status, if_idx;
extern struct aftype inet6_aftype; extern struct aftype inet6_aftype;
char addr6p[8][5]; char addr6p[8][5];
...@@ -743,13 +743,13 @@ void ife_print_long(struct interface *ptr) ...@@ -743,13 +743,13 @@ void ife_print_long(struct interface *ptr)
#if HAVE_AFINET #if HAVE_AFINET
if (ptr->has_ip) { if (ptr->has_ip) {
printf(_(" %s %s"), ap->name, printf(_(" %s %s"), ap->name,
ap->sprint(&ptr->addr, 1)); ap->sprint(&ptr->addr_sas, 1));
printf(_(" netmask %s"), ap->sprint(&ptr->netmask, 1)); printf(_(" netmask %s"), ap->sprint(&ptr->netmask_sas, 1));
if (ptr->flags & IFF_BROADCAST) { if (ptr->flags & IFF_BROADCAST) {
printf(_(" broadcast %s"), ap->sprint(&ptr->broadaddr, 1)); printf(_(" broadcast %s"), ap->sprint(&ptr->broadaddr_sas, 1));
} }
if (ptr->flags & IFF_POINTOPOINT) { if (ptr->flags & IFF_POINTOPOINT) {
printf(_(" destination %s"), ap->sprint(&ptr->dstaddr, 1)); printf(_(" destination %s"), ap->sprint(&ptr->dstaddr_sas, 1));
} }
printf("\n"); printf("\n");
} }
...@@ -767,10 +767,10 @@ void ife_print_long(struct interface *ptr) ...@@ -767,10 +767,10 @@ void ife_print_long(struct interface *ptr)
sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s", sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s",
addr6p[0], addr6p[1], addr6p[2], addr6p[3], addr6p[0], addr6p[1], addr6p[2], addr6p[3],
addr6p[4], addr6p[5], addr6p[6], addr6p[7]); addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
inet6_aftype.input(1, addr6, (struct sockaddr *) &sap); inet6_aftype.input(1, addr6, &sas);
printf(_(" %s %s prefixlen %d"), printf(_(" %s %s prefixlen %d"),
inet6_aftype.name, inet6_aftype.name,
inet6_aftype.sprint((struct sockaddr *) &sap, 1), inet6_aftype.sprint(&sas, 1),
plen); plen);
printf(_(" scopeid 0x%x"), scope); printf(_(" scopeid 0x%x"), scope);
...@@ -805,16 +805,16 @@ void ife_print_long(struct interface *ptr) ...@@ -805,16 +805,16 @@ void ife_print_long(struct interface *ptr)
if (ipxtype != NULL) { if (ipxtype != NULL) {
if (ptr->has_ipx_bb) if (ptr->has_ipx_bb)
printf(_(" %s Ethernet-II %s\n"), printf(_(" %s Ethernet-II %s\n"),
ipxtype->name, ipxtype->sprint(&ptr->ipxaddr_bb, 1)); ipxtype->name, ipxtype->sprint(&ptr->ipxaddr_bb_sas, 1));
if (ptr->has_ipx_sn) if (ptr->has_ipx_sn)
printf(_(" %s Ethernet-SNAP %s\n"), printf(_(" %s Ethernet-SNAP %s\n"),
ipxtype->name, ipxtype->sprint(&ptr->ipxaddr_sn, 1)); ipxtype->name, ipxtype->sprint(&ptr->ipxaddr_sn_sas, 1));
if (ptr->has_ipx_e2) if (ptr->has_ipx_e2)
printf(_(" %s Ethernet802.2 %s\n"), printf(_(" %s Ethernet802.2 %s\n"),
ipxtype->name, ipxtype->sprint(&ptr->ipxaddr_e2, 1)); ipxtype->name, ipxtype->sprint(&ptr->ipxaddr_e2_sas, 1));
if (ptr->has_ipx_e3) if (ptr->has_ipx_e3)
printf(_(" %s Ethernet802.3 %s\n"), printf(_(" %s Ethernet802.3 %s\n"),
ipxtype->name, ipxtype->sprint(&ptr->ipxaddr_e3, 1)); ipxtype->name, ipxtype->sprint(&ptr->ipxaddr_e3_sas, 1));
} }
#endif #endif
...@@ -823,7 +823,7 @@ void ife_print_long(struct interface *ptr) ...@@ -823,7 +823,7 @@ void ife_print_long(struct interface *ptr)
ddptype = get_afntype(AF_APPLETALK); ddptype = get_afntype(AF_APPLETALK);
if (ddptype != NULL) { if (ddptype != NULL) {
if (ptr->has_ddp) if (ptr->has_ddp)
printf(_(" %s %s\n"), ddptype->name, ddptype->sprint(&ptr->ddpaddr, 1)); printf(_(" %s %s\n"), ddptype->name, ddptype->sprint(&ptr->ddpaddr_sas, 1));
} }
#endif #endif
...@@ -832,7 +832,7 @@ void ife_print_long(struct interface *ptr) ...@@ -832,7 +832,7 @@ void ife_print_long(struct interface *ptr)
ectype = get_afntype(AF_ECONET); ectype = get_afntype(AF_ECONET);
if (ectype != NULL) { if (ectype != NULL) {
if (ptr->has_econet) if (ptr->has_econet)
printf(_(" %s %s\n"), ectype->name, ectype->sprint(&ptr->ecaddr, 1)); printf(_(" %s %s\n"), ectype->name, ectype->sprint(&ptr->ecaddr_sas, 1));
} }
#endif #endif
......
...@@ -73,8 +73,9 @@ static const char *IPX_print(const char *ptr) ...@@ -73,8 +73,9 @@ static const char *IPX_print(const char *ptr)
/* Display a ipx domain address. */ /* Display a ipx domain address. */
static const char *IPX_sprint(const struct sockaddr *sap, int numeric) static const char *IPX_sprint(const struct sockaddr_storage *sasp, int numeric)
{ {
const struct sockaddr *sap = (const struct sockaddr *)sasp;
static char buf[64]; static char buf[64];
if (sap->sa_family != AF_IPX) if (sap->sa_family != AF_IPX)
...@@ -83,11 +84,11 @@ static const char *IPX_sprint(const struct sockaddr *sap, int numeric) ...@@ -83,11 +84,11 @@ static const char *IPX_sprint(const struct sockaddr *sap, int numeric)
} }
static int IPX_getsock(char *bufp, struct sockaddr *sap) static int IPX_getsock(char *bufp, struct sockaddr_storage *sasp)
{ {
char *sp = bufp, *bp; char *sp = bufp, *bp;
unsigned int i; unsigned int i;
struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) sap; struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) sasp;
sipx->sipx_port = 0; sipx->sipx_port = 0;
...@@ -124,9 +125,9 @@ static int IPX_getsock(char *bufp, struct sockaddr *sap) ...@@ -124,9 +125,9 @@ static int IPX_getsock(char *bufp, struct sockaddr *sap)
/* 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_storage *sasp)
{ {
struct sockaddr_ipx *sai = (struct sockaddr_ipx *) sap; struct sockaddr_ipx *sai = (struct sockaddr_ipx *) sasp;
unsigned long netnum; unsigned long netnum;
char *ep; char *ep;
...@@ -156,7 +157,7 @@ static int IPX_input(int type, char *bufp, struct sockaddr *sap) ...@@ -156,7 +157,7 @@ static int IPX_input(int type, char *bufp, struct sockaddr *sap)
return (-3); return (-3);
bufp = ep + 1; bufp = ep + 1;
} }
return (IPX_getsock(bufp, sap)); return IPX_getsock(bufp, sasp);
} }
......
...@@ -41,7 +41,7 @@ int IPX_rprint(int options) ...@@ -41,7 +41,7 @@ int IPX_rprint(int options)
int num; int num;
FILE *fp; FILE *fp;
const struct aftype *ap; const struct aftype *ap;
struct sockaddr sa; struct sockaddr_storage sas;
fp = fopen(_PATH_PROCNET_IPX_ROUTE1, "r"); fp = fopen(_PATH_PROCNET_IPX_ROUTE1, "r");
...@@ -72,16 +72,16 @@ int IPX_rprint(int options) ...@@ -72,16 +72,16 @@ int IPX_rprint(int options)
continue; continue;
/* Fetch and resolve the Destination */ /* Fetch and resolve the Destination */
(void) ap->input(1, net, &sa); (void) ap->input(1, net, &sas);
safe_strncpy(net, ap->sprint(&sa, numeric), sizeof(net)); safe_strncpy(net, ap->sprint(&sas, numeric), sizeof(net));
/* Fetch and resolve the Router Net */ /* Fetch and resolve the Router Net */
(void) ap->input(1, router_net, &sa); (void) ap->input(1, router_net, &sas);
safe_strncpy(router_net, ap->sprint(&sa, numeric), sizeof(router_net)); safe_strncpy(router_net, ap->sprint(&sas, numeric), sizeof(router_net));
/* Fetch and resolve the Router Node */ /* Fetch and resolve the Router Node */
(void) ap->input(2, router_node, &sa); (void) ap->input(2, router_node, &sas);
safe_strncpy(router_node, ap->sprint(&sa, numeric), sizeof(router_node)); safe_strncpy(router_node, ap->sprint(&sas, numeric), sizeof(router_node));
printf("%-25s %-25s %-25s\n", net, router_net, router_node); printf("%-25s %-25s %-25s\n", net, router_net, router_node);
} }
......
...@@ -47,7 +47,14 @@ ...@@ -47,7 +47,14 @@
struct masq { struct masq {
unsigned long expires; /* Expiration timer */ unsigned long expires; /* Expiration timer */
char *proto; /* Which protocol are we talking? */ char *proto; /* Which protocol are we talking? */
struct sockaddr_in src, dst; /* Source and destination IP addresses */ union {
struct sockaddr_storage src_sas;
struct sockaddr_in src; /* Source IP address */
};
union {
struct sockaddr_storage dst_sas;
struct sockaddr_in dst; /* Destination IP address */
};
unsigned short sport, dport; /* Source and destination ports */ unsigned short sport, dport; /* Source and destination ports */
unsigned short mport; /* Masqueraded port */ unsigned short mport; /* Masqueraded port */
unsigned long initseq; /* Add delta from this seq. on */ unsigned long initseq; /* Add delta from this seq. on */
...@@ -79,8 +86,8 @@ static void print_masq(struct masq *ms, int numeric_host, int numeric_port, ...@@ -79,8 +86,8 @@ static void print_masq(struct masq *ms, int numeric_host, int numeric_port,
printf("%10lu %5hd - ", ms->initseq, printf("%10lu %5hd - ", ms->initseq,
ms->delta); ms->delta);
} }
printf("%-20s ", ap->sprint((struct sockaddr *) &(ms->src), numeric_host)); printf("%-20s ", ap->sprint(&ms->src_sas, numeric_host));
printf("%-20s ", ap->sprint((struct sockaddr *) &(ms->dst), numeric_host)); printf("%-20s ", ap->sprint(&ms->dst_sas, numeric_host));
printf("%s -> ", get_sname(ms->sport, ms->proto, numeric_port)); printf("%s -> ", get_sname(ms->sport, ms->proto, numeric_port));
printf("%s", get_sname(ms->dport, ms->proto, numeric_port)); printf("%s", get_sname(ms->dport, ms->proto, numeric_port));
......
...@@ -39,14 +39,14 @@ struct aftype { ...@@ -39,14 +39,14 @@ struct aftype {
int af; int af;
int alen; int alen;
const char *(*print) (const char *); const char *(*print) (const char *);
const char *(*sprint) (const struct sockaddr *, int numeric); const char *(*sprint) (const struct sockaddr_storage *, int numeric);
int (*input) (int type, char *bufp, struct sockaddr *); int (*input) (int type, char *bufp, struct sockaddr_storage *);
void (*herror) (const char *text); void (*herror) (const char *text);
int (*rprint) (int options); int (*rprint) (int options);
int (*rinput) (int typ, int ext, char **argv); int (*rinput) (int typ, int ext, char **argv);
/* may modify src */ /* may modify src */
int (*getmask) (char *src, struct sockaddr *mask, char *name); int (*getmask) (char *src, struct sockaddr_storage *mask, char *name);
int fd; int fd;
const char *flag_file; const char *flag_file;
...@@ -61,7 +61,7 @@ struct hwtype { ...@@ -61,7 +61,7 @@ struct hwtype {
int type; int type;
int alen; int alen;
const char *(*print) (const char *); const char *(*print) (const char *);
int (*input) (char *, struct sockaddr *); int (*input) (char *, struct sockaddr_storage *);
int (*activate) (int fd); int (*activate) (int fd);
int suppress_null_addr; int suppress_null_addr;
}; };
......
...@@ -71,12 +71,14 @@ static const char *NETROM_print(const char *ptr) ...@@ -71,12 +71,14 @@ static const char *NETROM_print(const char *ptr)
/* Display an AX.25 socket address. */ /* Display an AX.25 socket address. */
static const char *NETROM_sprint(const struct sockaddr *sap, int numeric) static const char *NETROM_sprint(const struct sockaddr_storage *sasp, int numeric)
{ {
const struct sockaddr_ax25 *ax25_sap = (const struct sockaddr_ax25 *)sasp;
const struct sockaddr *sap = (const struct sockaddr *)sasp;
char buf[64]; char buf[64];
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf)); return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf));
return (NETROM_print(((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call)); return NETROM_print(ax25_sap->sax25_call.ax25_call);
} }
#ifdef DEBUG #ifdef DEBUG
...@@ -85,14 +87,16 @@ static const char *NETROM_sprint(const struct sockaddr *sap, int numeric) ...@@ -85,14 +87,16 @@ static const char *NETROM_sprint(const struct sockaddr *sap, int numeric)
#define _DEBUG 0 #define _DEBUG 0
#endif #endif
static int NETROM_input(int type, char *bufp, struct sockaddr *sap) static int NETROM_input(int type, char *bufp, struct sockaddr_storage *sasp)
{ {
struct sockaddr_ax25 *ax25_sap = (struct sockaddr_ax25 *)sasp;
struct sockaddr *sap = (struct sockaddr *)sasp;
char *ptr; char *ptr;
char *orig, c; char *orig, c;
unsigned int i; unsigned int i;
sap->sa_family = netrom_aftype.af; sap->sa_family = netrom_aftype.af;
ptr = ((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call; ptr = ax25_sap->sax25_call.ax25_call;
/* First, scan and convert the basic callsign. */ /* First, scan and convert the basic callsign. */
orig = bufp; orig = bufp;
...@@ -155,9 +159,10 @@ static void NETROM_herror(const char *text) ...@@ -155,9 +159,10 @@ static void NETROM_herror(const char *text)
} }
static int NETROM_hinput(char *bufp, struct sockaddr *sap) static int NETROM_hinput(char *bufp, struct sockaddr_storage *sasp)
{ {
if (NETROM_input(0, bufp, sap) < 0) struct sockaddr *sap = (struct sockaddr *)sasp;
if (NETROM_input(0, bufp, sasp) < 0)
return (-1); return (-1);
sap->sa_family = ARPHRD_NETROM; sap->sa_family = ARPHRD_NETROM;
return (0); return (0);
......
...@@ -66,21 +66,24 @@ static const char * ...@@ -66,21 +66,24 @@ static const char *
/* Display a ROSE socket address. */ /* Display a ROSE socket address. */
static const char * static const char *
ROSE_sprint(const struct sockaddr *sap, int numeric) ROSE_sprint(const struct sockaddr_storage *sasp, int numeric)
{ {
const struct sockaddr_rose *rose_sap = (const struct sockaddr_rose *)sasp;
const struct sockaddr *sap = (const struct sockaddr *)sasp;
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return _("[NONE SET]"); return _("[NONE SET]");
return (ROSE_print(((struct sockaddr_rose *) sap)->srose_addr.rose_addr)); return ROSE_print(rose_sap->srose_addr.rose_addr);
} }
static int ROSE_input(int type, char *bufp, struct sockaddr *sap) static int ROSE_input(int type, char *bufp, struct sockaddr_storage *sasp)
{ {
struct sockaddr *sap = (struct sockaddr *)sasp;
char *ptr; char *ptr;
int i, o; int i, o;
sap->sa_family = rose_aftype.af; sap->sa_family = rose_aftype.af;
ptr = ((struct sockaddr_rose *) sap)->srose_addr.rose_addr; ptr = ((struct sockaddr_rose *) sasp)->srose_addr.rose_addr;
/* Node address the correct length ? */ /* Node address the correct length ? */
if (strlen(bufp) != 10) { if (strlen(bufp) != 10) {
...@@ -109,9 +112,10 @@ static void ROSE_herror(const char *text) ...@@ -109,9 +112,10 @@ static void ROSE_herror(const char *text)
} }
static int ROSE_hinput(char *bufp, struct sockaddr *sap) static int ROSE_hinput(char *bufp, struct sockaddr_storage *sasp)
{ {
if (ROSE_input(0, bufp, sap) < 0) struct sockaddr *sap = (struct sockaddr *)sasp;
if (ROSE_input(0, bufp, sasp) < 0)
return (-1); return (-1);
sap->sa_family = ARPHRD_ROSE; sap->sa_family = ARPHRD_ROSE;
return (0); return (0);
......
...@@ -52,8 +52,9 @@ pr_strip(const char *ptr) ...@@ -52,8 +52,9 @@ pr_strip(const char *ptr)
} }
static int static int
in_strip(char *bufp, struct sockaddr *sap) in_strip(char *bufp, struct sockaddr_storage *sasp)
{ {
struct sockaddr *sap = (struct sockaddr *)sasp;
int i,i0; int i,i0;
MetricomAddress *haddr = (MetricomAddress *) (sap->sa_data); MetricomAddress *haddr = (MetricomAddress *) (sap->sa_data);
......
...@@ -56,8 +56,9 @@ static const char *pr_tr(const char *ptr) ...@@ -56,8 +56,9 @@ static const char *pr_tr(const char *ptr)
#define _DEBUG 0 #define _DEBUG 0
#endif #endif
static int in_tr(char *bufp, struct sockaddr *sap) static int in_tr(char *bufp, struct sockaddr_storage *sasp)
{ {
struct sockaddr *sap = (struct sockaddr *)sasp;
char *ptr; char *ptr;
char c, *orig; char c, *orig;
int i, val; int i, val;
......
...@@ -27,7 +27,7 @@ static const char *pr_tunnel(const char *ptr) ...@@ -27,7 +27,7 @@ static const char *pr_tunnel(const char *ptr)
} }
static int in_tunnel(char *bufp, struct sockaddr *sap) static int in_tunnel(char *bufp, struct sockaddr_storage *sasp)
{ {
return (-1); return (-1);
} }
......
...@@ -48,8 +48,9 @@ static const char *UNSPEC_print(const char *ptr) ...@@ -48,8 +48,9 @@ static const char *UNSPEC_print(const char *ptr)
/* Display an UNSPEC socket address. */ /* Display an UNSPEC socket address. */
static const char *UNSPEC_sprint(const struct sockaddr *sap, int numeric) static const char *UNSPEC_sprint(const struct sockaddr_storage *sasp, int numeric)
{ {
const struct sockaddr *sap = (const struct sockaddr *)sasp;
static char buf[64]; static char buf[64];
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
...@@ -68,8 +69,9 @@ static const char *UNIX_print(const char *ptr) ...@@ -68,8 +69,9 @@ static const char *UNIX_print(const char *ptr)
/* Display a UNIX domain address. */ /* Display a UNIX domain address. */
static const char *UNIX_sprint(const struct sockaddr *sap, int numeric) static const char *UNIX_sprint(const struct sockaddr_storage *sasp, int numeric)
{ {
const struct sockaddr *sap = (const struct sockaddr *)sasp;
static char buf[64]; static char buf[64];
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
......
...@@ -65,11 +65,12 @@ X25_print(const char *ptr) ...@@ -65,11 +65,12 @@ X25_print(const char *ptr)
/* Display an X.25 socket address. */ /* Display an X.25 socket address. */
static const char * static const char *
X25_sprint(const struct sockaddr *sap, int numeric) X25_sprint(const struct sockaddr_storage *sasp, int numeric)
{ {
const struct sockaddr *sap = (const struct sockaddr *)sasp;
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return( _("[NONE SET]")); return( _("[NONE SET]"));
return(X25_print(((struct sockaddr_x25 *)sap)->sx25_addr.x25_addr)); return(X25_print(((struct sockaddr_x25 *)sasp)->sx25_addr.x25_addr));
} }
...@@ -77,8 +78,9 @@ X25_sprint(const struct sockaddr *sap, int numeric) ...@@ -77,8 +78,9 @@ X25_sprint(const struct sockaddr *sap, int numeric)
* return the sigdigits of the address * return the sigdigits of the address
*/ */
static int static int
X25_input(int type, char *bufp, struct sockaddr *sap) X25_input(int type, char *bufp, struct sockaddr_storage *sasp)
{ {
struct sockaddr *sap = (struct sockaddr *)sasp;
char *ptr; char *ptr;
char *p; char *p;
unsigned int sigdigits; unsigned int sigdigits;
...@@ -139,9 +141,10 @@ X25_herror(const char *text) ...@@ -139,9 +141,10 @@ X25_herror(const char *text)
static int static int
X25_hinput(char *bufp, struct sockaddr *sap) X25_hinput(char *bufp, struct sockaddr_storage *sasp)
{ {
if (X25_input(0, bufp, sap) < 0) return(-1); struct sockaddr *sap = (struct sockaddr *)sasp;
if (X25_input(0, bufp, sasp) < 0) return(-1);
sap->sa_family = ARPHRD_X25; sap->sa_family = ARPHRD_X25;
return(0); return(0);
} }
......
...@@ -56,7 +56,8 @@ static int usage(const int rc) ...@@ -56,7 +56,8 @@ static int usage(const int rc)
static int X25_setroute(int action, int options, char **args) static int X25_setroute(int action, int options, char **args)
{ {
struct x25_route_struct rt; struct x25_route_struct rt;
struct sockaddr_x25 sx25; struct sockaddr_storage sas;
struct sockaddr_x25 *sx25 = (struct sockaddr_x25 *)&sas;
char target[128]; char target[128];
signed int sigdigits; signed int sigdigits;
...@@ -69,14 +70,14 @@ static int X25_setroute(int action, int options, char **args) ...@@ -69,14 +70,14 @@ static int X25_setroute(int action, int options, char **args)
memset((char *) &rt, 0, sizeof(rt)); memset((char *) &rt, 0, sizeof(rt));
if ((sigdigits = x25_aftype.input(0, target, (struct sockaddr *)&sx25)) < 0) { if ((sigdigits = x25_aftype.input(0, target, &sas)) < 0) {
x25_aftype.herror(target); x25_aftype.herror(target);
return (E_LOOKUP); return (E_LOOKUP);
} }
rt.sigdigits=sigdigits; rt.sigdigits=sigdigits;
/* this works with 2.4 and 2.6 headers struct x25_address vs. typedef */ /* this works with 2.4 and 2.6 headers struct x25_address vs. typedef */
memcpy(&rt.address, &sx25.sx25_addr, sizeof(sx25.sx25_addr)); memcpy(&rt.address, &sx25->sx25_addr, sizeof(sx25->sx25_addr));
while (*args) { while (*args) {
if (!strcmp(*args,"device") || !strcmp(*args,"dev")) { if (!strcmp(*args,"device") || !strcmp(*args,"dev")) {
......
...@@ -613,7 +613,6 @@ static void igmp_do_one(int lnr, const char *line,const char *prot) ...@@ -613,7 +613,6 @@ static void igmp_do_one(int lnr, const char *line,const char *prot)
{ {
char mcast_addr[128]; char mcast_addr[128];
struct sockaddr_storage sas; struct sockaddr_storage sas;
struct sockaddr *sa = (struct sockaddr *)&sas;
struct sockaddr_in *sin = (struct sockaddr_in *)&sas; struct sockaddr_in *sin = (struct sockaddr_in *)&sas;
#if HAVE_AFINET6 #if HAVE_AFINET6
char addr6[INET6_ADDRSTRLEN]; char addr6[INET6_ADDRSTRLEN];
...@@ -656,7 +655,7 @@ static void igmp_do_one(int lnr, const char *line,const char *prot) ...@@ -656,7 +655,7 @@ static void igmp_do_one(int lnr, const char *line,const char *prot)
in6.s6_addr32[2] = htonl(in6.s6_addr32[2]); in6.s6_addr32[2] = htonl(in6.s6_addr32[2]);
in6.s6_addr32[3] = htonl(in6.s6_addr32[3]); in6.s6_addr32[3] = htonl(in6.s6_addr32[3]);
inet_ntop(AF_INET6, &in6, addr6, sizeof(addr6)); inet_ntop(AF_INET6, &in6, addr6, sizeof(addr6));
inet6_aftype.input(1, addr6, sa); inet6_aftype.input(1, addr6, &sas);
sas.ss_family = AF_INET6; sas.ss_family = AF_INET6;
} else { } else {
fprintf(stderr, _("warning, got bogus igmp6 line %d.\n"), lnr); fprintf(stderr, _("warning, got bogus igmp6 line %d.\n"), lnr);
...@@ -668,7 +667,7 @@ static void igmp_do_one(int lnr, const char *line,const char *prot) ...@@ -668,7 +667,7 @@ static void igmp_do_one(int lnr, const char *line,const char *prot)
sas.ss_family); sas.ss_family);
return; return;
} }
safe_strncpy(mcast_addr, ap->sprint(sa, flag_not & FLAG_NUM_HOST), safe_strncpy(mcast_addr, ap->sprint(&sas, flag_not & FLAG_NUM_HOST),
sizeof(mcast_addr)); sizeof(mcast_addr));
printf("%-15s %-6d %s\n", device, refcnt, mcast_addr); printf("%-15s %-6d %s\n", device, refcnt, mcast_addr);
#endif #endif
...@@ -705,7 +704,7 @@ static void igmp_do_one(int lnr, const char *line,const char *prot) ...@@ -705,7 +704,7 @@ static void igmp_do_one(int lnr, const char *line,const char *prot)
sas.ss_family); sas.ss_family);
return; return;
} }
safe_strncpy(mcast_addr, ap->sprint(sa, flag_not & FLAG_NUM_HOST), safe_strncpy(mcast_addr, ap->sprint(&sas, flag_not & FLAG_NUM_HOST),
sizeof(mcast_addr)); sizeof(mcast_addr));
printf("%-15s %-6d %s\n", device, refcnt, mcast_addr ); printf("%-15s %-6d %s\n", device, refcnt, mcast_addr );
#endif #endif
...@@ -781,7 +780,7 @@ static const char *sctp_socket_state_str(int state) ...@@ -781,7 +780,7 @@ static const char *sctp_socket_state_str(int state)
} }
} }
static const struct aftype *process_sctp_addr_str(const char *addr_str, struct sockaddr *sa) static const struct aftype *process_sctp_addr_str(const char *addr_str, struct sockaddr_storage *sas)
{ {
if (strchr(addr_str,':')) { if (strchr(addr_str,':')) {
#if HAVE_AFINET6 #if HAVE_AFINET6
...@@ -802,15 +801,15 @@ static const struct aftype *process_sctp_addr_str(const char *addr_str, struct s ...@@ -802,15 +801,15 @@ static const struct aftype *process_sctp_addr_str(const char *addr_str, struct s
in6.s6_addr16[7] = htons(u7); in6.s6_addr16[7] = htons(u7);
inet_ntop(AF_INET6, &in6, addr6_str, sizeof(addr6_str)); inet_ntop(AF_INET6, &in6, addr6_str, sizeof(addr6_str));
inet6_aftype.input(1, addr6_str, sa); inet6_aftype.input(1, addr6_str, sas);
sa->sa_family = AF_INET6; sas->ss_family = AF_INET6;
#endif #endif
} else { } else {
struct sockaddr_in *sin = (struct sockaddr_in *)sa; struct sockaddr_in *sin = (struct sockaddr_in *)sas;
sin->sin_addr.s_addr = inet_addr(addr_str); sin->sin_addr.s_addr = inet_addr(addr_str);
sa->sa_family = AF_INET; sas->ss_family = AF_INET;
} }
return get_afntype(sa->sa_family); return get_afntype(sas->ss_family);
} }
static void sctp_eps_do_one(int lnr, char *line, const char *proto) static void sctp_eps_do_one(int lnr, char *line, const char *proto)
...@@ -821,7 +820,6 @@ static void sctp_eps_do_one(int lnr, char *line, const char *proto) ...@@ -821,7 +820,6 @@ static void sctp_eps_do_one(int lnr, char *line, const char *proto)
unsigned long inode; unsigned long inode;
const struct aftype *ap; const struct aftype *ap;
struct sockaddr_storage localsas; struct sockaddr_storage localsas;
struct sockaddr *localsa = (struct sockaddr *)&localsas;
const char *sst_str; const char *sst_str;
const char *lport_str; const char *lport_str;
const char *uid_str; const char *uid_str;
...@@ -860,11 +858,11 @@ static void sctp_eps_do_one(int lnr, char *line, const char *proto) ...@@ -860,11 +858,11 @@ static void sctp_eps_do_one(int lnr, char *line, const char *proto)
this_local_addr; this_local_addr;
this_local_addr = strtok(0, " \t\n")) { this_local_addr = strtok(0, " \t\n")) {
char local_addr[64]; char local_addr[64];
ap = process_sctp_addr_str(this_local_addr, localsa); ap = process_sctp_addr_str(this_local_addr, &localsas);
if (ap) if (ap)
safe_strncpy(local_addr, ap->sprint(localsa, flag_not), sizeof(local_addr)); safe_strncpy(local_addr, ap->sprint(&localsas, flag_not), sizeof(local_addr));
else else
sprintf(local_addr, _("unsupported address family %d"), localsa->sa_family); sprintf(local_addr, _("unsupported address family %d"), localsas.ss_family);
if (first) if (first)
printf("sctp "); printf("sctp ");
...@@ -888,8 +886,6 @@ static void sctp_assoc_do_one(int lnr, char *line, const char *proto) ...@@ -888,8 +886,6 @@ static void sctp_assoc_do_one(int lnr, char *line, const char *proto)
const struct aftype *ap; const struct aftype *ap;
struct sockaddr_storage localsas, remotesas; struct sockaddr_storage localsas, remotesas;
struct sockaddr *localsa = (struct sockaddr *)&localsas;
struct sockaddr *remotesa = (struct sockaddr *)&remotesas;
const char *sst_str; const char *sst_str;
const char *txqueue_str; const char *txqueue_str;
const char *rxqueue_str; const char *rxqueue_str;
...@@ -959,24 +955,24 @@ static void sctp_assoc_do_one(int lnr, char *line, const char *proto) ...@@ -959,24 +955,24 @@ static void sctp_assoc_do_one(int lnr, char *line, const char *proto)
/* skip * */ /* skip * */
this_local_addr++; this_local_addr++;
} }
ap = process_sctp_addr_str(this_local_addr, localsa); ap = process_sctp_addr_str(this_local_addr, &localsas);
if (ap) if (ap)
safe_strncpy(local_addr, safe_strncpy(local_addr,
ap->sprint(localsa, flag_not), sizeof(local_addr)); ap->sprint(&localsas, flag_not), sizeof(local_addr));
else else
sprintf(local_addr, _("unsupported address family %d"), localsa->sa_family); sprintf(local_addr, _("unsupported address family %d"), localsas.ss_family);
} }
if (this_remote_addr) { if (this_remote_addr) {
if (this_remote_addr[0] == '*') { if (this_remote_addr[0] == '*') {
/* skip * */ /* skip * */
this_remote_addr++; this_remote_addr++;
} }
ap = process_sctp_addr_str(this_remote_addr, remotesa); ap = process_sctp_addr_str(this_remote_addr, &remotesas);
if (ap) if (ap)
safe_strncpy(remote_addr, safe_strncpy(remote_addr,
ap->sprint(remotesa, flag_not), sizeof(remote_addr)); ap->sprint(&remotesas, flag_not), sizeof(remote_addr));
else else
sprintf(remote_addr, _("unsupported address family %d"), remotesa->sa_family); sprintf(remote_addr, _("unsupported address family %d"), remotesas.ss_family);
} }
if (first) if (first)
...@@ -1036,7 +1032,7 @@ static void addr_do_one(char *buf, size_t buf_len, size_t short_len, const struc ...@@ -1036,7 +1032,7 @@ static void addr_do_one(char *buf, size_t buf_len, size_t short_len, const struc
const char *sport, *saddr; const char *sport, *saddr;
size_t port_len, addr_len; size_t port_len, addr_len;
saddr = ap->sprint((const struct sockaddr *)addr, flag_not & FLAG_NUM_HOST); saddr = ap->sprint(addr, flag_not & FLAG_NUM_HOST);
sport = get_sname(htons(port), proto, flag_not & FLAG_NUM_PORT); sport = get_sname(htons(port), proto, flag_not & FLAG_NUM_PORT);
addr_len = strlen(saddr); addr_len = strlen(saddr);
port_len = strlen(sport); port_len = strlen(sport);
...@@ -1091,12 +1087,12 @@ static void tcp_do_one(int lnr, const char *line, const char *prot) ...@@ -1091,12 +1087,12 @@ static void tcp_do_one(int lnr, const char *line, const char *prot)
&in6.s6_addr32[0], &in6.s6_addr32[1], &in6.s6_addr32[0], &in6.s6_addr32[1],
&in6.s6_addr32[2], &in6.s6_addr32[3]); &in6.s6_addr32[2], &in6.s6_addr32[3]);
inet_ntop(AF_INET6, &in6, addr6, sizeof(addr6)); inet_ntop(AF_INET6, &in6, addr6, sizeof(addr6));
inet6_aftype.input(1, addr6, (struct sockaddr *) &localsas); inet6_aftype.input(1, addr6, &localsas);
sscanf(rem_addr, "%08X%08X%08X%08X", sscanf(rem_addr, "%08X%08X%08X%08X",
&in6.s6_addr32[0], &in6.s6_addr32[1], &in6.s6_addr32[0], &in6.s6_addr32[1],
&in6.s6_addr32[2], &in6.s6_addr32[3]); &in6.s6_addr32[2], &in6.s6_addr32[3]);
inet_ntop(AF_INET6, &in6, addr6, sizeof(addr6)); inet_ntop(AF_INET6, &in6, addr6, sizeof(addr6));
inet6_aftype.input(1, addr6, (struct sockaddr *) &remsas); inet6_aftype.input(1, addr6, &remsas);
localsas.ss_family = AF_INET6; localsas.ss_family = AF_INET6;
remsas.ss_family = AF_INET6; remsas.ss_family = AF_INET6;
#endif #endif
...@@ -1215,12 +1211,12 @@ static void udp_do_one(int lnr, const char *line,const char *prot) ...@@ -1215,12 +1211,12 @@ static void udp_do_one(int lnr, const char *line,const char *prot)
&in6.s6_addr32[0], &in6.s6_addr32[1], &in6.s6_addr32[0], &in6.s6_addr32[1],
&in6.s6_addr32[2], &in6.s6_addr32[3]); &in6.s6_addr32[2], &in6.s6_addr32[3]);
inet_ntop(AF_INET6, &in6, addr6, sizeof(addr6)); inet_ntop(AF_INET6, &in6, addr6, sizeof(addr6));
inet6_aftype.input(1, addr6, (struct sockaddr *) &localsas); inet6_aftype.input(1, addr6, &localsas);
sscanf(rem_addr, "%08X%08X%08X%08X", sscanf(rem_addr, "%08X%08X%08X%08X",
&in6.s6_addr32[0], &in6.s6_addr32[1], &in6.s6_addr32[0], &in6.s6_addr32[1],
&in6.s6_addr32[2], &in6.s6_addr32[3]); &in6.s6_addr32[2], &in6.s6_addr32[3]);
inet_ntop(AF_INET6, &in6, addr6, sizeof(addr6)); inet_ntop(AF_INET6, &in6, addr6, sizeof(addr6));
inet6_aftype.input(1, addr6, (struct sockaddr *) &remsas); inet6_aftype.input(1, addr6, &remsas);
localsas.ss_family = AF_INET6; localsas.ss_family = AF_INET6;
remsas.ss_family = AF_INET6; remsas.ss_family = AF_INET6;
#endif #endif
...@@ -1328,12 +1324,12 @@ static void raw_do_one(int lnr, const char *line,const char *prot) ...@@ -1328,12 +1324,12 @@ static void raw_do_one(int lnr, const char *line,const char *prot)
&in6.s6_addr32[0], &in6.s6_addr32[1], &in6.s6_addr32[0], &in6.s6_addr32[1],
&in6.s6_addr32[2], &in6.s6_addr32[3]); &in6.s6_addr32[2], &in6.s6_addr32[3]);
inet_ntop(AF_INET6, &in6, addr6, sizeof(addr6)); inet_ntop(AF_INET6, &in6, addr6, sizeof(addr6));
inet6_aftype.input(1, addr6, (struct sockaddr *) &localsas); inet6_aftype.input(1, addr6, &localsas);
sscanf(rem_addr, "%08X%08X%08X%08X", sscanf(rem_addr, "%08X%08X%08X%08X",
&in6.s6_addr32[0], &in6.s6_addr32[1], &in6.s6_addr32[0], &in6.s6_addr32[1],
&in6.s6_addr32[2], &in6.s6_addr32[3]); &in6.s6_addr32[2], &in6.s6_addr32[3]);
inet_ntop(AF_INET6, &in6, addr6, sizeof(addr6)); inet_ntop(AF_INET6, &in6, addr6, sizeof(addr6));
inet6_aftype.input(1, addr6, (struct sockaddr *) &remsas); inet6_aftype.input(1, addr6, &remsas);
localsas.ss_family = AF_INET6; localsas.ss_family = AF_INET6;
remsas.ss_family = AF_INET6; remsas.ss_family = AF_INET6;
#endif #endif
...@@ -1651,7 +1647,7 @@ static int ipx_info(void) ...@@ -1651,7 +1647,7 @@ static int ipx_info(void)
const struct aftype *ap; const struct aftype *ap;
struct passwd *pw; struct passwd *pw;
char sad[50], dad[50]; char sad[50], dad[50];
struct sockaddr sa; struct sockaddr_storage sa;
unsigned sport = 0, dport = 0; unsigned sport = 0, dport = 0;
struct stat s; struct stat s;
......
...@@ -91,9 +91,10 @@ static int rarp_set(int fd, struct hostent *hp, char *hw_addr) ...@@ -91,9 +91,10 @@ static int rarp_set(int fd, struct hostent *hp, char *hw_addr)
{ {
struct arpreq req; struct arpreq req;
struct sockaddr_in *si; struct sockaddr_in *si;
struct sockaddr sap; struct sockaddr_storage sas;
struct sockaddr *sap = (struct sockaddr *)&sas;
if (hardware->input(hw_addr, &sap)) { if (hardware->input(hw_addr, &sas)) {
fprintf(stderr, _("%s: bad hardware address\n"), hw_addr); fprintf(stderr, _("%s: bad hardware address\n"), hw_addr);
return 1; return 1;
} }
...@@ -103,7 +104,7 @@ static int rarp_set(int fd, struct hostent *hp, char *hw_addr) ...@@ -103,7 +104,7 @@ static int rarp_set(int fd, struct hostent *hp, char *hw_addr)
si->sin_family = hp->h_addrtype; si->sin_family = hp->h_addrtype;
memcpy((char *) &si->sin_addr, hp->h_addr_list[0], hp->h_length); memcpy((char *) &si->sin_addr, hp->h_addr_list[0], hp->h_length);
req.arp_ha.sa_family = hardware->type; req.arp_ha.sa_family = hardware->type;
memcpy(req.arp_ha.sa_data, sap.sa_data, hardware->alen); memcpy(req.arp_ha.sa_data, sap->sa_data, hardware->alen);
/* Call the kernel. */ /* Call the kernel. */
if (ioctl(fd, SIOCSRARP, &req) < 0) { if (ioctl(fd, SIOCSRARP, &req) < 0) {
......
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