Better way of deducing mcast group bytes.

This commit is contained in:
Guido van Rossum 1992-09-24 10:33:40 +00:00
parent c8833d4ad3
commit 7814c10233
1 changed files with 7 additions and 8 deletions

View File

@ -6,14 +6,15 @@
# mcast (receivers)
MYPORT = 8123
MYGROUP_BYTES = 225, 0, 0, 250
MYGROUP = '225.0.0.250'
import sys
import time
import struct
import regsub
from socket import *
from SOCKET import *
from IN import *
from IN import * # Local module, SGI specific!!!
sender = sys.argv[1:]
@ -24,10 +25,7 @@
s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
mygroup = '<broadcast>'
else:
# Ugly: construct decimal IP address string from MYGROUP_BYTES
mygroup = ''
for byte in MYGROUP_BYTES: mygroup = mygroup + '.' + `byte`
mygroup = mygroup[1:]
mygroup = MYGROUP
ttl = struct.pack('b', 1) # Time-to-live
s.setsockopt(IPPROTO_IP, IP_MULTICAST_TTL, ttl)
while 1:
@ -42,9 +40,10 @@
# Allow multiple copies of this program on one machine
s.setsockopt(SOL_SOCKET, SO_REUSEPORT, 1) # (Not strictly needed)
# Ugly: construct binary group address from MYGROUP_BYTES
# Ugly: construct binary group address from MYGROUP converted to bytes
bytes = eval(regsub.gsub('\.', ',', MYGROUP))
grpaddr = 0
for byte in MYGROUP_BYTES: grpaddr = (grpaddr << 8) | byte
for byte in bytes: grpaddr = (grpaddr << 8) | byte
# Construct struct mreq from grpaddr and ifaddr
ifaddr = INADDR_ANY