l2_packet: Use wpa_printf() instead of perror()
This commit is contained in:
parent
ebbec8b2fa
commit
719007f5c0
1 changed files with 20 additions and 10 deletions
|
@ -51,7 +51,8 @@ int l2_packet_send(struct l2_packet_data *l2, const u8 *dst_addr, u16 proto,
|
|||
if (l2->l2_hdr) {
|
||||
ret = send(l2->fd, buf, len, 0);
|
||||
if (ret < 0)
|
||||
perror("l2_packet_send - send");
|
||||
wpa_printf(MSG_ERROR, "l2_packet_send - send: %s",
|
||||
strerror(errno));
|
||||
} else {
|
||||
struct sockaddr_ll ll;
|
||||
os_memset(&ll, 0, sizeof(ll));
|
||||
|
@ -62,8 +63,10 @@ int l2_packet_send(struct l2_packet_data *l2, const u8 *dst_addr, u16 proto,
|
|||
os_memcpy(ll.sll_addr, dst_addr, ETH_ALEN);
|
||||
ret = sendto(l2->fd, buf, len, 0, (struct sockaddr *) &ll,
|
||||
sizeof(ll));
|
||||
if (ret < 0)
|
||||
perror("l2_packet_send - sendto");
|
||||
if (ret < 0) {
|
||||
wpa_printf(MSG_ERROR, "l2_packet_send - sendto: %s",
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -82,7 +85,8 @@ static void l2_packet_receive(int sock, void *eloop_ctx, void *sock_ctx)
|
|||
res = recvfrom(sock, buf, sizeof(buf), 0, (struct sockaddr *) &ll,
|
||||
&fromlen);
|
||||
if (res < 0) {
|
||||
perror("l2_packet_receive - recvfrom");
|
||||
wpa_printf(MSG_DEBUG, "l2_packet_receive - recvfrom: %s",
|
||||
strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -111,14 +115,16 @@ struct l2_packet_data * l2_packet_init(
|
|||
l2->fd = socket(PF_PACKET, l2_hdr ? SOCK_RAW : SOCK_DGRAM,
|
||||
htons(protocol));
|
||||
if (l2->fd < 0) {
|
||||
perror("socket(PF_PACKET)");
|
||||
wpa_printf(MSG_ERROR, "%s: socket(PF_PACKET): %s",
|
||||
__func__, strerror(errno));
|
||||
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]");
|
||||
wpa_printf(MSG_ERROR, "%s: ioctl[SIOCGIFINDEX]: %s",
|
||||
__func__, strerror(errno));
|
||||
close(l2->fd);
|
||||
os_free(l2);
|
||||
return NULL;
|
||||
|
@ -130,14 +136,16 @@ struct l2_packet_data * l2_packet_init(
|
|||
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]");
|
||||
wpa_printf(MSG_ERROR, "%s: bind[PF_PACKET]: %s",
|
||||
__func__, strerror(errno));
|
||||
close(l2->fd);
|
||||
os_free(l2);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ioctl(l2->fd, SIOCGIFHWADDR, &ifr) < 0) {
|
||||
perror("ioctl[SIOCGIFHWADDR]");
|
||||
wpa_printf(MSG_ERROR, "%s: ioctl[SIOCGIFHWADDR]: %s",
|
||||
__func__, strerror(errno));
|
||||
close(l2->fd);
|
||||
os_free(l2);
|
||||
return NULL;
|
||||
|
@ -173,14 +181,16 @@ int l2_packet_get_ip_addr(struct l2_packet_data *l2, char *buf, size_t len)
|
|||
|
||||
s = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
perror("socket");
|
||||
wpa_printf(MSG_ERROR, "%s: socket: %s",
|
||||
__func__, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
os_memset(&ifr, 0, sizeof(ifr));
|
||||
os_strlcpy(ifr.ifr_name, l2->ifname, sizeof(ifr.ifr_name));
|
||||
if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
|
||||
if (errno != EADDRNOTAVAIL)
|
||||
perror("ioctl[SIOCGIFADDR]");
|
||||
wpa_printf(MSG_ERROR, "%s: ioctl[SIOCGIFADDR]: %s",
|
||||
__func__, strerror(errno));
|
||||
close(s);
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue