Lines Matching refs:l2
38 int l2_packet_get_own_addr(struct l2_packet_data *l2, u8 *addr)
40 os_memcpy(addr, l2->own_addr, ETH_ALEN);
45 int l2_packet_send(struct l2_packet_data *l2, const u8 *dst_addr, u16 proto,
49 if (l2 == NULL)
51 if (l2->l2_hdr) {
52 ret = send(l2->fd, buf, len, 0);
59 ll.sll_ifindex = l2->ifindex;
63 ret = sendto(l2->fd, buf, len, 0, (struct sockaddr *) &ll,
74 struct l2_packet_data *l2 = eloop_ctx;
89 l2->rx_callback(l2->rx_callback_ctx, ll.sll_addr, buf, res);
99 struct l2_packet_data *l2;
103 l2 = os_zalloc(sizeof(struct l2_packet_data));
104 if (l2 == NULL)
106 os_strncpy(l2->ifname, ifname, sizeof(l2->ifname));
107 l2->rx_callback = rx_callback;
108 l2->rx_callback_ctx = rx_callback_ctx;
109 l2->l2_hdr = l2_hdr;
111 l2->fd = socket(PF_PACKET, l2_hdr ? SOCK_RAW : SOCK_DGRAM,
113 if (l2->fd < 0) {
115 os_free(l2);
118 os_strncpy(ifr.ifr_name, l2->ifname, sizeof(ifr.ifr_name));
119 if (ioctl(l2->fd, SIOCGIFINDEX, &ifr) < 0) {
121 close(l2->fd);
122 os_free(l2);
125 l2->ifindex = ifr.ifr_ifindex;
131 if (bind(l2->fd, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
133 close(l2->fd);
134 os_free(l2);
138 if (ioctl(l2->fd, SIOCGIFHWADDR, &ifr) < 0) {
140 close(l2->fd);
141 os_free(l2);
144 os_memcpy(l2->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
146 eloop_register_read_sock(l2->fd, l2_packet_receive, l2, NULL);
148 return l2;
152 void l2_packet_deinit(struct l2_packet_data *l2)
154 if (l2 == NULL)
157 if (l2->fd >= 0) {
158 eloop_unregister_read_sock(l2->fd);
159 close(l2->fd);
162 os_free(l2);
166 int l2_packet_get_ip_addr(struct l2_packet_data *l2, char *buf, size_t len)
178 os_strncpy(ifr.ifr_name, l2->ifname, sizeof(ifr.ifr_name));
194 void l2_packet_notify_auth_start(struct l2_packet_data *l2)