forked from nim-lang/Nim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Various std net improvements (nim-lang#19132)
* Variant of that works with raw IpAddresses. - Add doc tests for new net proc's. - Aadd recvFrom impl - Add recvFrom impl -- tweak handling data var - Update lib/pure/net.nim Co-authored-by: Dominik Picheta <[email protected]> - cleaning up sendTo args - remove extra connect test - cleaning up sendTo args - fix inet_ntop test - fix test failing - byte len * fix test failing - byte len * debugging odd windows build failure * debugging odd windows build failure * more experiments to figure out the windows failure * try manual assigment on InAddr Co-authored-by: Jaremy Creechley <[email protected]>
- Loading branch information
Showing
3 changed files
with
97 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,45 @@ | ||
discard """ | ||
action: run | ||
output: ''' | ||
[Suite] inet_ntop tests | ||
''' | ||
""" | ||
|
||
when defined(windows): | ||
import winlean | ||
elif defined(posix): | ||
import posix | ||
else: | ||
{.error: "Unsupported OS".} | ||
|
||
import unittest, strutils | ||
|
||
suite "inet_ntop tests": | ||
|
||
setup: | ||
when defined(windows): | ||
var wsa: WSAData | ||
discard wsaStartup(0x101'i16, wsa.addr) | ||
|
||
test "IP V4": | ||
var ip4 = 0x10111213 | ||
var buff: array[0..255, char] | ||
let r = inet_ntop(AF_INET, ip4.addr, buff[0].addr, buff.sizeof.int32) | ||
let res = if r == nil: "" else: $r | ||
check: res == "19.18.17.16" | ||
|
||
|
||
test "IP V6": | ||
when defined(windows): | ||
let ipv6Support = (getVersion() and 0xff) > 0x5 | ||
else: | ||
let ipv6Support = true | ||
|
||
var ip6 = [0x1000'u16, 0x1001, 0x2000, 0x2001, 0x3000, 0x3001, 0x4000, 0x4001] | ||
var buff: array[0..255, char] | ||
let r = inet_ntop(AF_INET6, ip6[0].addr, buff[0].addr, buff.sizeof.int32) | ||
let res = if r == nil: "" else: $r | ||
check: not ipv6Support or res == "10:110:20:120:30:130:40:140" | ||
discard """ | ||
action: run | ||
output: ''' | ||
[Suite] inet_ntop tests | ||
''' | ||
""" | ||
|
||
when defined(windows): | ||
import winlean | ||
elif defined(posix): | ||
import posix | ||
else: | ||
{.error: "Unsupported OS".} | ||
|
||
import unittest, strutils | ||
|
||
suite "inet_ntop tests": | ||
|
||
setup: | ||
when defined(windows): | ||
var wsa: WSAData | ||
discard wsaStartup(0x101'i16, wsa.addr) | ||
|
||
test "IP V4": | ||
# regular | ||
var ip4 = InAddr() | ||
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) | ||
let res = if r == nil: "" else: $r | ||
check: res == "19.18.17.16" | ||
|
||
test "IP V6": | ||
when defined(windows): | ||
let ipv6Support = (getVersion() and 0xff) > 0x5 | ||
else: | ||
let ipv6Support = true | ||
|
||
var ip6 = [0x1000'u16, 0x1001, 0x2000, 0x2001, 0x3000, 0x3001, 0x4000, 0x4001] | ||
var buff: array[0..255, char] | ||
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" |