Ofir Reichenberg suggested to apply htonl() to grpaddr in openmcastsock().

Also got rid of unnecessary use of eval() and regsub.gsub().
This commit is contained in:
Guido van Rossum 1999-08-07 14:01:05 +00:00
parent d3fbdfd007
commit 4f1a6187a5
1 changed files with 3 additions and 3 deletions

View File

@ -59,7 +59,7 @@ def receiver():
# Open a UDP socket, bind it to a port and select a multicast group # Open a UDP socket, bind it to a port and select a multicast group
def openmcastsock(group, port): def openmcastsock(group, port):
# Import modules used only here # Import modules used only here
import regsub import string
import struct import struct
# #
# Create a socket # Create a socket
@ -77,13 +77,13 @@ def openmcastsock(group, port):
group = gethostbyname(group) group = gethostbyname(group)
# #
# Construct binary group address # Construct binary group address
bytes = eval(regsub.gsub('\.', ',', group)) bytes = map(int, string.split(group, "."))
grpaddr = 0 grpaddr = 0
for byte in bytes: grpaddr = (grpaddr << 8) | byte for byte in bytes: grpaddr = (grpaddr << 8) | byte
# #
# Construct struct mreq from grpaddr and ifaddr # Construct struct mreq from grpaddr and ifaddr
ifaddr = INADDR_ANY ifaddr = INADDR_ANY
mreq = struct.pack('ll', grpaddr, ifaddr) mreq = struct.pack('ll', htonl(grpaddr), htonl(ifaddr))
# #
# Add group membership # Add group membership
s.setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP, mreq) s.setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP, mreq)