Rename inarp_ctx.socket
We want to introduce another socket descriptor, so give this one a more
specific name.
No functional change to code.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
diff --git a/inarp.c b/inarp.c
index 212b10f..cfb4012 100644
--- a/inarp.c
+++ b/inarp.c
@@ -53,7 +53,7 @@
};
struct inarp_ctx {
- int socket;
+ int arp_sd;
struct interface *interfaces;
unsigned int n_interfaces;
};
@@ -194,7 +194,7 @@
for (;;) {
ifconf.ifc_len = 0;
ifconf.ifc_buf = NULL;
- rc = ioctl(inarp->socket, SIOCGIFCONF, &ifconf);
+ rc = ioctl(inarp->arp_sd, SIOCGIFCONF, &ifconf);
if (rc < 0) {
warn("Error querying interface configuration size");
return -1;
@@ -209,7 +209,7 @@
ifconf.ifc_len = alloc_len;
ifconf.ifc_buf = malloc(alloc_len);
- rc = ioctl(inarp->socket, SIOCGIFCONF, &ifconf);
+ rc = ioctl(inarp->arp_sd, SIOCGIFCONF, &ifconf);
if (rc < 0) {
warn("Error quering interface configuration");
free(ifconf.ifc_buf);
@@ -237,11 +237,11 @@
strncpy(iface.ifname, ifreq->ifr_name, IFNAMSIZ);
- rc = get_ifindex(inarp->socket, iface.ifname, &iface.ifindex);
+ rc = get_ifindex(inarp->arp_sd, iface.ifname, &iface.ifindex);
if (rc)
continue;
- rc = get_local_hwaddr(inarp->socket, iface.ifname,
+ rc = get_local_hwaddr(inarp->arp_sd, iface.ifname,
&iface.eth_addr);
if (rc)
continue;
@@ -300,8 +300,8 @@
memset(&inarp, 0, sizeof(inarp));
- inarp.socket = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ARP));
- if (inarp.socket < 0)
+ inarp.arp_sd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ARP));
+ if (inarp.arp_sd < 0)
err(EXIT_FAILURE, "Error opening ARP socket");
ret = init_interfaces(&inarp);
@@ -310,7 +310,8 @@
while (1) {
addrlen = sizeof(addr);
- len = recvfrom(inarp.socket, &inarp_req, sizeof(inarp_req), 0,
+ len = recvfrom(inarp.arp_sd, &inarp_req,
+ sizeof(inarp_req), 0,
(struct sockaddr *)&addr, &addrlen);
if (len <= 0) {
if (errno == EINTR)
@@ -347,7 +348,8 @@
printf("src mac: %s\n", eth_mac_to_str(&inarp_req.src_mac));
printf("src ip: %s\n", inet_ntoa(inarp_req.src_ip));
- ret = get_local_ipaddr(inarp.socket, iface->ifname, &local_ip);
+ ret = get_local_ipaddr(inarp.arp_sd, iface->ifname,
+ &local_ip);
/* if we don't have a local IP address to send, just drop the
* request */
if (ret)
@@ -356,12 +358,12 @@
printf("local mac: %s\n", eth_mac_to_str(&iface->eth_addr));
printf("local ip: %s\n", inet_ntoa(local_ip));
- send_arp_packet(inarp.socket, iface->ifindex,
+ send_arp_packet(inarp.arp_sd, iface->ifindex,
&inarp_req.dest_mac,
&local_ip,
&inarp_req.src_mac,
&inarp_req.src_ip);
}
- close(inarp.socket);
+ close(inarp.arp_sd);
return 0;
}