From e71576ba5294f019c19b623472677c2600883363 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Sun, 15 May 2011 21:33:32 +0200 Subject: [PATCH] Make the sender able to receive a response to the multicast query --- sender.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/sender.c b/sender.c index 8ca2927..1d54519 100644 --- a/sender.c +++ b/sender.c @@ -14,7 +14,7 @@ int main(int argc, char **argv) { int err; int sock6; - int idx = if_nametoindex("wlan0"); + int idx = if_nametoindex("br0"); struct addrinfo hints, *ai, *pai; uint8_t data[] = { 0x17, 0x2a, /* id */ @@ -51,30 +51,22 @@ int main(int argc, char **argv) err = setsockopt(sock6, IPPROTO_IPV6, IPV6_MULTICAST_IF, &idx, sizeof(idx)); if (err != 0) { - perror("setting default multicast interface"); + close(sock6); + continue; } - if (connect(sock6, pai->ai_addr, pai->ai_addrlen) != -1) { - /* success, end loop */ - break; + if (sendto(sock6, data, sizeof(data), 0, + pai->ai_addr, pai->ai_addrlen) == sizeof(data)) { + break; /* success, break out of loop */ } + perror("writing data"); close(sock6); } - if (pai == NULL) { - fprintf(stderr, "Could not connect to %s\n", "ff02::1:3"); - exit(1); - } - freeaddrinfo(ai); - if (write(sock6, data, sizeof(data)) != sizeof(data)) { - perror("writing data"); - exit(1); - } - - nread = read(sock6, reply, 1024); + nread = recvfrom(sock6, reply, 1024, 0, NULL, NULL); if (nread == -1) { perror("reading reply"); exit(1); -- 2.34.1