Convert *_family fields to cushort

Fixes #9008
This commit is contained in:
LemonBoy 2018-09-19 09:24:30 +02:00
commit a27429304e
14 changed files with 61 additions and 71 deletions

View file

@ -223,7 +223,7 @@ template htons(x: uint16): uint16 =
sockets.ntohs(x)
when defined(Posix):
proc toInt(domain: Domain): TSa_Family =
proc toInt(domain: Domain): cint =
case domain
of AF_UNIX: result = posix.AF_UNIX
of AF_INET: result = posix.AF_INET
@ -463,9 +463,9 @@ proc bindAddr*(socket: Socket, port = Port(0), address = "") {.
if address == "":
var name: Sockaddr_in
when defined(Windows):
name.sin_family = int16(ord(AF_INET))
name.sin_family = uint16(ord(AF_INET))
else:
name.sin_family = posix.AF_INET
name.sin_family = uint16(posix.AF_INET)
name.sin_port = sockets.htons(uint16(port))
name.sin_addr.s_addr = sockets.htonl(INADDR_ANY)
if bindSocket(socket.fd, cast[ptr SockAddr](addr(name)),
@ -485,9 +485,9 @@ proc getSockName*(socket: Socket): Port =
## returns the socket's associated port number.
var name: Sockaddr_in
when defined(Windows):
name.sin_family = int16(ord(AF_INET))
name.sin_family = uint16(ord(AF_INET))
else:
name.sin_family = posix.AF_INET
name.sin_family = uint16(posix.AF_INET)
#name.sin_port = htons(cint16(port))
#name.sin_addr.s_addr = htonl(INADDR_ANY)
var namelen = sizeof(name).SockLen
@ -729,9 +729,9 @@ proc getHostByAddr*(ip: string): Hostent {.tags: [ReadIOEffect].} =
when defined(windows):
result.addrtype = Domain(s.h_addrtype)
else:
if s.h_addrtype == posix.AF_INET:
if s.h_addrtype.cint == posix.AF_INET:
result.addrtype = AF_INET
elif s.h_addrtype == posix.AF_INET6:
elif s.h_addrtype.cint == posix.AF_INET6:
result.addrtype = AF_INET6
else:
raiseOSError(osLastError(), "unknown h_addrtype")
@ -750,9 +750,9 @@ proc getHostByName*(name: string): Hostent {.tags: [ReadIOEffect].} =
when defined(windows):
result.addrtype = Domain(s.h_addrtype)
else:
if s.h_addrtype == posix.AF_INET:
if s.h_addrtype.cint == posix.AF_INET:
result.addrtype = AF_INET
elif s.h_addrtype == posix.AF_INET6:
elif s.h_addrtype.cint == posix.AF_INET6:
result.addrtype = AF_INET6
else:
raiseOSError(osLastError(), "unknown h_addrtype")