Add getAddrString which returns string representing the address within SockAddr.
This commit is contained in:
parent
61336b2404
commit
48ff0d84d0
1 changed files with 12 additions and 0 deletions
|
|
@ -330,6 +330,18 @@ proc getSockDomain*(socket: SocketHandle): Domain =
|
||||||
raise newException(OSError, "unknown socket family in getSockFamily")
|
raise newException(OSError, "unknown socket family in getSockFamily")
|
||||||
|
|
||||||
|
|
||||||
|
proc getAddrString*(sockAddr: ptr SockAddr): string =
|
||||||
|
## return the string representation of address within sockAddr
|
||||||
|
if sockAddr.sa_family == posix.AF_INET:
|
||||||
|
result = $inet_ntoa(cast[ptr Sockaddr_in](sockAddr).sin_addr)
|
||||||
|
elif sockAddr.sa_family == posix.AF_INET6:
|
||||||
|
var v6addr = cast[ptr Sockaddr_in6](sockAddr).sin6_addr
|
||||||
|
result = newString(posix.INET6_ADDRSTRLEN)
|
||||||
|
discard posix.inet_ntop(posix.AF_INET6, addr cast[ptr Sockaddr_in6](sockAddr).sin6_addr, result.cstring, result.len.int32)
|
||||||
|
else:
|
||||||
|
raise newException(OSError, "unknown socket family in getAddrString")
|
||||||
|
|
||||||
|
|
||||||
proc getSockName*(socket: SocketHandle): Port =
|
proc getSockName*(socket: SocketHandle): Port =
|
||||||
## returns the socket's associated port number.
|
## returns the socket's associated port number.
|
||||||
var name: Sockaddr_in
|
var name: Sockaddr_in
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue