Socket.getaddrinfo handles special hosts '<any>' and '<broadcast>' #2115

Merged
merged 2 commits into from Jan 6, 2013
View
@@ -271,8 +271,10 @@ def self.getaddrinfo(host, service = nil, family = 0, socktype = 0, protocol =
hints[:ai_protocol] = protocol
hints[:ai_flags] = flags
- if host && host.empty?
+ if host && (host.empty? || host == '<any>')
host = "0.0.0.0"
+ elsif host == '<broadcast>'
+ host = '255.255.255.255'
end
res_p = FFI::MemoryPointer.new :pointer
View
@@ -357,8 +357,10 @@ def self.getaddrinfo(host, service = nil, family = 0, socktype = 0, protocol =
hints[:ai_protocol] = protocol
hints[:ai_flags] = flags
- if host && host.empty?
+ if host && (host.empty? || host == '<any>')
host = "0.0.0.0"
+ elsif host == '<broadcast>'
+ host = '255.255.255.255'
end
res_p = FFI::MemoryPointer.new :pointer
View
@@ -357,8 +357,10 @@ def self.getaddrinfo(host, service = nil, family = 0, socktype = 0, protocol =
hints[:ai_protocol] = protocol
hints[:ai_flags] = flags
- if host && host.empty?
+ if host && (host.empty? || host == '<any>')
host = "0.0.0.0"
+ elsif host == '<broadcast>'
+ host = '255.255.255.255'
end
res_p = FFI::MemoryPointer.new :pointer
@@ -5,12 +5,12 @@
describe "Socket#gethostbyname" do
it "returns broadcast address info for '<broadcast>'" do
- addr = Socket.gethostbyname('<broadcast>');
- addr.should == ["255.255.255.255", [], 2, "\377\377\377\377"]
+ addr = Socket.gethostbyname('<broadcast>').first;
+ addr.should == "255.255.255.255"
end
it "returns broadcast address info for '<any>'" do
- addr = Socket.gethostbyname('<any>');
- addr.should == ["0.0.0.0", [], 2, "\000\000\000\000"]
+ addr = Socket.gethostbyname('<any>').first;
+ addr.should == "0.0.0.0"
end
end
@@ -1,2 +0,0 @@
-fails:Socket#gethostbyname returns broadcast address info for '<broadcast>'
-fails:Socket#gethostbyname returns broadcast address info for '<any>'
@@ -1,2 +0,0 @@
-fails:Socket#gethostbyname returns broadcast address info for '<broadcast>'
-fails:Socket#gethostbyname returns broadcast address info for '<any>'