summaryrefslogtreecommitdiff
path: root/src/libsystemd-network/ipv4ll-network.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-05-06 22:02:32 +0200
committerTom Gundersen <teg@jklm.no>2014-05-06 22:15:46 +0200
commitc3d2994b595542caa971a06ea894019d16b95896 (patch)
tree84a760d36eba55aa390414c0e7aa1d687d22df70 /src/libsystemd-network/ipv4ll-network.c
parent85923f79e1d1191673c5dffa4bdf1f5aadaa415b (diff)
sd-dhcp: network - don't leak sockets on failure
Also some general cleanups
Diffstat (limited to 'src/libsystemd-network/ipv4ll-network.c')
-rw-r--r--src/libsystemd-network/ipv4ll-network.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/libsystemd-network/ipv4ll-network.c b/src/libsystemd-network/ipv4ll-network.c
index b917fbf3ac..0852f42c3a 100644
--- a/src/libsystemd-network/ipv4ll-network.c
+++ b/src/libsystemd-network/ipv4ll-network.c
@@ -24,11 +24,14 @@
int arp_network_send_raw_socket(int fd, const union sockaddr_union *link,
const struct ether_arp *arp) {
+ int r;
+
assert(arp);
assert(link);
assert(fd >= 0);
- if (sendto(fd, arp, sizeof(struct ether_arp), 0, &link->sa, sizeof(link->ll)) < 0)
+ r = sendto(fd, arp, sizeof(struct ether_arp), 0, &link->sa, sizeof(link->ll));
+ if (r < 0)
return -errno;
return 0;
@@ -56,7 +59,8 @@ int arp_network_bind_raw_socket(int index, union sockaddr_union *link) {
.len = ELEMENTSOF(filter),
.filter = filter
};
- int s;
+ _cleanup_close_ int s = -1;
+ int r;
assert(index > 0);
assert(link);
@@ -65,9 +69,9 @@ int arp_network_bind_raw_socket(int index, union sockaddr_union *link) {
if (s < 0)
return -errno;
- if (setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, &fprog, sizeof(fprog)) < 0) {
+ r = setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, &fprog, sizeof(fprog));
+ if (r < 0)
return -errno;
- }
link->ll.sll_family = AF_PACKET;
link->ll.sll_protocol = htons(ETH_P_ARP);
@@ -75,10 +79,12 @@ int arp_network_bind_raw_socket(int index, union sockaddr_union *link) {
link->ll.sll_halen = ETH_ALEN;
memset(link->ll.sll_addr, 0xff, ETH_ALEN);
- if (bind(s, &link->sa, sizeof(link->ll)) < 0) {
- safe_close(s);
+ r = bind(s, &link->sa, sizeof(link->ll));
+ if (r < 0)
return -errno;
- }
- return s;
+ r = s;
+ s = -1;
+
+ return r;
}