struct in_addr dst;
uint8_t added;
- char leasefile[sizeof(LEASEFILE) + IF_NAMESIZE + (IF_SSIDSIZE * 4)];
+ char leasefile[sizeof(LEASEFILE) + IF_NAMESIZE + (IF_SSIDLEN * 4)];
struct timespec started;
unsigned char *clientid;
struct authstate auth;
struct ipv6_addrhead addrs;
uint32_t lowpl;
/* The +3 is for the possible .pd extension for prefix delegation */
- char leasefile[sizeof(LEASEFILE6) + IF_NAMESIZE + (IF_SSIDSIZE * 4) +3];
+ char leasefile[sizeof(LEASEFILE6) + IF_NAMESIZE + (IF_SSIDLEN * 4) +3];
const char *reason;
struct authstate auth;
dhcpcd_handleinterface(ctx, 0, ifp->name);
#endif
if (ifp->wireless) {
- uint8_t ossid[IF_SSIDSIZE];
+ uint8_t ossid[IF_SSIDLEN];
#ifdef NOCARRIER_PRESERVE_IP
size_t olen;
#include "if-options.h"
#define HWADDR_LEN 20
-#define IF_SSIDSIZE 33
+#define IF_SSIDLEN 32
#define PROFILE_LEN 64
#define SECRET_LEN 64
unsigned int metric;
int carrier;
int wireless;
- uint8_t ssid[IF_SSIDSIZE];
+ uint8_t ssid[IF_SSIDLEN + 1]; /* NULL terminated */
unsigned int ssid_len;
char profile[PROFILE_LEN];
struct ieee80211_nwid nwid;
#elif defined(IEEE80211_IOC_SSID)
struct ieee80211req ireq;
- char nwid[IEEE80211_NWID_LEN + 1];
+ char nwid[IEEE80211_NWID_LEN];
#endif
#if defined(SIOCG80211NWID) /* NetBSD */
if (ioctl(s, SIOCG80211NWID, &ifr) == 0) {
if (ssid == NULL)
retval = nwid.i_len;
- else if (nwid.i_len > IF_SSIDSIZE) {
+ else if (nwid.i_len > IF_SSIDLEN)
errno = ENOBUFS;
- retval = -1;
- } else {
+ else {
retval = nwid.i_len;
memcpy(ssid, nwid.i_nwid, nwid.i_len);
- ssid[nwid.i_len] = '\0';
}
}
#elif defined(IEEE80211_IOC_SSID) /* FreeBSD */
if (ioctl(s, SIOCG80211, &ireq) == 0) {
if (ssid == NULL)
retval = ireq.i_len;
- else if (ireq.i_len > IF_SSIDSIZE - 1) {
+ else if (ireq.i_len > IF_SSIDLEN)
errno = ENOBUFS;
- retval = -1;
- } else {
+ else {
retval = ireq.i_len;
memcpy(ssid, nwid, ireq.i_len);
- ssid[ireq.i_len] = '\0';
}
}
+#else
+ errno = ENOSYS;
#endif
return retval;
r = if_getssid1(ifp->ctx->pf_inet_fd, ifp->name, ifp->ssid);
if (r != -1)
ifp->ssid_len = (unsigned int)r;
+ else
+ ifp->ssid_len = 0;
+ ifp->ssid[ifp->ssid_len] = '\0';
return r;
}
/*
* dhcpcd - DHCP client daemon
- * Copyright (c) 2009-2015 Roy Marples <roy@marples.name>
+ * Copyright (c) 2009-2016 Roy Marples <roy@marples.name>
* All rights reserved
* Redistribution and use in source and binary forms, with or without
/* We can't include if.h or dhcpcd.h because
* they would pull in net/if.h, which defeats the purpose of this hack. */
-#define IF_SSIDSIZE 33
+#define IF_SSIDLEN 32
int if_getssid_wext(const char *ifname, uint8_t *ssid);
int
memset(&iwr, 0, sizeof(iwr));
strlcpy(iwr.ifr_name, ifname, sizeof(iwr.ifr_name));
iwr.u.essid.pointer = ssid;
- iwr.u.essid.length = IF_SSIDSIZE - 1;
+ iwr.u.essid.length = IF_SSIDLEN;
- if (ioctl(s, SIOCGIWESSID, &iwr) == 0) {
+ if (ioctl(s, SIOCGIWESSID, &iwr) == 0)
retval = iwr.u.essid.length;
- ssid[retval] = '\0';
- } else
+ else
retval = -1;
close(s);
return retval;
}
ifp->ssid_len = NLA_LEN(tb[NL80211_ATTR_SSID]);
- if (ifp->ssid_len > sizeof(ifp->ssid) - 1) {
+ if (ifp->ssid_len > IF_SSIDLEN) {
errno = ENOBUFS;
ifp->ssid_len = 0;
return -1;
memcpy(ifp->ssid, NLA_DATA(tb[NL80211_ATTR_SSID]), ifp->ssid_len);
out:
- ifp->ssid[ifp->ssid_len] = '\0';
return (int)ifp->ssid_len;
}
r = if_getssid_wext(ifp->name, ifp->ssid);
if (r != -1)
ifp->ssid_len = (unsigned int)r;
+ else {
#ifdef HAVE_NL80211_H
- else if (r == -1)
r = if_getssid_nl80211(ifp);
+ if (r == -1)
+ ifp->ssid_len = 0;
+#else
+ ifp->ssid_len = 0;
#endif
+ }
+ ifp->ssid[ifp->ssid_len] = '\0';
return r;
}
strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
if (ioctl(ctx->pf_inet_fd, SIOCGIFPRIORITY, &ifr) == 0)
ifp->metric = (unsigned int)ifr.ifr_metric;
+ if_getssid(ifp);
#else
/* We reserve the 100 range for virtual interfaces, if and when
* we can work them out. */