* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $FreeBSD: src/usr.sbin/rtadvd/if.c,v 1.2.2.3 2001/07/03 11:02:14 ume Exp $
*/
#include <sys/param.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <net/if_types.h>
-#if defined(__FreeBSD__) || defined (__APPLE__)
-# include <net/ethernet.h>
-#endif
+#include <net/ethernet.h>
#include <ifaddrs.h>
-#ifdef __NetBSD__
-#include <net/if_ether.h>
-#endif
#include <net/route.h>
#include <net/if_dl.h>
#include <netinet/in.h>
#include <netinet/icmp6.h>
-#ifdef __bsdi__
-# include <netinet/if_ether.h>
-#endif
-#ifdef __OpenBSD__
-#include <netinet/if_ether.h>
-#endif
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#define NEXT_SA(ap) (ap) = (struct sockaddr *) \
((caddr_t)(ap) + ((ap)->sa_len ? ROUNDUP((ap)->sa_len,\
- sizeof(u_long)) :\
- sizeof(u_long)))
+ sizeof(uint32_t)) :\
+ sizeof(uint32_t)))
struct if_msghdr **iflist;
int iflist_init_ok;
size_t ifblock_size;
char *ifblock;
-static void get_iflist __P((char **buf, size_t *size));
-static void parse_iflist __P((struct if_msghdr ***ifmlist_p, char *buf,
- size_t bufsize));
+static void get_iflist(char **buf, size_t *size);
+static void parse_iflist(struct if_msghdr ***ifmlist_p, char *buf,
+ size_t bufsize);
static void
get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
size_t len;
struct if_msghdr *ifm;
struct sockaddr *sa, *rti_info[RTAX_MAX];
- struct sockaddr_dl *sdl = NULL, *ret_sdl = NULL;
+ struct sockaddr_dl *sdl = NULL, *ret_sdl;
if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0)
return(NULL);
if ((buf = malloc(len)) == NULL)
return(NULL);
- if (sysctl(mib, 6, buf, &len, NULL, 0) < 0)
- goto end;
+ if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
+ free(buf);
+ return(NULL);
+ }
lim = buf + len;
for (next = buf; next < lim; next += ifm->ifm_msglen) {
}
if (next == lim) {
/* search failed */
- goto end;
+ free(buf);
+ return(NULL);
}
if ((ret_sdl = malloc(sdl->sdl_len)) == NULL)
end:
free(buf);
- return (ret_sdl);
+ return(ret_sdl);
}
int
{
struct ifaddrs *ifap, *ifa;
struct if_data *ifd;
- u_long mtu = 0;
+ int mtu = 0;
if (getifaddrs(&ifap) < 0)
return(0);
int s;
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
- syslog(LOG_ERR, "<%s> socket: %s", __FUNCTION__,
+ syslog(LOG_ERR, "<%s> socket: %s", __func__,
strerror(errno));
return (oifflags & ~IFF_UP);
}
if_indextoname(ifindex, ifr.ifr_name);
if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
syslog(LOG_ERR, "<%s> ioctl:SIOCGIFFLAGS: failed for %s",
- __FUNCTION__, ifr.ifr_name);
+ __func__, ifr.ifr_name);
close(s);
return (oifflags & ~IFF_UP);
}
int
lladdropt_length(struct sockaddr_dl *sdl)
{
- switch(sdl->sdl_type) {
- case IFT_ETHER:
- return(ROUNDUP8(ETHER_ADDR_LEN + 2));
- default:
- return(0);
+ switch (sdl->sdl_type) {
+ case IFT_ETHER:
+ return(ROUNDUP8(ETHER_ADDR_LEN + 2));
+ default:
+ return(0);
}
}
ndopt->nd_opt_type = ND_OPT_SOURCE_LINKADDR; /* fixed */
- switch(sdl->sdl_type) {
- case IFT_ETHER:
- ndopt->nd_opt_len = (ROUNDUP8(ETHER_ADDR_LEN + 2)) >> 3;
- addr = (char *)(ndopt + 1);
- memcpy(addr, LLADDR(sdl), ETHER_ADDR_LEN);
- break;
- default:
- syslog(LOG_ERR,
- "<%s> unsupported link type(%d)",
- __FUNCTION__, sdl->sdl_type);
- exit(1);
+ switch (sdl->sdl_type) {
+ case IFT_ETHER:
+ ndopt->nd_opt_len = (ROUNDUP8(ETHER_ADDR_LEN + 2)) >> 3;
+ addr = (char *)(ndopt + 1);
+ memcpy(addr, LLADDR(sdl), ETHER_ADDR_LEN);
+ break;
+ default:
+ syslog(LOG_ERR, "<%s> unsupported link type(%d)",
+ __func__, sdl->sdl_type);
+ exit(1);
}
return;
/* just for safety */
if (!rtm->rtm_msglen) {
syslog(LOG_WARNING, "<%s> rtm_msglen is 0 "
- "(buf=%p lim=%p rtm=%p)", __FUNCTION__,
+ "(buf=%p lim=%p rtm=%p)", __func__,
buf, lim, rtm);
break;
}
if (sysctl(mib, 6, NULL, size, NULL, 0) < 0) {
syslog(LOG_ERR, "<%s> sysctl: iflist size get failed",
- __FUNCTION__);
+ __func__);
exit(1);
}
if ((*buf = malloc(*size)) == NULL) {
- syslog(LOG_ERR, "<%s> malloc failed", __FUNCTION__);
+ syslog(LOG_ERR, "<%s> malloc failed", __func__);
exit(1);
}
if (sysctl(mib, 6, *buf, size, NULL, 0) < 0) {
syslog(LOG_ERR, "<%s> sysctl: iflist get failed",
- __FUNCTION__);
+ __func__);
exit(1);
}
return;
/* roughly estimate max list size of pointers to each if_msghdr */
malloc_size = (bufsize/iflentry_size) * sizeof(size_t);
if ((*ifmlist_p = (struct if_msghdr **)malloc(malloc_size)) == NULL) {
- syslog(LOG_ERR, "<%s> malloc failed", __FUNCTION__);
+ syslog(LOG_ERR, "<%s> malloc failed", __func__);
exit(1);
}
for (ifm = (struct if_msghdr *)buf; ifm < (struct if_msghdr *)lim;) {
if (ifm->ifm_msglen == 0) {
syslog(LOG_WARNING, "<%s> ifm_msglen is 0 "
- "(buf=%p lim=%p ifm=%p)", __FUNCTION__,
+ "(buf=%p lim=%p ifm=%p)", __func__,
buf, lim, ifm);
return;
}
/* just for safety */
if (!ifam->ifam_msglen) {
syslog(LOG_WARNING, "<%s> ifa_msglen is 0 "
- "(buf=%p lim=%p ifam=%p)", __FUNCTION__,
+ "(buf=%p lim=%p ifam=%p)", __func__,
buf, lim, ifam);
return;
}