if (state->new == NULL)
return;
if (state->arp_fd == -1) {
- ipv4_opensocket(ifp, ETHERTYPE_ARP);
+ state->arp_fd = ipv4_opensocket(ifp, ETHERTYPE_ARP);
+ if (state->arp_fd == -1) {
+ syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
+ return;
+ }
eloop_event_add(state->arp_fd, arp_packet, ifp);
}
if (++state->claims < ANNOUNCE_NUM)
int arping = 0;
if (state->arp_fd == -1) {
- if (ipv4_opensocket(ifp, ETHERTYPE_ARP) == -1)
+ state->arp_fd = ipv4_opensocket(ifp, ETHERTYPE_ARP);
+ if (state->arp_fd == -1) {
+ syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
return;
+ }
eloop_event_add(state->arp_fd, arp_packet, ifp);
}
{
struct dhcp_state *state;
int fd = -1;
- int *fdp = NULL;
struct ifreq ifr;
int buf_len = 0;
struct bpf_version pv;
if (protocol == ETHERTYPE_ARP) {
pf.bf_insns = UNCONST(arp_bpf_filter);
pf.bf_len = arp_bpf_filter_len;
- fdp = &state->arp_fd;
} else {
pf.bf_insns = UNCONST(dhcp_bpf_filter);
pf.bf_len = dhcp_bpf_filter_len;
- fdp = &state->raw_fd;
}
if (ioctl(fd, BIOCSETF, &pf) == -1)
goto eexit;
if (set_cloexec(fd) == -1)
goto eexit;
- if (fdp) {
- if (*fdp != -1)
- close(*fdp);
- *fdp = fd;
- }
return fd;
eexit:
static int
dhcp_open(struct interface *ifp)
{
- int r = 0;
struct dhcp_state *state;
state = D_STATE(ifp);
if (state->raw_fd == -1) {
- if ((r = ipv4_opensocket(ifp, ETHERTYPE_IP)) == -1) {
+ state->raw_fd = ipv4_opensocket(ifp, ETHERTYPE_IP);
+ if (state->raw_fd == -1) {
syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
return -1;
}
struct sockaddr_storage ss;
} su;
struct sock_fprog pf;
- int *fd;
- struct dhcp_state *state;
#ifdef PACKET_AUXDATA
int n;
#endif
goto eexit;
if (bind(s, &su.sa, sizeof(su)) == -1)
goto eexit;
- state = D_STATE(ifp);
- if (protocol == ETHERTYPE_ARP)
- fd = &state->arp_fd;
- else
- fd = &state->raw_fd;
- if (*fd != -1)
- close(*fd);
- *fd = s;
return s;
eexit: