| 308 | } |
| 309 | |
| 310 | const char * tcp_bind(p_socket sock, const char *host, unsigned short port) { |
| 311 | // TODO support IPv6 |
| 312 | int err; |
| 313 | struct hostent *h; |
| 314 | struct sockaddr_in local; |
| 315 | memset(&local, 0, sizeof(local)); |
| 316 | local.sin_family = AF_INET; |
| 317 | local.sin_addr.s_addr = htonl(INADDR_ANY); |
| 318 | local.sin_port = htons(port); |
| 319 | if (strcmp(host, "*") && !inet_aton(host, &local.sin_addr)) { |
| 320 | h = gethostbyname(host); |
| 321 | if (!h) { |
| 322 | return hstrerror(h_errno); |
| 323 | } |
| 324 | memcpy(&local.sin_addr, |
| 325 | (struct in_addr *)h->h_addr_list[0], |
| 326 | sizeof(struct in_addr)); |
| 327 | } |
| 328 | err = socket_bind(sock, (p_sa) &local, sizeof(local)); |
| 329 | ERRORSTR_RETURN(err); |
| 330 | } |
| 331 | |
| 332 | const char * tcp_listen(p_socket sock, int backlog) { |
| 333 | int err = socket_listen(sock, backlog); |
no test coverage detected