mirror of
https://github.com/ecki/net-tools.git
synced 2025-04-10 08:59:34 +00:00
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
44 lines
697 B
C
44 lines
697 B
C
/*
|
|
* Tunnel.c, Alan Cox 1995.
|
|
*
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#if HAVE_HWTUNNEL
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <net/if_arp.h>
|
|
#include <linux/if_ether.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
#include <ctype.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include "net-support.h"
|
|
#include "pathnames.h"
|
|
|
|
extern struct hwtype ether_hwtype;
|
|
|
|
static const char *pr_tunnel(const char *ptr)
|
|
{
|
|
return ("");
|
|
}
|
|
|
|
|
|
static int in_tunnel(char *bufp, struct sockaddr_storage *sasp)
|
|
{
|
|
return (-1);
|
|
}
|
|
|
|
|
|
struct hwtype tunnel_hwtype =
|
|
{
|
|
"tunnel", NULL, /*"IPIP Tunnel", */ ARPHRD_TUNNEL, 0,
|
|
pr_tunnel, in_tunnel, NULL, 0
|
|
};
|
|
|
|
|
|
#endif /* HAVE_HWTUNNEL */
|