#include "unp.h"
int
tcp_connect(const char *host, const char *serv)
{
int sockfd, n;
struct addrinfo hints, *res, *ressave;
bzero(&hints, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
if ( (n = getaddrinfo(host, serv, &hints, &res)) != 0)
err_quit("tcp_connect error for %s, %s: %s",
host, serv, gai_strerror(n));
}
比如 tcp_connect("192.168.1.1", daytime);
实际应返回3个地址, 1. loop
2.eth0
3.wlan0
但是每次都发现getaddrinfo只返回一个loop地址