r16528 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r16527‎ | r16528 | r16529 >
Date:12:39, 17 September 2006
Author:mark
Status:old
Tags:
Comment:
Add a -t option that sets the TTL for outgoing multicast packets
Clean up the help message
Modified paths:
  • /trunk/udpmcast/udpmcast.py (modified) (history)

Diff [purge]

Index: trunk/udpmcast/udpmcast.py
@@ -124,20 +124,22 @@
125125 def print_help():
126126 print 'Usage:\n\tudpmcast [ options ] { addresses | forward rules }\n'
127127 print 'Options:'
128 - print '\t-d\tFork into the background (become a daemon)'
 128+ print '\t-d\t\tFork into the background (become a daemon)'
129129 print '\t-p {portnr}\tUDP port number to listen on (default is 4827)'
130 - print '\t-j {multicast address}\tMulticast group to join on startup'
131 - print '\t-u {username}Change uid'
132 - print '\t-g {group}Change group'
133 - print '\t-v\tBe more verbose'
 130+ print '\t-j {mcast addr}\tMulticast group to join on startup'
 131+ print '\t-u {username}\tChange uid'
 132+ print '\t-g {group}\tChange group'
 133+ print '\t-t {ttl}\tSet multicast TTL for outgoing multicast packets'
 134+ print '\t-v\t\tBe more verbose'
134135
135136 if __name__ == '__main__':
136137 host = ''
137138 portnr = 4827
138139 multicast_group = None
 140+ multicast_ttl = None
139141 daemon = False
140142 user = group = None
141 - opts = 'dhj:p:vu:g:'
 143+ opts = 'dhj:p:vu:g:t:'
142144
143145 # Parse options
144146 options, arguments = getopt.getopt(sys.argv[1:], opts)
@@ -161,6 +163,8 @@
162164 group = value
163165 elif option == '-v':
164166 debugging = True
 167+ elif option == '-t':
 168+ multicast_ttl = int(value)
165169
166170 try:
167171 # Change uid and gid
@@ -178,9 +182,15 @@
179183 # Open the UDP socket
180184 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
181185 sock.bind((host, portnr))
 186+
 187+ # Set the multicast TTL if requested
 188+ if multicast_ttl is not None:
 189+ sock.setsockopt(socket.IPPROTO_IP,
 190+ socket.IP_MULTICAST_TTL,
 191+ multicast_ttl)
182192
183193 # Join a multicast group if requested
184 - if multicast_group != None:
 194+ if multicast_group is not None:
185195 debug('Joining multicast group ' + multicast_group)
186196 join_multicast_group(sock, multicast_group)
187197