]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
l2_packet: Use wpa_printf() instead of perror()
authorJouni Malinen <jouni.malinen@atheros.com>
Wed, 24 Nov 2010 13:00:22 +0000 (15:00 +0200)
committerJouni Malinen <j@w1.fi>
Wed, 24 Nov 2010 13:00:22 +0000 (15:00 +0200)
src/l2_packet/l2_packet_linux.c

index 48d1bde024e240fab2c77f07c5f84be4c703171e..93e15eb7c5b01ddabc4a7166c9fa58072a9c9e2c 100644 (file)
@@ -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;
        }