diff options
| author | Dmitry Shmidt <dimitrysh@google.com> | 2012-07-10 10:48:38 -0700 |
|---|---|---|
| committer | Dmitry Shmidt <dimitrysh@google.com> | 2012-07-10 17:49:22 -0700 |
| commit | 2d9a6281ca4fdacd88098f3b135b89b9d0c65226 (patch) | |
| tree | a9ebab46311f9554a5d973c13758316f850cdf2d /libnl_2 | |
| parent | de92239055ac87e51ef7e868ed9697d038a72368 (diff) | |
| download | system_core-2d9a6281ca4fdacd88098f3b135b89b9d0c65226.tar.gz system_core-2d9a6281ca4fdacd88098f3b135b89b9d0c65226.tar.bz2 system_core-2d9a6281ca4fdacd88098f3b135b89b9d0c65226.zip | |
libnl_2: Extend genl_ctrl_resolve() to support "nl80211" name
Change-Id: I46759ba55bdf42baef7c1f43de845b0dc846d502
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
Diffstat (limited to 'libnl_2')
| -rw-r--r-- | libnl_2/genl/genl.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/libnl_2/genl/genl.c b/libnl_2/genl/genl.c index 244299327..05431d618 100644 --- a/libnl_2/genl/genl.c +++ b/libnl_2/genl/genl.c @@ -21,6 +21,8 @@ #include <stdio.h> #include <sys/time.h> #include <linux/netlink.h> +#include <netlink/genl/ctrl.h> +#include <netlink/genl/family.h> #include "netlink-types.h" /* Get head of attribute data. */ @@ -250,7 +252,6 @@ error: struct genl_family *genl_ctrl_search_by_name(struct nl_cache *cache, \ const char *name) { - /* TODO: When will we release this memory ? */ struct genl_family *gf = (struct genl_family *) \ malloc(sizeof(struct genl_family)); if (!gf) @@ -262,7 +263,7 @@ struct genl_family *genl_ctrl_search_by_name(struct nl_cache *cache, \ /* Overriding cache pointer as family id for now */ gf->gf_id = (uint16_t) ((uint32_t) cache); - strcpy(gf->gf_name, "nl80211"); + strncpy(gf->gf_name, name, GENL_NAMSIZ); return gf; fail: @@ -272,15 +273,29 @@ fail: int genl_ctrl_resolve(struct nl_sock *sk, const char *name) { + struct nl_cache *cache = NULL; + struct genl_family *gf = NULL; + int id = -1; + /* Hack to support wpa_supplicant */ if (strcmp(name, "nlctrl") == 0) return NETLINK_GENERIC; - else { - int errsv = errno; - fprintf(stderr, \ - "Only nlctrl supported by genl_ctrl_resolve!\n"); - return -errsv; + + if (strcmp(name, "nl80211") != 0) { + fprintf(stderr, "%s is not supported\n", name); + return id; } -} + if (!genl_ctrl_alloc_cache(sk, &cache)) { + gf = genl_ctrl_search_by_name(cache, name); + if (gf) + id = genl_family_get_id(gf); + } + + if (gf) + genl_family_put(gf); + if (cache) + nl_cache_free(cache); + return id; +} |
