lib:socket: get interface index from kernel
authorMichael Adam <obnox@samba.org>
Mon, 25 Jan 2016 11:23:40 +0000 (12:23 +0100)
committerMichael Adam <obnox@samba.org>
Tue, 26 Jan 2016 06:33:16 +0000 (07:33 +0100)
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/socket/interfaces.c

index e62da3c3a1f906012d61a789a6f2b12fda32c875..3b15615b8d1c0be710df1078abe20b1af2a55262 100644 (file)
@@ -214,6 +214,12 @@ static int _get_interfaces(TALLOC_CTX *mem_ctx, struct iface_struct **pifaces)
                        continue;
                }
 
+               ifaces[total].if_index = if_nametoindex(ifptr->ifa_name);
+               if (ifaces[total].if_index == 0) {
+                       DBG_ERR("Failed to retrieve interface index for '%s': "
+                               "%s\n", ifptr->ifa_name, strerror(errno));
+               }
+
                if (strlcpy(ifaces[total].name, ifptr->ifa_name,
                        sizeof(ifaces[total].name)) >=
                                sizeof(ifaces[total].name)) {