| 77 | } |
| 78 | |
| 79 | int SetAddr6(const char * ip_string, const unsigned short port, struct sockaddr_in6 & addr) { |
| 80 | bzero(&addr, sizeof(addr)); |
| 81 | addr.sin6_family = AF_INET6; |
| 82 | addr.sin6_port = htons(port); |
| 83 | if (!ip_string || '\0' == *ip_string || 0 == strcmp(ip_string, "0") || 0 == strcmp(ip_string, "::") |
| 84 | || 0 == strcmp(ip_string, "*")) { |
| 85 | addr.sin6_addr = in6addr_any; |
| 86 | } else { |
| 87 | int ret = inet_pton(AF_INET6, ip_string, &addr.sin6_addr); |
| 88 | if (ret <= 0) { |
| 89 | LogError("inet_pton failed, ip [%s], ret %d, errno(%d:%s)", ip_string, ret, errno, strerror(errno)); |
| 90 | return -1; |
| 91 | } |
| 92 | } |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | int CreateTcpSocket(const unsigned short port /* = 0 */, const char *ip /* = "*" */, bool is_reuse /* = false */) { |
| 97 | int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
no test coverage detected