From: matz@... (Yukihiro Matsumoto) Date: 2002-03-28T17:24:09+09:00 Subject: [ruby-dev:16639] Re: socket.c/sock_addrinfo() まつもと ゆきひろです In message "[ruby-dev:16638] Re: socket.c/sock_addrinfo()" on 02/03/28, WATANABE Tetsuya writes: ||むう、これを指定しないと動かないケースがあるので指定したので ||すが、あちらを立てればこちらが立たず。わかりました、 ||SOCK_STREAMかSOCK_DGRAMを外部から指定するようにしましょう。 | |になると思います。 | |tcp か udp の指定は必要になりま |すので... | |対応お願いします。 こんな感じでどうでしょう? うちでは動いているみたいです。 --- socket.c 2002/03/26 06:18:51 1.70 +++ socket.c 2002/03/28 08:23:29 @@ -542,7 +542,7 @@ static struct addrinfo* -sock_addrinfo(host, port, flags) +sock_addrinfo(host, port, socktype, flags) VALUE host, port; - int flags; + int socktype, flags; { - struct addrinfo hints, *res; + struct addrinfo hints, *hintsp, *res; char *hostp, *portp; @@ -591,7 +591,13 @@ - MEMZERO(&hints, struct addrinfo, 1); - hints.ai_family = PF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = flags; - error = getaddrinfo(hostp, portp, &hints, &res); + if (socktype == 0 && flags == 0) { + hintsp = 0; + } + else { + hintsp = &hints; + hints.ai_family = PF_UNSPEC; + hints.ai_protocol = 0; + hints.ai_socktype = socktype; + hints.ai_flags = flags; + } + error = getaddrinfo(hostp, portp, hintsp, &res); if (error) { @@ -611,3 +617,3 @@ { - struct addrinfo *res = sock_addrinfo(name, Qnil, 0); + struct addrinfo *res = sock_addrinfo(name, Qnil, SOCK_STREAM, 0); @@ -844,3 +850,3 @@ - res_remote = sock_addrinfo(remote_host, remote_serv, + res_remote = sock_addrinfo(remote_host, remote_serv, SOCK_STREAM, (type == INET_SERVER) ? AI_PASSIVE : 0); @@ -851,3 +857,3 @@ if (type != INET_SERVER && (!NIL_P(local_host) || !NIL_P(local_serv))) { - res_local = sock_addrinfo(local_host, local_serv, + res_local = sock_addrinfo(local_host, local_serv, SOCK_STREAM, (type == INET_SERVER) ? AI_PASSIVE : 0); @@ -1272,3 +1278,3 @@ fd = fileno(fptr->f); - res0 = sock_addrinfo(host, port, 0); + res0 = sock_addrinfo(host, port, SOCK_DGRAM, 0); for (res = res0; res; res = res->ai_next) { @@ -1294,3 +1300,3 @@ GetOpenFile(sock, fptr); - res0 = sock_addrinfo(host, port, 0); + res0 = sock_addrinfo(host, port, SOCK_DGRAM, 0); for (res = res0; res; res = res->ai_next) { @@ -1326,3 +1332,3 @@ GetOpenFile(sock, fptr); - res0 = sock_addrinfo(host, port, 0); + res0 = sock_addrinfo(host, port, SOCK_DGRAM, 0); f = GetWriteFile(fptr); @@ -2197,3 +2203,3 @@ { - struct addrinfo *res = sock_addrinfo(host, port, 0); + struct addrinfo *res = sock_addrinfo(host, port, 0, 0); VALUE addr = rb_str_new((char*)res->ai_addr, res->ai_addrlen);