本文整理汇总了C++中eloop_register_read_sock函数的典型用法代码示例。如果您正苦于以下问题:C++ eloop_register_read_sock函数的具体用法?C++ eloop_register_read_sock怎么用?C++ eloop_register_read_sock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了eloop_register_read_sock函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: radius_client_init_acct
static int radius_client_init_acct(struct radius_client_data *radius)
{
struct hostapd_radius_servers *conf = radius->conf;
int ok = 0;
radius_close_acct_sockets(radius);
radius->acct_serv_sock = socket(PF_INET, SOCK_DGRAM, 0);
if (radius->acct_serv_sock < 0)
wpa_printf(MSG_INFO, "RADIUS: socket[PF_INET,SOCK_DGRAM]: %s",
strerror(errno));
else {
radius_client_disable_pmtu_discovery(radius->acct_serv_sock);
ok++;
}
#ifdef CONFIG_IPV6
radius->acct_serv_sock6 = socket(PF_INET6, SOCK_DGRAM, 0);
if (radius->acct_serv_sock6 < 0)
wpa_printf(MSG_INFO, "RADIUS: socket[PF_INET6,SOCK_DGRAM]: %s",
strerror(errno));
else
ok++;
#endif /* CONFIG_IPV6 */
if (ok == 0)
return -1;
radius_change_server(radius, conf->acct_server, NULL,
radius->acct_serv_sock, radius->acct_serv_sock6,
0);
if (radius->acct_serv_sock >= 0 &&
eloop_register_read_sock(radius->acct_serv_sock,
radius_client_receive, radius,
(void *) RADIUS_ACCT)) {
wpa_printf(MSG_INFO, "RADIUS: Could not register read socket for accounting server");
radius_close_acct_sockets(radius);
return -1;
}
#ifdef CONFIG_IPV6
if (radius->acct_serv_sock6 >= 0 &&
eloop_register_read_sock(radius->acct_serv_sock6,
radius_client_receive, radius,
(void *) RADIUS_ACCT)) {
wpa_printf(MSG_INFO, "RADIUS: Could not register read socket for accounting server");
radius_close_acct_sockets(radius);
return -1;
}
#endif /* CONFIG_IPV6 */
return 0;
}
开发者ID:9A9A,项目名称:wpa_supplicant-fork,代码行数:54,代码来源:radius_client.c
示例2: radius_client_init_auth
static int radius_client_init_auth(struct radius_client_data *radius)
{
struct hostapd_radius_servers *conf = radius->conf;
int ok = 0;
radius->auth_serv_sock = socket(PF_INET, SOCK_DGRAM, 0);
if (radius->auth_serv_sock < 0)
perror("socket[PF_INET,SOCK_DGRAM]");
else {
radius_client_disable_pmtu_discovery(radius->auth_serv_sock);
ok++;
}
#ifdef CONFIG_IPV6
radius->auth_serv_sock6 = socket(PF_INET6, SOCK_DGRAM, 0);
if (radius->auth_serv_sock6 < 0)
perror("socket[PF_INET6,SOCK_DGRAM]");
else
ok++;
#endif /* CONFIG_IPV6 */
if (ok == 0)
return -1;
radius_change_server(radius, conf->auth_server, NULL,
radius->auth_serv_sock, radius->auth_serv_sock6,
1);
if (radius->auth_serv_sock >= 0 &&
eloop_register_read_sock(radius->auth_serv_sock,
radius_client_receive, radius,
(void *) RADIUS_AUTH)) {
printf("Could not register read socket for authentication "
"server\n");
return -1;
}
#ifdef CONFIG_IPV6
if (radius->auth_serv_sock6 >= 0 &&
eloop_register_read_sock(radius->auth_serv_sock6,
radius_client_receive, radius,
(void *) RADIUS_AUTH)) {
printf("Could not register read socket for authentication "
"server\n");
return -1;
}
#endif /* CONFIG_IPV6 */
return 0;
}
开发者ID:flwh,项目名称:Alcatel_OT_985_kernel,代码行数:50,代码来源:radius_client.c
示例3: l2_packet_init_libpcap
static int l2_packet_init_libpcap(struct l2_packet_data *l2,
unsigned short protocol)
{
bpf_u_int32 pcap_maskp, pcap_netp;
char pcap_filter[200], pcap_err[PCAP_ERRBUF_SIZE];
struct bpf_program pcap_fp;
pcap_lookupnet(l2->ifname, &pcap_netp, &pcap_maskp, pcap_err);
l2->pcap = pcap_open_live(l2->ifname, 2500, 0, 10, pcap_err);
if (l2->pcap == NULL) {
fprintf(stderr, "pcap_open_live: %s\n", pcap_err);
fprintf(stderr, "ifname='%s'\n", l2->ifname);
return -1;
}
if (pcap_datalink(l2->pcap) != DLT_EN10MB &&
pcap_set_datalink(l2->pcap, DLT_EN10MB) < 0) {
fprintf(stderr, "pcap_set_datalink(DLT_EN10MB): %s\n",
pcap_geterr(l2->pcap));
return -1;
}
os_snprintf(pcap_filter, sizeof(pcap_filter),
"not ether src " MACSTR " and "
"( ether dst " MACSTR " or ether dst " MACSTR " ) and "
"ether proto 0x%x",
MAC2STR(l2->own_addr), /* do not receive own packets */
MAC2STR(l2->own_addr), MAC2STR(pae_group_addr),
protocol);
if (pcap_compile(l2->pcap, &pcap_fp, pcap_filter, 1, pcap_netp) < 0) {
fprintf(stderr, "pcap_compile: %s\n", pcap_geterr(l2->pcap));
return -1;
}
if (pcap_setfilter(l2->pcap, &pcap_fp) < 0) {
fprintf(stderr, "pcap_setfilter: %s\n", pcap_geterr(l2->pcap));
return -1;
}
pcap_freecode(&pcap_fp);
#ifndef __sun__
/*
* When libpcap uses BPF we must enable "immediate mode" to
* receive frames right away; otherwise the system may
* buffer them for us.
*/
{
unsigned int on = 1;
if (ioctl(pcap_fileno(l2->pcap), BIOCIMMEDIATE, &on) < 0) {
fprintf(stderr, "%s: cannot enable immediate mode on "
"interface %s: %s\n",
__func__, l2->ifname, strerror(errno));
/* XXX should we fail? */
}
}
#endif /* __sun__ */
eloop_register_read_sock(pcap_get_selectable_fd(l2->pcap),
l2_packet_receive, l2, l2->pcap);
return 0;
}
开发者ID:kusumi,项目名称:DragonFlyBSD,代码行数:60,代码来源:l2_packet.c
示例4: l2_packet_init
struct l2_packet_data * l2_packet_init(
const char *ifname, const u8 *own_addr, unsigned short protocol,
void (*rx_callback)(void *ctx, const u8 *src_addr,
const u8 *buf, size_t len),
void *rx_callback_ctx, int l2_hdr)
{
struct l2_packet_data *l2;
l2 = (struct l2_packet_data*)os_zalloc(sizeof(struct l2_packet_data));
if (l2 == NULL)
return NULL;
os_strlcpy(l2->ifname, ifname, sizeof(l2->ifname));
l2->rx_callback = rx_callback;
l2->rx_callback_ctx = rx_callback_ctx;
l2->l2_hdr = l2_hdr;
/*
* TODO: open connection for receiving frames
*/
l2->fd = -1;
eloop_register_read_sock(l2->fd, l2_packet_receive, l2, NULL);
return l2;
}
开发者ID:xiaoyeqiannian,项目名称:githubck,代码行数:25,代码来源:l2_packet_none.c
示例5: netlink_init
struct netlink_data * netlink_init(struct netlink_config *cfg)
{
struct netlink_data *netlink;
struct sockaddr_nl local;
netlink = os_zalloc(sizeof(*netlink));
if (netlink == NULL)
return NULL;
netlink->cfg = cfg;
netlink->sock = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (netlink->sock < 0) {
wpa_printf(MSG_ERROR, "netlink: Failed to open netlink "
"socket: %s", strerror(errno));
netlink_deinit(netlink);
return NULL;
}
os_memset(&local, 0, sizeof(local));
local.nl_family = AF_NETLINK;
local.nl_groups = RTMGRP_LINK;
if (bind(netlink->sock, (struct sockaddr *) &local, sizeof(local)) < 0)
{
wpa_printf(MSG_ERROR, "netlink: Failed to bind netlink "
"socket: %s", strerror(errno));
netlink_deinit(netlink);
return NULL;
}
eloop_register_read_sock(netlink->sock, netlink_receive, netlink,
NULL);
return netlink;
}
开发者ID:RasmusKoldsoe,项目名称:performand.k70.2,代码行数:35,代码来源:netlink.c
示例6:
int32
WPASupplicantApp::_SupplicantThread(void *data)
{
WPASupplicantApp *app = (WPASupplicantApp *)data;
// Register our notify socket with the polling event loop.
if (eloop_register_read_sock(app->fNotifySockets[0],
_EventLoopProcessEvents, app->fWPAGlobal, app) != 0) {
return B_ERROR;
}
wpa_supplicant_run(app->fWPAGlobal);
eloop_unregister_read_sock(app->fNotifySockets[0]);
// There are two reasons why the supplicant thread quit:
// 1. The event loop was terminated because of a signal or error and the
// application is still there and running.
// 2. The app has quit and stopped the event loop.
//
// In case of 2. we're done, but in case of 1. we need to quit the still
// running application. We use the app messenger to reach the app if it is
// still running. If it already quit the SendMessage() will simply fail.
be_app_messenger.SendMessage(B_QUIT_REQUESTED);
return B_OK;
}
开发者ID:kallisti5,项目名称:wpa_supplicant-haiku,代码行数:27,代码来源:main_haiku.cpp
示例7: madwifi_wireless_event_init
static int
madwifi_wireless_event_init(void *priv)
{
struct madwifi_driver_data *drv = priv;
int s;
struct sockaddr_nl local;
madwifi_get_we_version(drv);
drv->wext_sock = -1;
s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (s < 0) {
perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
return -1;
}
memset(&local, 0, sizeof(local));
local.nl_family = AF_NETLINK;
local.nl_groups = RTMGRP_LINK;
if (bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
perror("bind(netlink)");
close(s);
return -1;
}
eloop_register_read_sock(s, madwifi_wireless_event_receive, drv, NULL);
drv->wext_sock = s;
return 0;
}
开发者ID:Rajeev-Sirasanagandla,项目名称:t80_platform_external,代码行数:31,代码来源:driver_madwifi.c
示例8: edit_init
int edit_init(void (*cmd_cb)(void *ctx, char *cmd),
void (*eof_cb)(void *ctx),
char ** (*completion_cb)(void *ctx, const char *cmd, int pos),
void *ctx, const char *history_file, const char *ps)
{
edit_cb_ctx = ctx;
edit_cmd_cb = cmd_cb;
edit_eof_cb = eof_cb;
edit_completion_cb = completion_cb;
rl_attempted_completion_function = readline_completion;
if (history_file) {
read_history(history_file);
stifle_history(100);
}
eloop_register_read_sock(STDIN_FILENO, edit_read_char, NULL, NULL);
if (ps) {
size_t blen = os_strlen(ps) + 3;
char *ps2 = os_malloc(blen);
if (ps2) {
os_snprintf(ps2, blen, "%s> ", ps);
rl_callback_handler_install(ps2, readline_cmd_handler);
os_free(ps2);
return 0;
}
}
rl_callback_handler_install("> ", readline_cmd_handler);
return 0;
}
开发者ID:0x000000FF,项目名称:wpa_supplicant_for_edison,代码行数:33,代码来源:edit_readline.c
示例9: rtl871x_mgnt_sock_init
static int rtl871x_mgnt_sock_init(struct rtl871x_driver_data *drv, const char *name)
{
int sock;
struct ifreq ifr;
struct sockaddr_ll addr;
sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (sock < 0) {
perror("socket[PF_PACKET,SOCK_RAW]");
return -1;
}
if (eloop_register_read_sock(sock, rtl871x_recvive_mgmt_frame, drv->hapd, NULL))
{
printf("Could not register read socket\n");
return -1;
}
memset(&ifr, 0, sizeof(ifr));
//snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%sap", drv->iface);
os_strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (ioctl(sock, SIOCGIFINDEX, &ifr) != 0) {
perror("ioctl(SIOCGIFINDEX)");
return -1;
}
//if (rtl871x_set_iface_flags(drv, 1)) {
// return -1;
//}
memset(&addr, 0, sizeof(addr));
addr.sll_family = AF_PACKET;
addr.sll_ifindex = ifr.ifr_ifindex;
wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
addr.sll_ifindex);
if (bind(sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
perror("bind");
return -1;
}
memset(&ifr, 0, sizeof(ifr));
os_strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (ioctl(sock, SIOCGIFHWADDR, &ifr) != 0) {
perror("ioctl(SIOCGIFHWADDR)");
return -1;
}
if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
printf("Invalid HW-addr family 0x%04x\n",
ifr.ifr_hwaddr.sa_family);
return -1;
}
//memcpy(drv->hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
return sock;
}
开发者ID:LucaBongiorni,项目名称:hostapd-rtl871xdrv,代码行数:60,代码来源:driver_rtw.c
示例10: os_zalloc
struct ctrl_iface_global_priv *wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global)
{
struct ctrl_iface_global_priv *priv;
struct sockaddr_in addr;
int port = WPA_GLOBAL_CTRL_IFACE_PORT;
priv = os_zalloc(sizeof(*priv));
if (priv == NULL) {
return NULL;
}
priv->sock = -1;
os_get_random(priv->cookie, COOKIE_LEN);
if (global->params.ctrl_interface == NULL) {
return priv;
}
wpa_printf(MSG_DEBUG, "Global control interface '%s'", global->params.ctrl_interface);
/* WARNING: UDP is unreliable (indirectly selected by use of SOCK_DRAM), hence not suitable
* for API interfaces.
* - change to use TCP (SOCK_STREAM), for a reliable transport. */
priv->sock = socket(PF_INET, SOCK_DGRAM, 0);
if (priv->sock < 0) {
wpa_printf(MSG_ERROR, "socket(PF_INET): %s", strerror(errno));
goto fail;
}
os_memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
#ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
addr.sin_addr.s_addr = INADDR_ANY;
#else /* CONFIG_CTRL_IFACE_UDP_REMOTE */
addr.sin_addr.s_addr = htonl((127 << 24) | 1);
#endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
try_again:
addr.sin_port = htons(port);
if (bind(priv->sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
port++;
if ((port - WPA_GLOBAL_CTRL_IFACE_PORT) < WPA_GLOBAL_CTRL_IFACE_PORT_LIMIT) {
goto try_again;
}
wpa_printf(MSG_ERROR, "bind(AF_INET): %s", strerror(errno));
goto fail;
}
#ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
wpa_printf(MSG_DEBUG, "global_ctrl_iface_init UDP port: %d", port);
#endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
eloop_register_read_sock(priv->sock, wpa_supplicant_global_ctrl_iface_receive, global, priv);
return priv;
fail:
if (priv->sock >= 0) {
close(priv->sock);
}
os_free(priv);
return NULL;
}
开发者ID:drashti304,项目名称:TizenRT,代码行数:60,代码来源:ctrl_iface_udp.c
示例11: wsc_ie_init
int wsc_ie_init(struct hostapd_data *hapd)
{
struct sockaddr_in to;
char sendBuf[5];
wpa_printf(MSG_DEBUG, "WSC_IE: In wsc_ie_init");
g_wsc_ie_data = malloc(sizeof(WSC_IE_DATA));
if (g_wsc_ie_data == NULL) {
return -1;
}
memset(g_wsc_ie_data, 0, sizeof(WSC_IE_DATA));
g_wsc_ie_data->hapd = hapd;
g_wsc_ie_data->udpFdCom = udp_open();
eloop_register_read_sock(g_wsc_ie_data->udpFdCom, wsc_ie_read_callback,
g_wsc_ie_data, NULL);
/* Send a start packet */
strcpy(sendBuf, "PORT");
to.sin_addr.s_addr = inet_addr(WSC_WLAN_UDP_ADDR);
to.sin_family = AF_INET;
to.sin_port = htons(WSC_WLAN_UDP_PORT);
if (udp_write(g_wsc_ie_data->udpFdCom, sendBuf, 5, &to) < 5) {
wpa_printf(MSG_ERROR, "WSC_IE: Sending Port message to "
"upper Layer failed");
return -1;
} else {
wpa_printf(MSG_DEBUG, "WSC_IE: send port = %d", WSC_WLAN_UDP_PORT );
}
return 0;
}
开发者ID:jameshilliard,项目名称:actiontec_opensrc_mi424wr-rev-ef_fw-20-19-8,代码行数:35,代码来源:wsc_ie.c
示例12: wpa_driver_register_event_cb
int wpa_driver_register_event_cb(struct wpa_driver_ndis_data *drv)
{
struct sockaddr_in addr;
drv->event_sock = socket(PF_INET, SOCK_DGRAM, 0);
if (drv->event_sock < 0) {
perror("socket");
return -1;
}
/* These events are received from an external program, ndis_events,
* which is converting WMI events to more "UNIX-like" input for
* wpa_supplicant, i.e., UDP packets that can be received through the
* eloop mechanism. */
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl((127 << 24) | 1);
addr.sin_port = htons(9876);
if (bind(drv->event_sock, (struct sockaddr *) &addr, sizeof(addr)) < 0)
{
perror("bind");
close(drv->event_sock);
drv->event_sock = -1;
return -1;
}
eloop_register_read_sock(drv->event_sock, wpa_driver_ndis_event_cb,
drv, NULL);
return 0;
}
开发者ID:NikhilNJ,项目名称:screenplay-dx,代码行数:31,代码来源:driver_ndis_.c
示例13: wpa_printf
struct wpas_binder_priv *wpas_binder_init(struct wpa_global *global)
{
struct wpas_binder_priv *priv;
wpa_supplicant_binder::BinderManager *binder_manager;
priv = (wpas_binder_priv *)os_zalloc(sizeof(*priv));
if (!priv)
return NULL;
priv->global = global;
android::ProcessState::self()->setThreadPoolMaxThreadCount(0);
android::IPCThreadState::self()->disableBackgroundScheduling(true);
android::IPCThreadState::self()->setupPolling(&priv->binder_fd);
wpa_printf(MSG_INFO, "Process binder events on FD %d", priv->binder_fd);
if (priv->binder_fd < 0)
goto err;
/* Look for read events from the binder socket in the eloop. */
if (eloop_register_read_sock(
priv->binder_fd, wpas_binder_sock_handler, global, priv) < 0)
goto err;
binder_manager = wpa_supplicant_binder::BinderManager::getInstance();
if (!binder_manager)
goto err;
binder_manager->registerBinderService(global);
/* We may not need to store this binder manager reference in the
* global data strucure because we've made it a singleton class. */
priv->binder_manager = (void *)binder_manager;
return priv;
err:
wpas_binder_deinit(priv);
return NULL;
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:35,代码来源:binder.cpp
示例14: ctrl_connect
static void ctrl_connect(int sock, void *eloop_ctx, void *sock_ctx)
{
struct wlantest *wt = eloop_ctx;
int conn, i;
conn = accept(sock, NULL, NULL);
if (conn < 0) {
wpa_printf(MSG_INFO, "accept(ctrl): %s", strerror(errno));
return;
}
wpa_printf(MSG_MSGDUMP, "New control interface connection %d", conn);
for (i = 0; i < MAX_CTRL_CONNECTIONS; i++) {
if (wt->ctrl_socks[i] < 0)
break;
}
if (i == MAX_CTRL_CONNECTIONS) {
wpa_printf(MSG_INFO, "No room for new control connection");
close(conn);
return;
}
wt->ctrl_socks[i] = conn;
eloop_register_read_sock(conn, ctrl_read, wt, NULL);
}
开发者ID:cozybit,项目名称:hostap-sae,代码行数:26,代码来源:ctrl.c
示例15: wpa_supplicant_global_ctrl_iface_init
struct ctrl_iface_global_priv *
wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global)
{
struct ctrl_iface_global_priv *priv;
struct sockaddr_in addr;
int port = WPA_GLOBAL_CTRL_IFACE_PORT;
priv = os_zalloc(sizeof(*priv));
if (priv == NULL)
return NULL;
priv->sock = -1;
os_get_random(priv->cookie, COOKIE_LEN);
if (global->params.ctrl_interface == NULL)
return priv;
wpa_printf(MSG_DEBUG, "Global control interface '%s'",
global->params.ctrl_interface);
priv->sock = socket(PF_INET, SOCK_DGRAM, 0);
if (priv->sock < 0) {
perror("socket(PF_INET)");
goto fail;
}
os_memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
#ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
addr.sin_addr.s_addr = INADDR_ANY;
#else /* CONFIG_CTRL_IFACE_UDP_REMOTE */
addr.sin_addr.s_addr = htonl((127 << 24) | 1);
#endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
try_again:
addr.sin_port = htons(port);
if (bind(priv->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
port++;
if ((port - WPA_GLOBAL_CTRL_IFACE_PORT) <
WPA_GLOBAL_CTRL_IFACE_PORT_LIMIT)
goto try_again;
perror("bind(AF_INET)");
goto fail;
}
#ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
wpa_printf(MSG_DEBUG, "global_ctrl_iface_init UDP port: %d", port);
#endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
eloop_register_read_sock(priv->sock,
wpa_supplicant_global_ctrl_iface_receive,
global, priv);
return priv;
fail:
if (priv->sock >= 0)
close(priv->sock);
os_free(priv);
return NULL;
}
开发者ID:Alkzndr,项目名称:freebsd,代码行数:59,代码来源:ctrl_iface_udp.c
示例16: wpa_driver_wext_init
void * wpa_driver_wext_init(void *ctx, const char *ifname)
{
int s, flags;
struct sockaddr_nl local;
struct wpa_driver_wext_data *drv;
drv = malloc(sizeof(*drv));
if (drv == NULL)
return NULL;
memset(drv, 0, sizeof(*drv));
drv->ctx = ctx;
strncpy(drv->ifname, ifname, sizeof(drv->ifname));
drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
if (drv->ioctl_sock < 0) {
perror("socket(PF_INET,SOCK_DGRAM)");
free(drv);
return NULL;
}
s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (s < 0) {
perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
close(drv->ioctl_sock);
free(drv);
return NULL;
}
memset(&local, 0, sizeof(local));
local.nl_family = AF_NETLINK;
local.nl_groups = RTMGRP_LINK;
if (bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
perror("bind(netlink)");
close(s);
close(drv->ioctl_sock);
free(drv);
return NULL;
}
eloop_register_read_sock(s, wpa_driver_wext_event_receive, drv, ctx);
drv->event_sock = s;
/*
* Make sure that the driver does not have any obsolete PMKID entries.
*/
wpa_driver_wext_flush_pmkid(drv);
if (wpa_driver_wext_set_mode(drv, 0) < 0) {
printf("Could not configure driver to use managed mode\n");
}
if (wpa_driver_wext_get_ifflags(drv, &flags) != 0 ||
wpa_driver_wext_set_ifflags(drv, flags | IFF_UP) != 0) {
printf("Could not set interface '%s' UP\n", drv->ifname);
}
return drv;
}
开发者ID:vutukurikishore,项目名称:wpa_supplicant,代码行数:58,代码来源:driver_wext.c
示例17: l2_packet_init
struct l2_packet_data * l2_packet_init(
const char *ifname, const u8 *own_addr, unsigned short protocol,
void (*rx_callback)(void *ctx, const u8 *src_addr,
const u8 *buf, size_t len),
void *rx_callback_ctx, int l2_hdr)
{
struct l2_packet_data *l2;
struct ifreq ifr;
struct sockaddr_ll ll;
l2 = os_zalloc(sizeof(struct l2_packet_data));
if (l2 == NULL)
return NULL;
os_strlcpy(l2->ifname, ifname, sizeof(l2->ifname));
l2->rx_callback = rx_callback;
l2->rx_callback_ctx = rx_callback_ctx;
l2->l2_hdr = l2_hdr;
l2->fd = socket(PF_PACKET, l2_hdr ? SOCK_RAW : SOCK_DGRAM,
htons(protocol));
if (l2->fd < 0) {
perror("socket(PF_PACKET)");
os_free(l2);
return NULL;
}
os_memset(&ifr, 0, sizeof(ifr));
os_strlcpy(ifr.ifr_name, l2->ifname, sizeof(ifr.ifr_name));
if (ioctl(l2->fd, SIOCGIFINDEX, &ifr) < 0) {
perror("ioctl[SIOCGIFINDEX]");
close(l2->fd);
os_free(l2);
return NULL;
}
l2->ifindex = ifr.ifr_ifindex;
os_memset(&ll, 0, sizeof(ll));
ll.sll_family = PF_PACKET;
ll.sll_ifindex = ifr.ifr_ifindex;
ll.sll_protocol = htons(protocol);
if (bind(l2->fd, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
perror("bind[PF_PACKET]");
close(l2->fd);
os_free(l2);
return NULL;
}
if (ioctl(l2->fd, SIOCGIFHWADDR, &ifr) < 0) {
perror("ioctl[SIOCGIFHWADDR]");
close(l2->fd);
os_free(l2);
return NULL;
}
os_memcpy(l2->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
eloop_register_read_sock(l2->fd, l2_packet_receive, l2, NULL);
return l2;
}
开发者ID:Austrie,项目名称:android_external_hostapd,代码行数:58,代码来源:l2_packet_linux.c
示例18: wpa_driver_broadcom_init
static void * wpa_driver_broadcom_init(void *ctx, const char *ifname)
{
int s;
struct sockaddr_ll ll;
struct wpa_driver_broadcom_data *drv;
struct ifreq ifr;
/* open socket to kernel */
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("socket");
return NULL;
}
/* do it */
os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
perror(ifr.ifr_name);
return NULL;
}
drv = os_zalloc(sizeof(*drv));
if (drv == NULL)
return NULL;
drv->ctx = ctx;
os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname));
drv->ioctl_sock = s;
s = socket(PF_PACKET, SOCK_RAW, ntohs(ETH_P_802_2));
if (s < 0) {
perror("socket(PF_PACKET, SOCK_RAW, ntohs(ETH_P_802_2))");
close(drv->ioctl_sock);
os_free(drv);
return NULL;
}
os_memset(&ll, 0, sizeof(ll));
ll.sll_family = AF_PACKET;
ll.sll_protocol = ntohs(ETH_P_802_2);
ll.sll_ifindex = ifr.ifr_ifindex;
ll.sll_hatype = 0;
ll.sll_pkttype = PACKET_HOST;
ll.sll_halen = 0;
if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
perror("bind(netlink)");
close(s);
close(drv->ioctl_sock);
os_free(drv);
return NULL;
}
eloop_register_read_sock(s, wpa_driver_broadcom_event_receive, ctx,
NULL);
drv->event_sock = s;
wpa_driver_broadcom_set_wpa(drv, 1);
return drv;
}
开发者ID:09sea98,项目名称:rtl8188eu,代码行数:58,代码来源:driver_broadcom.c
示例19: wpa_driver_awext_open_mlme
static int wpa_driver_awext_open_mlme(struct wpa_driver_awext_data *drv)
{
int flags, ifindex, s, *i;
struct sockaddr_ll addr;
struct iwreq iwr;
os_memset(&iwr, 0, sizeof(iwr));
os_strncpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
i = (int *) iwr.u.name;
*i++ = PRISM2_PARAM_USER_SPACE_MLME;
*i++ = 1;
if (ioctl(drv->ioctl_sock, PRISM2_IOCTL_PRISM2_PARAM, &iwr) < 0) {
wpa_printf(MSG_ERROR, "WEXT: Failed to configure driver to "
"use user space MLME");
return -1;
}
ifindex = if_nametoindex(drv->wext->mlmedev);
if (ifindex == 0) {
wpa_printf(MSG_ERROR, "WEXT: mlmedev='%s' not found",
drv->mlmedev);
return -1;
}
if (wpa_driver_awext_get_ifflags_ifname(drv, drv->wext->mlmedev, &flags) != 0
|| wpa_driver_awext_set_ifflags_ifname(drv, drv->wext->mlmedev,
flags | IFF_UP) != 0) {
wpa_printf(MSG_ERROR, "WEXT: Could not set interface "
"'%s' UP", drv->mlmedev);
return -1;
}
s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (s < 0) {
perror("socket[PF_PACKET,SOCK_RAW]");
return -1;
}
os_memset(&addr, 0, sizeof(addr));
addr.sll_family = AF_PACKET;
addr.sll_ifindex = ifindex;
if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
perror("bind(MLME)");
return -1;
}
if (eloop_register_read_sock(s, wpa_driver_awext_mlme_read, drv, NULL))
{
wpa_printf(MSG_ERROR, "WEXT: Could not register MLME read "
"socket");
close(s);
return -1;
}
return s;
}
开发者ID:kamejoko80,项目名称:my_km233,代码行数:58,代码来源:driver_awext.c
示例20: hostapd_init_sockets
int hostapd_init_sockets(struct hostap_driver_data *drv)
{
struct hostapd_data *hapd = drv->hapd;
struct ifreq ifr;
struct sockaddr_ll addr;
drv->sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (drv->sock < 0) {
perror("socket[PF_PACKET,SOCK_RAW]");
return -1;
}
if (eloop_register_read_sock(drv->sock, handle_read, drv->hapd, NULL))
{
printf("Could not register read socket\n");
return -1;
}
memset(&ifr, 0, sizeof(ifr));
snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%sap", drv->iface);
if (ioctl(drv->sock, SIOCGIFINDEX, &ifr) != 0) {
perror("ioctl(SIOCGIFINDEX)");
return -1;
}
if (hostapd_set_iface_flags(drv, 1)) {
return -1;
}
memset(&addr, 0, sizeof(addr));
addr.sll_family = AF_PACKET;
addr.sll_ifindex = ifr.ifr_ifindex;
HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL,
"Opening raw packet socket for ifindex %d\n",
addr.sll_ifindex);
if (bind(drv->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
perror("bind");
return -1;
}
memset(&ifr, 0, sizeof(ifr));
snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", drv->iface);
if (ioctl(drv->sock, SIOCGIFHWADDR, &ifr) != 0) {
perror("ioctl(SIOCGIFHWADDR)");
return -1;
}
if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
printf("Invalid HW-addr family 0x%04x\n",
ifr.ifr_hwaddr.sa_family);
return -1;
}
memcpy(drv->hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
return 0;
}
开发者ID:gittestusername,项目名称:uClinux,代码行数:57,代码来源:receive.c
注:本文中的eloop_register_read_sock函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论