summaryrefslogtreecommitdiffstats
path: root/Demo/sockets
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1999-08-07 14:01:05 (GMT)
committerGuido van Rossum <guido@python.org>1999-08-07 14:01:05 (GMT)
commit4f1a6187a59fbe58244e34954300af02d33b336d (patch)
tree39dcd7a403f5668d8b2e828ffc17523a64a19bb2 /Demo/sockets
parentd3fbdfd007efc8c0e64e1dbb97f1b3992a23e361 (diff)
downloadcpython-4f1a6187a59fbe58244e34954300af02d33b336d.zip
cpython-4f1a6187a59fbe58244e34954300af02d33b336d.tar.gz
cpython-4f1a6187a59fbe58244e34954300af02d33b336d.tar.bz2
Ofir Reichenberg suggested to apply htonl() to grpaddr in openmcastsock().
Also got rid of unnecessary use of eval() and regsub.gsub().
Diffstat (limited to 'Demo/sockets')
-rwxr-xr-xDemo/sockets/mcast.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/Demo/sockets/mcast.py b/Demo/sockets/mcast.py
index fe4aacb..cc7a7e0 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)