Another improvement of getifaddrs.patch
This commit is contained in:
parent
30f41aa41d
commit
f0f508f3bf
@ -406,14 +406,20 @@ diff -up dhcp-4.2.3-P2/common/discover.c.getifaddrs dhcp-4.2.3-P2/common/discove
|
|||||||
if (ifaces->next == NULL) {
|
if (ifaces->next == NULL) {
|
||||||
*err = 0;
|
*err = 0;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -825,8 +446,18 @@ next_iface(struct iface_info *info, int
|
@@ -825,8 +446,24 @@ next_iface(struct iface_info *info, int
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
strcpy(info->name, ifaces->next->ifa_name);
|
strcpy(info->name, ifaces->next->ifa_name);
|
||||||
- memcpy(&info->addr, ifaces->next->ifa_addr,
|
- memcpy(&info->addr, ifaces->next->ifa_addr,
|
||||||
- ifaces->next->ifa_addr->sa_len);
|
- ifaces->next->ifa_addr->sa_len);
|
||||||
+
|
+
|
||||||
|
+ memset(&info->addr, 0 , sizeof(info->addr));
|
||||||
|
+ /*
|
||||||
|
+ * getifaddrs() can on Linux with some interfaces like PPP or TEQL
|
||||||
|
+ * result in a record with no address (ifa_addr).
|
||||||
|
+ */
|
||||||
+ if (ifaces->next->ifa_addr != NULL) {
|
+ if (ifaces->next->ifa_addr != NULL) {
|
||||||
|
+/* Linux lacks the sa_len member in struct sockaddr. */
|
||||||
+#if defined(__linux)
|
+#if defined(__linux)
|
||||||
+ if (ifaces->next->ifa_addr->sa_family == AF_INET)
|
+ if (ifaces->next->ifa_addr->sa_family == AF_INET)
|
||||||
+ sa_len = sizeof(struct sockaddr_in);
|
+ sa_len = sizeof(struct sockaddr_in);
|
||||||
|
Loading…
Reference in New Issue
Block a user