Wed, May 15, 2019 at 01:44:00PM CEST, csfakian(a)redhat.com wrote:
From: Christos Sfakianakis <csfakian(a)redhat.com>
Add multicast address verification (to be used with vxlan recipes).
Signed-off-by: Christos Sfakianakis <csfakian(a)redhat.com>
---
lnst/Common/IpAddress.py | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/lnst/Common/IpAddress.py b/lnst/Common/IpAddress.py
index 53dc047..b9fc949 100644
--- a/lnst/Common/IpAddress.py
+++ b/lnst/Common/IpAddress.py
@@ -13,7 +13,7 @@ olichtne(a)redhat.com (Ondrej Lichtner)
import re
from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
from binascii import hexlify
-import socket
+import socket, struct
from lnst.Common.LnstError import LnstError
#TODO create various generators for IPNetworks and IPaddresses in the same
@@ -74,6 +74,13 @@ class Ip4Address(BaseIpAddress):
return addr, prefixlen
+ def is_multicast(self):
+ pack = socket.inet_aton
+ unpack = struct.unpack
+ triade = ["224.0.0.0", str(self), "239.255.255.255"]
+ triade = [unpack("!L", pack(val))[0] for val in triade]
+ return sorted(triade) == triade
+
I'd like to get some explanation of the code above.
Could you explain how this works?
Thanks,
Jan