diff options
author | Guido van Rossum <guido@python.org> | 1992-09-24 10:33:40 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1992-09-24 10:33:40 (GMT) |
commit | 7814c10233cde1c85e6eaae4a9b623d00c471bdd (patch) | |
tree | bd8bf7fac8c0dd897c25680514e8e71c84fd66fa | |
parent | c8833d4ad39557e870bc10fba3ea598f68dca1fd (diff) | |
download | cpython-7814c10233cde1c85e6eaae4a9b623d00c471bdd.zip cpython-7814c10233cde1c85e6eaae4a9b623d00c471bdd.tar.gz cpython-7814c10233cde1c85e6eaae4a9b623d00c471bdd.tar.bz2 |
Better way of deducing mcast group bytes.
-rwxr-xr-x | Demo/sockets/mcast.py | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/Demo/sockets/mcast.py b/Demo/sockets/mcast.py index 5f16ed9..a6bee7c 100755 --- a/Demo/sockets/mcast.py +++ b/Demo/sockets/mcast.py @@ -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 @@ if sender: 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 @@ else: # 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 |