Fix wrong value range of ntohs ... (#5390)

This commit is contained in:
wt 2017-04-01 04:13:06 +08:00 • committed by Andreas Rumpf
commit c480505797
2 changed files with 7 additions and 7 deletions

View file

@ -1862,10 +1862,10 @@ when hasAioH:
a4: ptr SigEvent): cint {.importc, header: "<aio.h>".} a4: ptr SigEvent): cint {.importc, header: "<aio.h>".}
# arpa/inet.h # arpa/inet.h
proc htonl*(a1: int32): int32 {.importc, header: "<arpa/inet.h>".} proc htonl*(a1: uint32): uint32 {.importc, header: "<arpa/inet.h>".}
proc htons*(a1: int16): int16 {.importc, header: "<arpa/inet.h>".} proc htons*(a1: uint16): uint16 {.importc, header: "<arpa/inet.h>".}
proc ntohl*(a1: int32): int32 {.importc, header: "<arpa/inet.h>".} proc ntohl*(a1: uint32): uint32 {.importc, header: "<arpa/inet.h>".}
proc ntohs*(a1: int16): int16 {.importc, header: "<arpa/inet.h>".} proc ntohs*(a1: uint16): uint16 {.importc, header: "<arpa/inet.h>".}
proc inet_addr*(a1: cstring): InAddrT {.importc, header: "<arpa/inet.h>".} proc inet_addr*(a1: cstring): InAddrT {.importc, header: "<arpa/inet.h>".}
proc inet_ntoa*(a1: InAddr): cstring {.importc, header: "<arpa/inet.h>".} proc inet_ntoa*(a1: InAddr): cstring {.importc, header: "<arpa/inet.h>".}

View file

@ -33,8 +33,8 @@ proc prepareAddress(intaddr: uint32, intport: uint16): ptr Sockaddr_in =
result.sin_family = toInt(nativesockets.AF_INET).int16 result.sin_family = toInt(nativesockets.AF_INET).int16
else: else:
result.sin_family = toInt(nativesockets.AF_INET) result.sin_family = toInt(nativesockets.AF_INET)
result.sin_port = htons(intport) result.sin_port = nativesockets.htons(intport)
result.sin_addr.s_addr = htonl(intaddr) result.sin_addr.s_addr = nativesockets.htonl(intaddr)
proc launchSwarm(name: ptr SockAddr) {.async.} = proc launchSwarm(name: ptr SockAddr) {.async.} =
var i = 0 var i = 0
@ -90,7 +90,7 @@ proc readMessages(server: AsyncFD) {.async.} =
await sendTo(server, addr grammString[0], len(grammString), await sendTo(server, addr grammString[0], len(grammString),
cast[ptr SockAddr](addr saddr), slen) cast[ptr SockAddr](addr saddr), slen)
inc(msgCount) inc(msgCount)
saveReceivedPort(ntohs(saddr.sin_port).int) saveReceivedPort(nativesockets.ntohs(saddr.sin_port).int)
inc(i) inc(i)
proc createServer() {.async.} = proc createServer() {.async.} =