Update `toIPv4` and `toIPv6` to keep the port (#209)
Currently, converting a `TransportAddress` from IPv4 to IPv6 or vice-versa will set the port to 0.
This commit is contained in:
parent
14ebf269e9
commit
3a9cc6bfc9
|
@ -174,6 +174,7 @@ proc toIPv6*(address: TransportAddress): TransportAddress =
|
||||||
## If ``address`` is IPv6 address it will be returned without any changes.
|
## If ``address`` is IPv6 address it will be returned without any changes.
|
||||||
if address.family == AddressFamily.IPv4:
|
if address.family == AddressFamily.IPv4:
|
||||||
result = TransportAddress(family: AddressFamily.IPv6)
|
result = TransportAddress(family: AddressFamily.IPv6)
|
||||||
|
result.port = address.port
|
||||||
result.address_v6[10] = 0xFF'u8
|
result.address_v6[10] = 0xFF'u8
|
||||||
result.address_v6[11] = 0xFF'u8
|
result.address_v6[11] = 0xFF'u8
|
||||||
let data = cast[ptr uint32](unsafeAddr address.address_v4[0])[]
|
let data = cast[ptr uint32](unsafeAddr address.address_v4[0])[]
|
||||||
|
@ -202,6 +203,7 @@ proc toIPv4*(address: TransportAddress): TransportAddress =
|
||||||
if address.family == AddressFamily.IPv6:
|
if address.family == AddressFamily.IPv6:
|
||||||
if isV4Mapped(address):
|
if isV4Mapped(address):
|
||||||
result = TransportAddress(family: AddressFamily.IPv4)
|
result = TransportAddress(family: AddressFamily.IPv4)
|
||||||
|
result.port = address.port
|
||||||
let data = cast[ptr uint32](unsafeAddr address.address_v6[12])[]
|
let data = cast[ptr uint32](unsafeAddr address.address_v6[12])[]
|
||||||
cast[ptr uint32](addr result.address_v4[0])[] = data
|
cast[ptr uint32](addr result.address_v4[0])[] = data
|
||||||
elif address.family == AddressFamily.IPv4:
|
elif address.family == AddressFamily.IPv4:
|
||||||
|
|
Loading…
Reference in New Issue