(argv, extract_route)
| 94 | |
| 95 | |
| 96 | def _list_routes(argv, extract_route): |
| 97 | # FIXME: IPv4 only |
| 98 | p = ssubprocess.Popen(argv, stdout=ssubprocess.PIPE, env=get_env()) |
| 99 | routes = [] |
| 100 | for line in p.stdout: |
| 101 | if not line.strip(): |
| 102 | continue |
| 103 | ipw, mask = extract_route(line.decode("ASCII")) |
| 104 | if not ipw: |
| 105 | continue |
| 106 | width = min(ipw[1], mask) |
| 107 | ip = ipw[0] & _shl(_shl(1, width) - 1, 32 - width) |
| 108 | routes.append( |
| 109 | (socket.AF_INET, socket.inet_ntoa(struct.pack('!I', ip)), width)) |
| 110 | rv = p.wait() |
| 111 | if rv != 0: |
| 112 | log('WARNING: %r returned %d' % (argv, rv)) |
| 113 | |
| 114 | return routes |
| 115 | |
| 116 | |
| 117 | def list_routes(): |
no test coverage detected