From 4f1a6187a59fbe58244e34954300af02d33b336d Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sat, 7 Aug 1999 14:01:05 +0000 Subject: [PATCH] Ofir Reichenberg suggested to apply htonl() to grpaddr in openmcastsock(). Also got rid of unnecessary use of eval() and regsub.gsub(). --- Demo/sockets/mcast.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Demo/sockets/mcast.py b/Demo/sockets/mcast.py index fe4aacbba3c..cc7a7e07d44 100755 --- a/Demo/sockets/mcast.py +++ b/Demo/sockets/mcast.py @@ -59,7 +59,7 @@ def receiver(): # Open a UDP socket, bind it to a port and select a multicast group def openmcastsock(group, port): # Import modules used only here - import regsub + import string import struct # # Create a socket @@ -77,13 +77,13 @@ def openmcastsock(group, port): group = gethostbyname(group) # # Construct binary group address - bytes = eval(regsub.gsub('\.', ',', group)) + bytes = map(int, string.split(group, ".")) grpaddr = 0 for byte in bytes: grpaddr = (grpaddr << 8) | byte # # Construct struct mreq from grpaddr and ifaddr ifaddr = INADDR_ANY - mreq = struct.pack('ll', grpaddr, ifaddr) + mreq = struct.pack('ll', htonl(grpaddr), htonl(ifaddr)) # # Add group membership s.setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP, mreq)