| 63 | } |
| 64 | |
| 65 | static int bind_addr(struct addrinfo *res0, struct addrinfo **res) |
| 66 | { |
| 67 | struct addrinfo *it; |
| 68 | int on, fd; |
| 69 | |
| 70 | for (it = res0; it != NULL ; it = it->ai_next) { |
| 71 | fd = socket(it->ai_family, it->ai_socktype, it->ai_protocol); |
| 72 | if (fd == ACL_SOCKET_INVALID) { |
| 73 | acl_msg_error("%s(%d): create socket %s", |
| 74 | __FILE__, __LINE__, acl_last_serror()); |
| 75 | return ACL_SOCKET_INVALID; |
| 76 | } |
| 77 | |
| 78 | on = 1; |
| 79 | if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, |
| 80 | (const void *) &on, sizeof(on)) < 0) |
| 81 | { |
| 82 | acl_msg_warn("%s(%d): setsockopt(SO_REUSEADDR): %s", |
| 83 | __FILE__, __LINE__, acl_last_serror()); |
| 84 | } |
| 85 | |
| 86 | #if defined(SO_REUSEPORT) |
| 87 | on = 1; |
| 88 | if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, |
| 89 | (const void *) &on, sizeof(on)) < 0) |
| 90 | { |
| 91 | acl_msg_warn("%s(%d): setsocket(SO_REUSEPORT): %s", |
| 92 | __FILE__, __LINE__, acl_last_serror()); |
| 93 | } |
| 94 | #endif |
| 95 | |
| 96 | #ifdef ACL_WINDOWS |
| 97 | if (bind(fd, it->ai_addr, (int) it->ai_addrlen) == 0) |
| 98 | #else |
| 99 | if (bind(fd, it->ai_addr, it->ai_addrlen) == 0) |
| 100 | #endif |
| 101 | { |
| 102 | *res = it; |
| 103 | return fd; |
| 104 | } |
| 105 | |
| 106 | acl_msg_error("%s(%d): bind error %s", |
| 107 | __FILE__, __LINE__, acl_last_serror()); |
| 108 | acl_socket_close(fd); |
| 109 | } |
| 110 | |
| 111 | return ACL_SOCKET_INVALID; |
| 112 | } |
| 113 | |
| 114 | static SOCK_UDP *sock_open(const char *addr) |
| 115 | { |
no test coverage detected
searching dependent graphs…