Index: trunk/udpmcast/udpmcast.py |
— | — | @@ -124,20 +124,22 @@ |
125 | 125 | def print_help(): |
126 | 126 | print 'Usage:\n\tudpmcast [ options ] { addresses | forward rules }\n' |
127 | 127 | 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)' |
129 | 129 | 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' |
134 | 135 | |
135 | 136 | if __name__ == '__main__': |
136 | 137 | host = '' |
137 | 138 | portnr = 4827 |
138 | 139 | multicast_group = None |
| 140 | + multicast_ttl = None |
139 | 141 | daemon = False |
140 | 142 | user = group = None |
141 | | - opts = 'dhj:p:vu:g:' |
| 143 | + opts = 'dhj:p:vu:g:t:' |
142 | 144 | |
143 | 145 | # Parse options |
144 | 146 | options, arguments = getopt.getopt(sys.argv[1:], opts) |
— | — | @@ -161,6 +163,8 @@ |
162 | 164 | group = value |
163 | 165 | elif option == '-v': |
164 | 166 | debugging = True |
| 167 | + elif option == '-t': |
| 168 | + multicast_ttl = int(value) |
165 | 169 | |
166 | 170 | try: |
167 | 171 | # Change uid and gid |
— | — | @@ -178,9 +182,15 @@ |
179 | 183 | # Open the UDP socket |
180 | 184 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
181 | 185 | 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) |
182 | 192 | |
183 | 193 | # Join a multicast group if requested |
184 | | - if multicast_group != None: |
| 194 | + if multicast_group is not None: |
185 | 195 | debug('Joining multicast group ' + multicast_group) |
186 | 196 | join_multicast_group(sock, multicast_group) |
187 | 197 | |