lib:socket: get interface index from kernel
[sfrench/samba-autobuild/.git] / 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)) {