aboutsummaryrefslogtreecommitdiffstats
path: root/netlib
diff options
context:
space:
mode:
Diffstat (limited to 'netlib')
-rw-r--r--netlib/utils.py29
-rw-r--r--netlib/version.py1
2 files changed, 27 insertions, 3 deletions
diff --git a/netlib/utils.py b/netlib/utils.py
index 61fd54ae..00e1cd12 100644
--- a/netlib/utils.py
+++ b/netlib/utils.py
@@ -1,3 +1,5 @@
+import socket
+
def isascii(s):
try:
@@ -32,9 +34,9 @@ def hexdump(s):
"""
parts = []
for i in range(0, len(s), 16):
- o = "%.10x"%i
- part = s[i:i+16]
- x = " ".join("%.2x"%ord(i) for i in part)
+ o = "%.10x" % i
+ part = s[i:i + 16]
+ x = " ".join("%.2x" % ord(i) for i in part)
if len(part) < 16:
x += " "
x += " ".join(" " for i in range(16 - len(part)))
@@ -42,3 +44,24 @@ def hexdump(s):
(o, x, cleanBin(part, True))
)
return parts
+
+
+def inet_ntop(address_family, packed_ip):
+ if hasattr(socket, "inet_ntop"):
+ return socket.inet_ntop(address_family, packed_ip)
+ # Windows Fallbacks
+ if address_family == socket.AF_INET:
+ return socket.inet_ntoa(packed_ip)
+ if address_family == socket.AF_INET6:
+ ip = packed_ip.encode("hex")
+ return ":".join([ip[i:i + 4] for i in range(0, len(ip), 4)])
+
+
+def inet_pton(address_family, ip_string):
+ if hasattr(socket, "inet_pton"):
+ return socket.inet_pton(address_family, ip_string)
+ # Windows Fallbacks
+ if address_family == socket.AF_INET:
+ return socket.inet_aton(ip_string)
+ if address_family == socket.AF_INET6:
+ return ip_string.replace(":", "").decode("hex") \ No newline at end of file
diff --git a/netlib/version.py b/netlib/version.py
index 1d3250e1..25565d40 100644
--- a/netlib/version.py
+++ b/netlib/version.py
@@ -1,4 +1,5 @@
IVERSION = (0, 11)
VERSION = ".".join(str(i) for i in IVERSION)
+MINORVERSION = ".".join(str(i) for i in IVERSION[:2])
NAME = "netlib"
NAMEVERSION = NAME + " " + VERSION