static int nl80211_init(void) { int err, fd; if (!nls) { nls = malloc(sizeof(struct nl80211_state)); if (!nls) { err = -ENOMEM; goto err; } memset(nls, 0, sizeof(*nls)); nls->nl_sock = nl_socket_alloc(); if (!nls->nl_sock) { err = -ENOMEM; goto err; } if (genl_connect(nls->nl_sock)) { err = -ENOLINK; goto err; } fd = nl_socket_get_fd(nls->nl_sock); if (fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC) < 0) { err = -EINVAL; goto err; } if (genl_ctrl_alloc_cache(nls->nl_sock, &nls->nl_cache)) { err = -ENOMEM; goto err; } nls->nl80211 = genl_ctrl_search_by_name(nls->nl_cache, "nl80211"); if (!nls->nl80211) { err = -ENOENT; goto err; } nls->nlctrl = genl_ctrl_search_by_name(nls->nl_cache, "nlctrl"); if (!nls->nlctrl) { err = -ENOENT; goto err; } } return 0; err: nl80211_close(); return err; }
void iwinfo_finish(void) { #ifdef USE_WL wl_close(); #endif #ifdef USE_MADWIFI madwifi_close(); #endif #ifdef USE_NL80211 nl80211_close(); #endif wext_close(); iwinfo_close(); }
/* Shutdown backends */ static int iwinfo_L__gc(lua_State *L) { #ifdef USE_WL wl_close(); #endif #ifdef USE_MADWIFI madwifi_close(); #endif #ifdef USE_NL80211 nl80211_close(); #endif wext_close(); iwinfo_close(); }