| @@ -1869,38 +1869,37 @@ get_ether_addr(u_int32_t ipaddr, struct | | | @@ -1869,38 +1869,37 @@ get_ether_addr(u_int32_t ipaddr, struct |
1869 | return 0; | | 1869 | return 0; |
1870 | } | | 1870 | } |
1871 | | | 1871 | |
1872 | /* | | 1872 | /* |
1873 | * get_if_hwaddr - get the hardware address for the specified | | 1873 | * get_if_hwaddr - get the hardware address for the specified |
1874 | * network interface device. | | 1874 | * network interface device. |
1875 | */ | | 1875 | */ |
1876 | int | | 1876 | int |
1877 | get_if_hwaddr(u_char *addr, char *name) | | 1877 | get_if_hwaddr(u_char *addr, char *name) |
1878 | { | | 1878 | { |
1879 | | | 1879 | |
1880 | #define IFREQ_SAFE (sizeof(struct ifreq) + sizeof(struct sockaddr_dl)) | | 1880 | #define IFREQ_SAFE (sizeof(struct ifreq) + sizeof(struct sockaddr_dl)) |
1881 | /* XXX sockaddr_dl is larger than the sockaddr in struct ifreq! */ | | 1881 | /* XXX sockaddr_dl is larger than the sockaddr in struct ifreq! */ |
1882 | union { /* XXX */ | | 1882 | union { /* XXX */ |
1883 | struct ifreq _ifreq; /* XXX */ | | 1883 | struct ifreq _ifreq; /* XXX */ |
1884 | char _X[IFREQ_SAFE]; /* XXX */ | | 1884 | char _X[IFREQ_SAFE]; /* XXX */ |
1885 | } _ifreq_dontsmashstack; /* XXX */ | | 1885 | } _ifreq_dontsmashstack = {0}; /* XXX */ |
1886 | #define ifreq_xxx _ifreq_dontsmashstack._ifreq /* XXX */ | | 1886 | #define ifreq_xxx _ifreq_dontsmashstack._ifreq /* XXX */ |
1887 | | | 1887 | |
1888 | struct sockaddr_dl *sdl = (struct sockaddr_dl *) &ifreq_xxx.ifr_addr; | | 1888 | struct sockaddr_dl *sdl = (struct sockaddr_dl *) &ifreq_xxx.ifr_addr; |
1889 | int fd; | | 1889 | int fd; |
1890 | | | 1890 | |
1891 | if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) | | 1891 | if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) |
1892 | return 0; | | 1892 | return 0; |
1893 | (void)memset(sdl, 0, sizeof(*sdl)); | | | |
1894 | sdl->sdl_family = AF_LINK; | | 1893 | sdl->sdl_family = AF_LINK; |
1895 | (void)strlcpy(ifreq_xxx.ifr_name, name, sizeof(ifreq_xxx.ifr_name)); | | 1894 | (void)strlcpy(ifreq_xxx.ifr_name, name, sizeof(ifreq_xxx.ifr_name)); |
1896 | if (ioctl(fd, SIOCGIFADDR, &ifreq_xxx) == -1) { | | 1895 | if (ioctl(fd, SIOCGIFADDR, &ifreq_xxx) == -1) { |
1897 | (void)close(fd); | | 1896 | (void)close(fd); |
1898 | return 0; | | 1897 | return 0; |
1899 | } | | 1898 | } |
1900 | (void)close(fd); | | 1899 | (void)close(fd); |
1901 | (void)memcpy(addr, LLADDR(sdl), sdl->sdl_alen); | | 1900 | (void)memcpy(addr, LLADDR(sdl), sdl->sdl_alen); |
1902 | return sdl->sdl_nlen; | | 1901 | return sdl->sdl_nlen; |
1903 | } | | 1902 | } |
1904 | | | 1903 | |
1905 | /* | | 1904 | /* |
1906 | * get_first_ethernet - return the name of the first ethernet-style | | 1905 | * get_first_ethernet - return the name of the first ethernet-style |