summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2021-05-25 23:54:20 +0300
committerDevaev Maxim <[email protected]>2021-05-25 23:54:20 +0300
commit9b4cbfab7f71ee4a98657a8bd1b55f3a0aa3ea5f (patch)
tree34213d02ebde43948cc51ee3bdaacb3e92545d3f
parent6ce07208a1b6a9fec07d610ced5a73630176662f (diff)
ipv6 stun
-rw-r--r--kvmd/apps/janus/stun.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/kvmd/apps/janus/stun.py b/kvmd/apps/janus/stun.py
index 9a54e5df..837cd377 100644
--- a/kvmd/apps/janus/stun.py
+++ b/kvmd/apps/janus/stun.py
@@ -1,5 +1,6 @@
import asyncio
import socket
+import ipaddress
import struct
import secrets
import dataclasses
@@ -168,10 +169,9 @@ class Stun:
def __parse_address(self, data: bytes) -> StunAddress:
family = data[1]
- if family == 1:
- parts = struct.unpack(">HBBBB", data[2:8])
- return StunAddress(
- ip=".".join(map(str, parts[1:])),
- port=parts[0],
- )
- raise RuntimeError(f"Only IPv4 supported; received: {family}")
+ port = struct.unpack(">H", data[2:4])[0]
+ if family == 0x01:
+ return StunAddress(str(ipaddress.IPv4Address(data[4:8])), port)
+ elif family == 0x02:
+ return StunAddress(str(ipaddress.IPv6Address(data[4:20])), port)
+ raise RuntimeError(f"Unknown family; received: {family}")