return errno == EAGAIN ? 0 : -1;
/* If it's an ARP reply, then just send it back */
- if (iface->socket_protocol == ETHERTYPE_ARP)
- return bytes;
-
- if (valid_udp_packet(iface->buffer) != 0)
- return -1;
-
- bytes = get_udp_data(&p, iface->buffer);
+ if (iface->socket_protocol == ETHERTYPE_ARP) {
+ p = iface->buffer;
+ } else {
+ if (valid_udp_packet(iface->buffer) != 0)
+ return -1;
+ bytes = get_udp_data(&p, iface->buffer);
+ }
if (bytes > len)
bytes = len;
memcpy(data, p, bytes);
if (get_time(&stopat) != 0)
break;
stopat.tv_usec += timeout;
-
continue;
}
if (!(fds[1].revents & POLLIN))
continue;
-
for(;;) {
memset(&arp_reply, 0, sizeof(arp_reply));
- bytes = get_packet(iface, &arp_reply, sizeof(arp_reply));
+ bytes = get_packet(iface,
+ &arp_reply, sizeof(arp_reply));
if (bytes == -1 || bytes == 0)
break;
- memcpy(&reply, arp_reply, sizeof(reply));
+ memcpy(&reply, &arp_reply, sizeof(reply));
/* Only these types are recognised */
if (reply.ar_op != htons(ARPOP_REPLY))
continue;
-
/* Protocol must be IP. */
if (reply.ar_pro != htons(ETHERTYPE_IP))
continue;
if (reply.ar_pln != sizeof(reply_ipv4))
continue;
- if ((size_t)bytes < sizeof(reply) + 2 * (4 + reply.ar_hln) ||
+ if ((size_t)bytes < sizeof(reply) + 2 *
+ (4 + reply.ar_hln) ||
reply.ar_hln > 8)
continue;
- memcpy(&reply_mac, arp_reply + sizeof(reply), reply.ar_hln);
- memcpy(&reply_ipv4, arp_reply + sizeof(reply) + reply.ar_hln, reply.ar_hln);
+ memcpy(&reply_mac,
+ arp_reply + sizeof(reply), reply.ar_hln);
+ memcpy(&reply_ipv4,
+ arp_reply + sizeof(reply) + reply.ar_hln,
+ reply.ar_hln);
/* Ensure the ARP reply is for the our address */
if (reply_ipv4.s_addr != address.s_addr)
/* Some systems send a reply back from our hwaddress,
* which is wierd */
if (reply.ar_hln == iface->hwlen &&
- memcmp(&reply_mac, iface->hwaddr, iface->hwlen) == 0)
+ memcmp(&reply_mac, iface->hwaddr,
+ iface->hwlen) == 0)
continue;
logger(LOG_ERR, "ARPOP_REPLY received from %s (%s)",
inet_ntoa(reply_ipv4),
- hwaddr_ntoa((unsigned char *)&reply_mac, (size_t)reply.ar_hln));
+ hwaddr_ntoa((unsigned char *)&reply_mac,
+ (size_t)reply.ar_hln));
retval = -1;
goto eexit;
}