Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 2 commits into from

2 participants

@sdaubert

As said on rubinius#2111, here is the new pull request to handle special hosts '' and '', without converting last item on returned array to a packed string.

This pull request also contains a commit to modify specs "Socket#gethostbyname returns broadcast address info for '<broadcast>'" and "Socket#gethostbyname returns broadcast address info for '<any>'" to only test the first item returned.

@dbussink
Owner

Ok, looks good! One thing though, could you improve the layout of the commit messages? For example sdaubert/rubinius@b24e1aa has a long first line that overflows and the line breaks in the lines further seem weird too. In general the recommendation is to use up to 72 char lines.

Usually how it looks on github can be a good guideline for the messages. For a multiple line commit message, also use a newline after the first line and multiple paragraphs for really long texts.

sdaubert added some commits
@sdaubert sdaubert Modify library/socket/socket/gethostbyname specs.
For specs "Socket#gethostbyname returns broadcast address info for
'<broadcast>'" and "Socket#gethostbyname returns broadcast address
info for '<any>'", only the first item (address) of returned array
is tested.

Later, some specs shall be added to verify that latest item of returned array contains
address as a packed string.
c319579
@sdaubert sdaubert Modify Socket::Foreign.getaddrinfo to handle special host strings.
Modify Socket::Foreign.getaddrinfo to handle special host strings
'<any>' and '<broadcast>'.

Modification made for 1.8, 1.9 and 2.0 versions.
03f305b
@sdaubert

OK, commit messages have been modified.

@dbussink dbussink merged commit dcf1bd9 into rubinius:master
@dbussink
Owner

Thnx!

@sdaubert sdaubert deleted the unknown repository branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 6, 2013
  1. @sdaubert

    Modify library/socket/socket/gethostbyname specs.

    sdaubert authored
    For specs "Socket#gethostbyname returns broadcast address info for
    '<broadcast>'" and "Socket#gethostbyname returns broadcast address
    info for '<any>'", only the first item (address) of returned array
    is tested.
    
    Later, some specs shall be added to verify that latest item of returned array contains
    address as a packed string.
  2. @sdaubert

    Modify Socket::Foreign.getaddrinfo to handle special host strings.

    sdaubert authored
    Modify Socket::Foreign.getaddrinfo to handle special host strings
    '<any>' and '<broadcast>'.
    
    Modification made for 1.8, 1.9 and 2.0 versions.
This page is out of date. Refresh to see the latest.
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>'
Something went wrong with that request. Please try again.