Skip to content

Commit b767514

Browse files
committed
dhcp4, dhcp6: Minor cleanups
The check to close existing fds is unnecessary since create_*socket() always gets a freshly calloc'ed value.
1 parent 221d239 commit b767514

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

dhcp4.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ static bool create_dhcp4_socket(struct D4Listener *self)
136136
struct sockaddr_in sai = {
137137
.sin_family = AF_INET,
138138
.sin_port = htons(67),
139-
.sin_addr.s_addr = 0, // any
140139
};
141-
if (self->fd_ > 0) close(self->fd_);
142140
self->fd_ = socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_UDP);
143141
if (self->fd_ < 0) {
144142
log_line("dhcp4: Failed to create v4 UDP socket on %s: %s\n", self->ifname_, strerror(errno));

dhcp6.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,10 @@ struct d6msg_state
248248
static bool create_dhcp6_socket(struct D6Listener *self)
249249
{
250250
struct in6_addr mc6_alldhcp_ras;
251-
struct sockaddr_in6 sai;
252-
if (self->fd_ > 0) close(self->fd_);
251+
struct sockaddr_in6 sai = {
252+
.sin6_family = AF_INET6,
253+
.sin6_port = htons(547),
254+
};
253255
self->fd_ = socket(AF_INET6, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_UDP);
254256
if (self->fd_ < 0) {
255257
log_line("dhcp6: Failed to create v6 UDP socket on %s: %s\n", self->ifname_, strerror(errno));
@@ -259,9 +261,6 @@ static bool create_dhcp6_socket(struct D6Listener *self)
259261
if (!attach_multicast_in6_addr(self->fd_, self->ifname_, &mc6_alldhcp_ras)) goto err1;
260262
self->using_bpf_ = attach_bpf_dhcp6_info(self->fd_, self->ifname_);
261263

262-
memset(&sai, 0, sizeof sai); // s6_addr is set to any here
263-
sai.sin6_family = AF_INET6;
264-
sai.sin6_port = htons(547);
265264
if (bind(self->fd_, (const struct sockaddr *)&sai, sizeof sai)) {
266265
log_line("dhcp6: Failed to bind to UDP 547 on %s: %s\n", self->ifname_, strerror(errno));
267266
goto err1;

multicast6.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Copyright 2016-2024 Nicholas J. Kain <njkain at gmail dot com>
2+
// SPDX-License-Identifier: MIT
13
#include "multicast6.h"
24
#include "nlsocket.h"
35
#include "nk/log.h"

0 commit comments

Comments
 (0)