Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #2115 from sdaubert/socket.getaddrinfo_any_broadcast

Socket.getaddrinfo handles special hosts '<any>' and '<broadcast>'
  • Loading branch information...
commit dcf1bd9afe2d101172b8ac46fdfec5aa0f0b4677 2 parents 92b8a90 + 03f305b
@dbussink dbussink authored
View
4 lib/18/socket.rb
@@ -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
4 lib/19/socket.rb
@@ -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
4 lib/20/socket.rb
@@ -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
8 spec/ruby/library/socket/socket/gethostbyname_spec.rb
@@ -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
View
2  spec/tags/18/ruby/library/socket/socket/gethostbyname_tags.txt
@@ -1,2 +0,0 @@
-fails:Socket#gethostbyname returns broadcast address info for '<broadcast>'
-fails:Socket#gethostbyname returns broadcast address info for '<any>'
View
2  spec/tags/19/ruby/library/socket/socket/gethostbyname_tags.txt
@@ -1,2 +0,0 @@
-fails:Socket#gethostbyname returns broadcast address info for '<broadcast>'
-fails:Socket#gethostbyname returns broadcast address info for '<any>'
Please sign in to comment.
Something went wrong with that request. Please try again.