aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/monitor.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/monitor.py b/src/monitor.py
index ef8146d..4c4b5ef 100644
--- a/src/monitor.py
+++ b/src/monitor.py
@@ -4,6 +4,7 @@
import os
import os.path
import socket
+import sys
import fcntl
import struct
import traceback
@@ -350,9 +351,18 @@ class Monitor:
status=fields[3]
loc_a,loc_p = loc.split(":")
rem_a,rem_p = rem.split(":")
- loc_addr = socket.inet_ntoa(struct.pack('I', int(loc_a, 16)))
+ if ( proto.find('6') != -1 ):
+ # the bytes must be reversed as IPV6 is four 32 bits blocks
+ loc_a = loc_a[24:32] + loc_a[16:24] + loc_a[8:16] + loc_a[0:8]
+ loc_a = int(loc_a, 16)
+ rem_a = rem_a[24:32] + rem_a[16:24] + rem_a[8:16] + rem_a[0:8]
+ rem_a = int(rem_a, 16)
+ loc_addr = socket.inet_ntop(socket.AF_INET6, loc_a.to_bytes(16, sys.byteorder))
+ rem_addr = socket.inet_ntop(socket.AF_INET6, rem_a.to_bytes(16, sys.byteorder))
+ else:
+ loc_addr = socket.inet_ntop(socket.AF_INET, struct.pack('I', int(loc_a, 16)))
+ rem_addr = socket.inet_ntop(socket.AF_INET, struct.pack('I', int(rem_a, 16)))
loc_port = (int(loc_p, 16))
- rem_addr = socket.inet_ntoa(struct.pack('I', int(rem_a, 16)))
rem_port = (int(rem_p, 16))
# parse status
status = int(status, 16)