If the name of the ethernet interface is longer than can fit in the
relevant structure used for system calls, generate an error rather
than using a truncated interface name.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
int fd;
struct ifreq ifr;
int domain, stype;
+ size_t maxlen;
#ifdef HAVE_STRUCT_SOCKADDR_LL
struct sockaddr_ll sa;
#ifdef HAVE_STRUCT_SOCKADDR_LL
domain = PF_PACKET;
stype = SOCK_RAW;
+ maxlen = IFNAMSIZ;
#else
domain = PF_INET;
stype = SOCK_PACKET;
+ maxlen = sizeof(sa.sa_data);
#endif
+ if (strlen(ifname) >= maxlen) {
+ error("Can't use interface %.16s: name is too long", ifname);
+ return -1;
+ }
+
if ((fd = socket(domain, stype, htons(type))) < 0) {
/* Give a more helpful message for the common error case */
if (errno == EPERM) {