aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/socket.c')
-rw-r--r--networking/udhcp/socket.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c
index ea2913172..c19131d65 100644
--- a/networking/udhcp/socket.c
+++ b/networking/udhcp/socket.c
@@ -63,23 +63,27 @@ int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp)
63 DEBUG("%s (our ip) = %s", ifr.ifr_name, inet_ntoa(our_ip->sin_addr)); 63 DEBUG("%s (our ip) = %s", ifr.ifr_name, inet_ntoa(our_ip->sin_addr));
64 } 64 }
65 65
66 if (ioctl(fd, SIOCGIFINDEX, &ifr) == 0) { 66 if (ifindex) {
67 bb_perror_msg("SIOCGIFINDEX failed"); 67 if (ioctl(fd, SIOCGIFINDEX, &ifr) == 0) {
68 close(fd); 68 bb_perror_msg("SIOCGIFINDEX failed");
69 return -1; 69 close(fd);
70 return -1;
71 }
72 DEBUG("adapter index %d", ifr.ifr_ifindex);
73 *ifindex = ifr.ifr_ifindex;
70 } 74 }
71 75
72 DEBUG("adapter index %d", ifr.ifr_ifindex); 76 if (arp) {
73 *ifindex = ifr.ifr_ifindex; 77 if (ioctl(fd, SIOCGIFHWADDR, &ifr) != 0) {
74 if (ioctl(fd, SIOCGIFHWADDR, &ifr) != 0) { 78 bb_perror_msg("SIOCGIFHWADDR failed");
75 bb_perror_msg("SIOCGIFHWADDR failed"); 79 close(fd);
76 close(fd); 80 return -1;
77 return -1; 81 }
82 memcpy(arp, ifr.ifr_hwaddr.sa_data, 6);
83 DEBUG("adapter hardware address %02x:%02x:%02x:%02x:%02x:%02x",
84 arp[0], arp[1], arp[2], arp[3], arp[4], arp[5]);
78 } 85 }
79 86
80 memcpy(arp, ifr.ifr_hwaddr.sa_data, 6);
81 DEBUG("adapter hardware address %02x:%02x:%02x:%02x:%02x:%02x",
82 arp[0], arp[1], arp[2], arp[3], arp[4], arp[5]);
83 return 0; 87 return 0;
84} 88}
85 89