| 340 | } |
| 341 | |
| 342 | const char * tcp_connect(p_socket sock, |
| 343 | const char *host, |
| 344 | unsigned short port, |
| 345 | int timeout) { |
| 346 | // TODO support IPv6 |
| 347 | int err; |
| 348 | struct hostent *h; |
| 349 | struct sockaddr_in remote; |
| 350 | memset(&remote, 0, sizeof(remote)); |
| 351 | remote.sin_family = AF_INET; |
| 352 | remote.sin_port = htons(port); |
| 353 | if (strcmp(host, "*") && !inet_aton(host, &remote.sin_addr)) { |
| 354 | h = gethostbyname(host); |
| 355 | if (!h) { |
| 356 | return hstrerror(h_errno); |
| 357 | } |
| 358 | memcpy(&remote.sin_addr, |
| 359 | (struct in_addr *)h->h_addr_list[0], |
| 360 | sizeof(struct in_addr)); |
| 361 | } |
| 362 | err = socket_connect(sock, (p_sa) &remote, sizeof(remote), timeout); |
| 363 | ERRORSTR_RETURN(err); |
| 364 | } |
| 365 | |
| 366 | const char * tcp_create_and_connect(p_socket sock, |
| 367 | const char *host, |
no test coverage detected