2018-08-03 12:19:40 -04:00
|
|
|
require_relative '../spec_helper'
|
2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../fixtures/classes'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
describe "Socket::BasicSocket#getsockname" do
|
|
|
|
after :each do
|
|
|
|
@socket.closed?.should be_false
|
|
|
|
@socket.close
|
|
|
|
end
|
|
|
|
|
2019-02-07 11:35:33 -05:00
|
|
|
it "returns the sockaddr associated with the socket" do
|
2017-06-15 08:48:52 -04:00
|
|
|
@socket = TCPServer.new("127.0.0.1", 0)
|
2017-05-07 08:04:49 -04:00
|
|
|
sockaddr = Socket.unpack_sockaddr_in(@socket.getsockname)
|
2017-06-15 08:48:52 -04:00
|
|
|
sockaddr.should == [@socket.addr[1], "127.0.0.1"]
|
2017-06-29 10:35:37 -04:00
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
it "works on sockets listening in ipaddr_any" do
|
2017-06-15 08:48:52 -04:00
|
|
|
@socket = TCPServer.new(0)
|
2017-05-07 08:04:49 -04:00
|
|
|
sockaddr = Socket.unpack_sockaddr_in(@socket.getsockname)
|
|
|
|
["::", "0.0.0.0", "::ffff:0.0.0.0"].include?(sockaddr[1]).should be_true
|
2017-06-15 08:48:52 -04:00
|
|
|
sockaddr[0].should == @socket.addr[1]
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
2018-08-03 12:19:40 -04:00
|
|
|
it 'returns a default socket address for a disconnected socket' do
|
2017-05-07 08:04:49 -04:00
|
|
|
@socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
|
|
|
|
sockaddr = Socket.unpack_sockaddr_in(@socket.getsockname)
|
|
|
|
sockaddr.should == [0, "0.0.0.0"]
|
|
|
|
end
|
|
|
|
end
|