Repository : ssh://git@open-mesh.org/alfred
On branch : master
commit fcd4b0a71b265b2e3dfea88f495c6f9279344add Author: Sven Eckelmann sven@open-mesh.com Date: Thu Apr 17 13:19:30 2014 +0200
alfred: Handle EPERM on every sendto
The announcements are currently only sent by alfred instances in master mode. Slave instances don't announce themself and thus don't detect the broken socket. To also catch such problems, it is useful to handle the detection of EPERM during the send in send_alfred_packet which is always called when a link-local UDP packet is send over the network.
Signed-off-by: Sven Eckelmann sven@open-mesh.com Signed-off-by: Simon Wunderlich sw@simonwunderlich.de
fcd4b0a71b265b2e3dfea88f495c6f9279344add send.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/send.c b/send.c index 89e9c07..dc0e428 100644 --- a/send.c +++ b/send.c @@ -32,7 +32,6 @@
int announce_master(struct globals *globals) { - ssize_t ret; struct alfred_announce_master_v0 announcement;
if (globals->netsock < 0) @@ -42,14 +41,8 @@ int announce_master(struct globals *globals) announcement.header.version = ALFRED_VERSION; announcement.header.length = htons(0);
- ret = send_alfred_packet(globals, &in6addr_localmcast, &announcement, - sizeof(announcement)); - if (ret == -EPERM) { - fprintf(stderr, "Error during announcement\n"); - netsock_close(globals->netsock); - globals->netsock = -1; - } - + send_alfred_packet(globals, &in6addr_localmcast, &announcement, + sizeof(announcement));
return 0; } @@ -176,6 +169,11 @@ ssize_t send_alfred_packet(struct globals *globals, const struct in6_addr *dest, ret = sendto(globals->netsock, buf, length, 0, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr_in6)); + if (ret == -EPERM) { + fprintf(stderr, "Error during sent\n"); + netsock_close(globals->netsock); + globals->netsock = -1; + }
return ret; }