| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: mcast.c,v 1.1 2015/05/26 00:42:07 ozaki-r Exp $ */ | | 1 | /* $NetBSD: mcast.c,v 1.2 2015/05/28 08:32:53 ozaki-r Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2014 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2014 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Christos Zoulas. | | 8 | * by Christos Zoulas. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -20,27 +20,27 @@ | | | @@ -20,27 +20,27 @@ |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | #include <sys/cdefs.h> | | 31 | #include <sys/cdefs.h> |
32 | #ifdef __RCSID | | 32 | #ifdef __RCSID |
33 | __RCSID("$NetBSD: mcast.c,v 1.1 2015/05/26 00:42:07 ozaki-r Exp $"); | | 33 | __RCSID("$NetBSD: mcast.c,v 1.2 2015/05/28 08:32:53 ozaki-r Exp $"); |
34 | #else | | 34 | #else |
35 | extern const char *__progname; | | 35 | extern const char *__progname; |
36 | #define getprogname() __progname | | 36 | #define getprogname() __progname |
37 | #endif | | 37 | #endif |
38 | | | 38 | |
39 | #include <sys/types.h> | | 39 | #include <sys/types.h> |
40 | #include <sys/socket.h> | | 40 | #include <sys/socket.h> |
41 | #include <sys/wait.h> | | 41 | #include <sys/wait.h> |
42 | #include <sys/time.h> | | 42 | #include <sys/time.h> |
43 | #include <netinet/in.h> | | 43 | #include <netinet/in.h> |
44 | | | 44 | |
45 | #include <assert.h> | | 45 | #include <assert.h> |
46 | #include <netdb.h> | | 46 | #include <netdb.h> |
| @@ -276,27 +276,28 @@ receiver(const char *host, const char *p | | | @@ -276,27 +276,28 @@ receiver(const char *host, const char *p |
276 | s = getsocket(host, port, bind, &slen, bug); | | 276 | s = getsocket(host, port, bind, &slen, bug); |
277 | pfd.fd = s; | | 277 | pfd.fd = s; |
278 | pfd.events = POLLIN; | | 278 | pfd.events = POLLIN; |
279 | for (seq = 0; seq < n; seq++) { | | 279 | for (seq = 0; seq < n; seq++) { |
280 | if (poll(&pfd, 1, 10000) == -1) | | 280 | if (poll(&pfd, 1, 10000) == -1) |
281 | ERRX(EXIT_FAILURE, "poll (%s)", strerror(errno)); | | 281 | ERRX(EXIT_FAILURE, "poll (%s)", strerror(errno)); |
282 | l = conn ? recv(s, &msg, sizeof(msg), 0) : | | 282 | l = conn ? recv(s, &msg, sizeof(msg), 0) : |
283 | recvfrom(s, &msg, sizeof(msg), 0, (void *)&ss, &slen); | | 283 | recvfrom(s, &msg, sizeof(msg), 0, (void *)&ss, &slen); |
284 | if (l == -1) | | 284 | if (l == -1) |
285 | ERRX(EXIT_FAILURE, "recv (%s)", strerror(errno)); | | 285 | ERRX(EXIT_FAILURE, "recv (%s)", strerror(errno)); |
286 | if (debug) | | 286 | if (debug) |
287 | show("got", &msg); | | 287 | show("got", &msg); |
288 | if (seq != msg.seq) | | 288 | if (seq != msg.seq) |
289 | ERRX(EXIT_FAILURE, "seq %zu != %zu", seq, msg.seq); | | 289 | ERRX(EXIT_FAILURE, "seq: expect=%zu actual=%zu", |
| | | 290 | seq, msg.seq); |
290 | } | | 291 | } |
291 | } | | 292 | } |
292 | | | 293 | |
293 | static void | | 294 | static void |
294 | run(const char *host, const char *port, size_t n, bool conn, bool bug) | | 295 | run(const char *host, const char *port, size_t n, bool conn, bool bug) |
295 | { | | 296 | { |
296 | pid_t pid; | | 297 | pid_t pid; |
297 | int status; | | 298 | int status; |
298 | | | 299 | |
299 | switch ((pid = fork())) { | | 300 | switch ((pid = fork())) { |
300 | case 0: | | 301 | case 0: |
301 | receiver(host, port, n, conn, bug); | | 302 | receiver(host, port, n, conn, bug); |
302 | return; | | 303 | return; |