Actions
Bug #678
closedSocket.getservbyport should convert the port param to network byte order
Bug #678:
Socket.getservbyport should convert the port param to network byte order
Description
=begin
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));
}
=end
Actions