Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/networking/udhcp/socket.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/networking/udhcp/socket.c
r2725 r3232 23 23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 24 */ 25 #include "common.h" 25 26 #include <net/if.h> 26 #if (defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined _NEWLIB_VERSION27 # include <netpacket/packet.h>28 # include <net/ethernet.h>29 #else30 # include <asm/types.h>31 # include <linux/if_packet.h>32 # include <linux/if_ether.h>33 #endif34 35 #include "common.h"36 27 37 28 int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac) 38 29 { 30 /* char buffer instead of bona-fide struct avoids aliasing warning */ 31 char ifr_buf[sizeof(struct ifreq)]; 32 struct ifreq *const ifr = (void *)ifr_buf; 33 39 34 int fd; 40 struct ifreq ifr;41 35 struct sockaddr_in *our_ip; 42 36 43 memset( &ifr, 0, sizeof(ifr));37 memset(ifr, 0, sizeof(*ifr)); 44 38 fd = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW); 45 39 46 ifr .ifr_addr.sa_family = AF_INET;47 strncpy_IFNAMSIZ(ifr .ifr_name, interface);40 ifr->ifr_addr.sa_family = AF_INET; 41 strncpy_IFNAMSIZ(ifr->ifr_name, interface); 48 42 if (nip) { 49 if (ioctl_or_perror(fd, SIOCGIFADDR, &ifr,43 if (ioctl_or_perror(fd, SIOCGIFADDR, ifr, 50 44 "is interface %s up and configured?", interface) 51 45 ) { … … 53 47 return -1; 54 48 } 55 our_ip = (struct sockaddr_in *) &ifr .ifr_addr;49 our_ip = (struct sockaddr_in *) &ifr->ifr_addr; 56 50 *nip = our_ip->sin_addr.s_addr; 57 51 log1("IP %s", inet_ntoa(our_ip->sin_addr)); … … 59 53 60 54 if (ifindex) { 61 if (ioctl_or_warn(fd, SIOCGIFINDEX, &ifr) != 0) {55 if (ioctl_or_warn(fd, SIOCGIFINDEX, ifr) != 0) { 62 56 close(fd); 63 57 return -1; 64 58 } 65 log1("Adapter index %d", ifr .ifr_ifindex);66 *ifindex = ifr .ifr_ifindex;59 log1("Adapter index %d", ifr->ifr_ifindex); 60 *ifindex = ifr->ifr_ifindex; 67 61 } 68 62 69 63 if (mac) { 70 if (ioctl_or_warn(fd, SIOCGIFHWADDR, &ifr) != 0) {64 if (ioctl_or_warn(fd, SIOCGIFHWADDR, ifr) != 0) { 71 65 close(fd); 72 66 return -1; 73 67 } 74 memcpy(mac, ifr .ifr_hwaddr.sa_data, 6);68 memcpy(mac, ifr->ifr_hwaddr.sa_data, 6); 75 69 log1("MAC %02x:%02x:%02x:%02x:%02x:%02x", 76 70 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); … … 87 81 int fd; 88 82 struct sockaddr_in addr; 83 char *colon; 89 84 90 85 log1("Opening listen socket on *:%d %s", port, inf); … … 95 90 bb_perror_msg_and_die("SO_BROADCAST"); 96 91 97 /* NB: bug 1032 says this doesn't work on ethernet aliases (ethN:M) */ 92 /* SO_BINDTODEVICE doesn't work on ethernet aliases (ethN:M) */ 93 colon = strrchr(inf, ':'); 94 if (colon) 95 *colon = '\0'; 96 98 97 if (setsockopt_bindtodevice(fd, inf)) 99 98 xfunc_die(); /* warning is already printed */ 99 100 if (colon) 101 *colon = ':'; 100 102 101 103 memset(&addr, 0, sizeof(addr));
Note:
See TracChangeset
for help on using the changeset viewer.