Denys Vlasenko | 9ba7504 | 2011-11-07 15:55:39 +0100 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * Copyright (C) 2011 Denys Vlasenko. |
| 4 | * |
| 5 | * Licensed under GPLv2, see file LICENSE in this source tree. |
| 6 | */ |
| 7 | #include "common.h" |
| 8 | #include "d6_common.h" |
| 9 | #include <net/if.h> |
| 10 | |
| 11 | int FAST_FUNC d6_listen_socket(int port, const char *inf) |
| 12 | { |
| 13 | int fd; |
| 14 | struct sockaddr_in6 addr; |
| 15 | |
Denys Vlasenko | 8f2e99c | 2016-03-30 18:41:23 +0200 | [diff] [blame] | 16 | log1("opening listen socket on *:%d %s", port, inf); |
Denys Vlasenko | 9ba7504 | 2011-11-07 15:55:39 +0100 | [diff] [blame] | 17 | fd = xsocket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP); |
| 18 | |
| 19 | setsockopt_reuseaddr(fd); |
| 20 | if (setsockopt_broadcast(fd) == -1) |
| 21 | bb_perror_msg_and_die("SO_BROADCAST"); |
| 22 | |
| 23 | /* NB: bug 1032 says this doesn't work on ethernet aliases (ethN:M) */ |
| 24 | if (setsockopt_bindtodevice(fd, inf)) |
| 25 | xfunc_die(); /* warning is already printed */ |
| 26 | |
| 27 | memset(&addr, 0, sizeof(addr)); |
| 28 | addr.sin6_family = AF_INET6; |
| 29 | addr.sin6_port = htons(port); |
| 30 | /* addr.sin6_addr is all-zeros */ |
| 31 | xbind(fd, (struct sockaddr *)&addr, sizeof(addr)); |
| 32 | |
| 33 | return fd; |
| 34 | } |