mirror of
https://github.com/ecki/net-tools.git
synced 2024-11-13 14:09:25 +00:00
5c9e1e7615
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
87 lines
2.0 KiB
C
87 lines
2.0 KiB
C
/*
|
|
* lib/econet.c This file contains an implementation of the Econet
|
|
* support functions for the net-tools.
|
|
* (NET-3 base distribution).
|
|
*
|
|
* Version: $Id: econet.c,v 1.11 2000/05/27 17:36:16 pb Exp $
|
|
*
|
|
* Author: Philip Blundell <philb@gnu.org>
|
|
*
|
|
* Modified:
|
|
*
|
|
* This program is free software; you can redistribute it
|
|
* and/or modify it under the terms of the GNU General
|
|
* Public License as published by the Free Software
|
|
* Foundation; either version 2 of the License, or (at
|
|
* your option) any later version.
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#if HAVE_AFECONET
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <stdio.h>
|
|
#include <neteconet/ec.h>
|
|
|
|
#include "version.h"
|
|
#include "net-support.h"
|
|
#include "pathnames.h"
|
|
#include "intl.h"
|
|
|
|
|
|
/* Display an Econet address */
|
|
static const char *
|
|
ec_print(const char *ptr)
|
|
{
|
|
static char buff[64];
|
|
struct ec_addr *ec = (struct ec_addr *) ptr;
|
|
sprintf(buff, "%d.%d", ec->net, ec->station);
|
|
return buff;
|
|
}
|
|
|
|
|
|
/* Display an Econet socket address */
|
|
static const char *
|
|
ec_sprint(const struct sockaddr_storage *sasp, int numeric)
|
|
{
|
|
const struct sockaddr_ec *sec = (const struct sockaddr_ec *)sasp;
|
|
|
|
if (sasp->ss_family != AF_ECONET)
|
|
return _("[NONE SET]");
|
|
|
|
return ec_print((const char *) &sec->addr);
|
|
}
|
|
|
|
static int
|
|
ec_input(int type, char *bufp, struct sockaddr_storage *sasp)
|
|
{
|
|
struct sockaddr_ec *sec = (struct sockaddr_ec *) sasp;
|
|
int net, stn;
|
|
switch (sscanf(bufp, "%d.%d", &net, &stn)) {
|
|
case 2:
|
|
sec->addr.station = stn;
|
|
sec->addr.net = net;
|
|
return 0;
|
|
case 1:
|
|
if (sscanf(bufp, "%d", &stn) == 1) {
|
|
sec->addr.net = 0;
|
|
sec->addr.station = stn;
|
|
return 0;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
struct aftype ec_aftype =
|
|
{
|
|
"ec", NULL, AF_ECONET, 0,
|
|
ec_print, ec_sprint, ec_input, NULL,
|
|
NULL, NULL, NULL,
|
|
-1,
|
|
"/proc/sys/net/econet"
|
|
};
|
|
|
|
#endif /* HAVE_AFECONET */
|