0
0
mirror of https://github.com/ecki/net-tools.git synced 2024-11-13 14:09:25 +00:00
net-tools/lib/ipx_gr.c
Mike Frysinger 5c9e1e7615 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
2015-11-24 09:34:47 -05:00

94 lines
2.2 KiB
C

/* support for ap->rresolv missing */
/*
Modifications:
1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets,
snprintf instead of sprintf
*/
#include "config.h"
#if HAVE_AFIPX
#include <asm/types.h>
#include <sys/types.h>
#include <sys/socket.h>
#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
#include <netipx/ipx.h>
#else
#include "ipx.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <netinet/in.h>
#include "version.h"
#include "net-support.h"
#include "pathnames.h"
#include "intl.h"
#include "util.h"
/* UGLY */
int IPX_rprint(int options)
{
/* int ext = options & FLAG_EXT; */
int numeric = options & FLAG_NUM_HOST;
char buff[1024];
char net[128], router_net[128];
char router_node[128];
int num;
FILE *fp;
const struct aftype *ap;
struct sockaddr_storage sas;
fp = fopen(_PATH_PROCNET_IPX_ROUTE1, "r");
if (!fp) {
fp = fopen(_PATH_PROCNET_IPX_ROUTE2, "r");
}
if (!fp) {
perror(NULL);
printf(_("IPX routing not in file %s or %s found.\n"), _PATH_PROCNET_IPX_ROUTE1, _PATH_PROCNET_IPX_ROUTE2);
return 1;
}
if ((ap = get_afntype(AF_IPX)) == NULL) {
EINTERN("lib/ipx_rt.c", "AF_IPX missing");
return (-1);
}
printf(_("Kernel IPX routing table\n")); /* xxx */
printf(_("Destination Router Net Router Node\n"));
if (fgets(buff, 1023, fp))
/* eat line */;
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(1, net, &sas);
safe_strncpy(net, ap->sprint(&sas, numeric), sizeof(net));
/* Fetch and resolve the Router Net */
(void) ap->input(1, router_net, &sas);
safe_strncpy(router_net, ap->sprint(&sas, numeric), sizeof(router_net));
/* Fetch and resolve the Router Node */
(void) ap->input(2, router_node, &sas);
safe_strncpy(router_node, ap->sprint(&sas, numeric), sizeof(router_node));
printf("%-25s %-25s %-25s\n", net, router_net, router_node);
}
(void) fclose(fp);
return (0);
}
#endif /* HAVE_AFIPX */