Skip to content

Commit

Permalink
Fix: Addrinfo#ip_address
Browse files Browse the repository at this point in the history
  • Loading branch information
ysbaddaden authored and asterite committed Dec 27, 2016
1 parent cd51ef6 commit 48af685
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions spec/std/socket_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ describe Socket::Addrinfo do
end
end
end

describe "#ip_address" do
assert do
addrinfos = Socket::Addrinfo.udp("localhost", 80)
typeof(addrinfos.first.ip_address).should eq(Socket::IPAddress)
end
end
end

describe Socket::IPAddress do
Expand Down
4 changes: 3 additions & 1 deletion src/socket/addrinfo.cr
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,11 @@ class Socket
end
end

@ip_address : IPAddress?

# Returns an `IPAddress` matching this addrinfo.
def ip_address
@ip_address = IPAddress.from(@addr, @addrlen)
@ip_address ||= IPAddress.from(to_unsafe, size)
end

def to_unsafe
Expand Down

0 comments on commit 48af685

Please sign in to comment.