| 60 | } |
| 61 | |
| 62 | int SetAddr(const char * ip_string, const unsigned short port, struct sockaddr_in & addr) { |
| 63 | bzero(&addr, sizeof(addr)); |
| 64 | addr.sin_family = AF_INET; |
| 65 | addr.sin_port = htons(port); |
| 66 | if (!ip_string || '\0' == *ip_string || 0 == strcmp(ip_string, "0") || 0 == strcmp(ip_string, "0.0.0.0") |
| 67 | || 0 == strcmp(ip_string, "*")) { |
| 68 | addr.sin_addr.s_addr = htonl(INADDR_ANY); |
| 69 | } else { |
| 70 | int ret = inet_pton(AF_INET, ip_string, &addr.sin_addr); |
| 71 | if (ret <= 0) { |
| 72 | LogError("inet_pton failed, ip [%s], ret %d, errno(%d:%s)", ip_string, ret, errno, strerror(errno)); |
| 73 | return -1; |
| 74 | } |
| 75 | } |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | int SetAddr6(const char * ip_string, const unsigned short port, struct sockaddr_in6 & addr) { |
| 80 | bzero(&addr, sizeof(addr)); |
no test coverage detected