diff options
Diffstat (limited to 'networking/udhcp/d6_socket.c')
-rw-r--r-- | networking/udhcp/d6_socket.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/networking/udhcp/d6_socket.c b/networking/udhcp/d6_socket.c new file mode 100644 index 000000000..56f69f6a1 --- /dev/null +++ b/networking/udhcp/d6_socket.c | |||
@@ -0,0 +1,34 @@ | |||
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 | |||
16 | log1("Opening listen socket on *:%d %s", port, inf); | ||
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 | } | ||