Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Unified Diff: fusl/src/network/if_nametoindex.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fusl/src/network/if_nameindex.c ('k') | fusl/src/network/in6addr_any.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/src/network/if_nametoindex.c
diff --git a/fusl/src/network/if_nametoindex.c b/fusl/src/network/if_nametoindex.c
new file mode 100644
index 0000000000000000000000000000000000000000..cb6ec054efbd971fc362bc7dd24c738fc12eb997
--- /dev/null
+++ b/fusl/src/network/if_nametoindex.c
@@ -0,0 +1,18 @@
+#define _GNU_SOURCE
+#include <net/if.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <string.h>
+#include "syscall.h"
+
+unsigned if_nametoindex(const char *name)
+{
+ struct ifreq ifr;
+ int fd, r;
+
+ if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return -1;
+ strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
+ r = ioctl(fd, SIOCGIFINDEX, &ifr);
+ __syscall(SYS_close, fd);
+ return r < 0 ? 0 : ifr.ifr_ifindex;
+}
« no previous file with comments | « fusl/src/network/if_nameindex.c ('k') | fusl/src/network/in6addr_any.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698