@
geelaw 我看书 301 页对于 connect 的设置超时代码,能不能换成 gethostbyaddr
```c
static void getnameinfo_alarm(int signo) {
return;
}
int getnameinfo_timeo(const struct sockaddr *sockaddr, socklen_t addrlen,
char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flag, int timeout){
Sigfunc *sigfunc;
sigfunc = Signal(SIGALRM, getnameinfo_alarm);
if (alarm(timeout) != 0) {
err_msg("alarm is aready set!");
}
int ret;
if ((ret = getnameinfo(sockaddr, addrlen, host, hostlen, serv, servlen, flag)) != 0) {
printf("getnameinfo error:%s", gai_strerror(ret));
}
alarm(0);
Signal(SIGALRM, sigfunc);
return ret;
}
```