]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
initial commit
authorJohannes Berg <johannes@sipsolutions.net>
Fri, 28 Sep 2007 20:11:34 +0000 (22:11 +0200)
committerJohannes Berg <johannes@sipsolutions.net>
Fri, 28 Sep 2007 20:11:34 +0000 (22:11 +0200)
.gitignore [new file with mode: 0644]
Makefile [new file with mode: 0644]
iw.c [new file with mode: 0644]
iw.h [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..bc3b431
--- /dev/null
@@ -0,0 +1,2 @@
+iw
+*~
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..2fbb56c
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,9 @@
+# adjust this
+LIBNL = /home/johannes/Projects/libnl/
+
+CFLAGS += -Wall -lnl -I$(LIBNL)/include/ -L$(LIBNL)/lib/
+
+iw:    iw.c iw.h
+
+clean:
+       rm -f iw *~
diff --git a/iw.c b/iw.c
new file mode 100644 (file)
index 0000000..e973fea
--- /dev/null
+++ b/iw.c
@@ -0,0 +1,80 @@
+/*
+ * nl80211 userspace tool
+ *
+ * Copyright 2007      Johannes Berg <johannes@sipsolutions.net>
+ *
+ * GPLv2
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <netlink/genl/genl.h>
+#include <netlink/genl/family.h>
+#include <netlink/genl/ctrl.h>  
+#include <netlink/msg.h>
+#include <netlink/attr.h>
+#include <linux/nl80211.h>
+
+#include "iw.h"
+
+
+static int nl80211_init(struct nl80211_state *state)
+{
+       int err;
+
+       state->nl_handle = nl_handle_alloc();
+       if (!state->nl_handle) {
+               fprintf(stderr, "Failed to allocate netlink handle.\n");
+               return -ENOMEM;
+       }
+
+       if (genl_connect(state->nl_handle)) {
+               fprintf(stderr, "Failed to connect to generic netlink.\n");
+               err = -ENOLINK;
+               goto out_handle_destroy;
+       }
+
+       state->nl_cache = genl_ctrl_alloc_cache(state->nl_handle);
+       if (!state->nl_cache) {
+               fprintf(stderr, "Failed to allocate generic netlink cache.\n");
+               err = -ENOMEM;
+               goto out_handle_destroy;
+       }
+
+       state->nl80211 = genl_ctrl_search_by_name(state->nl_cache, "nl80211");
+       if (!state->nl80211) {
+               fprintf(stderr, "nl80211 not found.\n");
+               err = -ENOENT;
+               goto out_cache_free;
+       }
+
+       return 0;
+
+ out_cache_free:
+       nl_cache_free(state->nl_cache);
+ out_handle_destroy:
+       nl_handle_destroy(state->nl_handle);
+       return err;
+}
+
+static void nl80211_cleanup(struct nl80211_state *state)
+{
+       genl_family_put(state->nl80211);
+       nl_cache_free(state->nl_cache);
+       nl_handle_destroy(state->nl_handle);
+}
+
+int main(int argc, char **argv)
+{
+       struct nl80211_state nlstate;
+       int err;
+
+       err = nl80211_init(&nlstate);
+       if (err)
+               return 1;
+
+
+       nl80211_cleanup(&nlstate);
+
+       return 0;
+}
diff --git a/iw.h b/iw.h
new file mode 100644 (file)
index 0000000..09faa87
--- /dev/null
+++ b/iw.h
@@ -0,0 +1,14 @@
+#ifndef __IW_H
+#define __IW_H
+
+#include <netlink/genl/genl.h>
+#include <netlink/genl/family.h>
+#include <netlink/genl/ctrl.h>
+
+struct nl80211_state {
+       struct nl_handle *nl_handle;
+       struct nl_cache *nl_cache;
+       struct genl_family *nl80211;
+};
+
+#endif /* __IW_H */