From: Dave Thomas Date: 2008-10-23T07:54:55+09:00 Subject: [ruby-core:19454] [Bug #678] Socket.getservbyport should convert the port param to network byte order Bug #678: Socket.getservbyport should convert the port param to network byte order http://redmine.ruby-lang.org/issues/show/678 Author: Dave Thomas Status: Open, Priority: Normal getservbyname returns the port number in native byte order (so "telnet" returns 23). But if you pass 23 back to getserverbyport, it fails, because it doesn't covert the param to network byte order before calling getservbyport(2). Here's a patch that fixes it: Index: ext/socket/socket.c =================================================================== --- ext/socket/socket.c (revision 19883) +++ ext/socket/socket.c (working copy) @@ -3254,7 +3254,7 @@ if (NIL_P(proto)) proto = rb_str_new2("tcp"); StringValue(proto); - sp = getservbyport(NUM2INT(port), StringValueCStr(proto)); + sp = getservbyport(htons(NUM2INT(port)), StringValueCStr(proto)); if (!sp) { rb_raise(rb_eSocket, "no such service for port %d/%s", NUM2INT(port), RSTRING_PTR(proto)); } ---------------------------------------- http://redmine.ruby-lang.org