Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #19244 - solves the problem of the InAddr object constructor in Windows. #19259

Merged
merged 2 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/windows/winlean.nim
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ type

PSockAddr = ptr SockAddr

InAddr* {.importc: "IN_ADDR", header: "winsock2.h".} = object
InAddr* {.importc: "IN_ADDR", header: "winsock2.h", union.} = object
s_addr*: uint32 # IP address

Sockaddr_in* {.importc: "SOCKADDR_IN",
Expand Down
6 changes: 6 additions & 0 deletions tests/stdlib/tnet_ll.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ suite "inet_ntop tests":
# regular
var ip4 = InAddr()
ip4.s_addr = 0x10111213'u32
check: ip4.s_addr == 0x10111213'u32

var buff: array[0..255, char]
let r = inet_ntop(AF_INET, cast[pointer](ip4.s_addr.addr), buff[0].addr, buff.len.int32)
Expand All @@ -43,3 +44,8 @@ suite "inet_ntop tests":
let r = inet_ntop(AF_INET6, cast[pointer](ip6[0].addr), buff[0].addr, buff.len.int32)
let res = if r == nil: "" else: $r
check: not ipv6Support or res == "10:110:20:120:30:130:40:140"

test "InAddr":
# issue 19244
var ip4 = InAddr(s_addr: 0x10111213'u32)
check: ip4.s_addr == 0x10111213'u32