X-Git-Url: https://git.saurik.com/apple/network_cmds.git/blobdiff_plain/b8dff1509d79abed3d82c4d8bfb2e73c7d0f1d1a..7af5ce03cf81eb8cf0c6e1bfd903b52fcc7c224a:/rtadvd.tproj/if.c?ds=inline diff --git a/rtadvd.tproj/if.c b/rtadvd.tproj/if.c index 2c7ffd7..db83a69 100644 --- a/rtadvd.tproj/if.c +++ b/rtadvd.tproj/if.c @@ -27,8 +27,6 @@ * 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 @@ -37,23 +35,12 @@ #include #include #include -#if defined(__FreeBSD__) || defined (__APPLE__) -# include -#endif +#include #include -#ifdef __NetBSD__ -#include -#endif #include #include #include #include -#ifdef __bsdi__ -# include -#endif -#ifdef __OpenBSD__ -#include -#endif #include #include #include @@ -67,17 +54,17 @@ #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) @@ -102,14 +89,16 @@ if_nametosdl(char *name) 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) { @@ -133,7 +122,8 @@ if_nametosdl(char *name) } if (next == lim) { /* search failed */ - goto end; + free(buf); + return(NULL); } if ((ret_sdl = malloc(sdl->sdl_len)) == NULL) @@ -142,7 +132,7 @@ if_nametosdl(char *name) end: free(buf); - return (ret_sdl); + return(ret_sdl); } int @@ -150,7 +140,7 @@ if_getmtu(char *name) { struct ifaddrs *ifap, *ifa; struct if_data *ifd; - u_long mtu = 0; + int mtu = 0; if (getifaddrs(&ifap) < 0) return(0); @@ -196,7 +186,7 @@ if_getflags(int ifindex, int oifflags) 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); } @@ -204,7 +194,7 @@ if_getflags(int ifindex, int oifflags) 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); } @@ -216,11 +206,11 @@ if_getflags(int ifindex, int oifflags) 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); } } @@ -231,17 +221,16 @@ lladdropt_fill(struct sockaddr_dl *sdl, struct nd_opt_hdr *ndopt) 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; @@ -277,7 +266,7 @@ get_next_msg(char *buf, char *lim, int ifindex, size_t *lenp, int filter) /* 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; } @@ -496,16 +485,16 @@ get_iflist(char **buf, size_t *size) 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; @@ -531,7 +520,7 @@ parse_iflist(struct if_msghdr ***ifmlist_p, char *buf, size_t bufsize) /* 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); } @@ -539,7 +528,7 @@ parse_iflist(struct if_msghdr ***ifmlist_p, char *buf, size_t bufsize) 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; } @@ -562,7 +551,7 @@ parse_iflist(struct if_msghdr ***ifmlist_p, char *buf, size_t bufsize) /* 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; }