Select the network interface according to the layer 3 destination
(packet: _PacketIterable)
| 670 | |
| 671 | |
| 672 | def _interface_selection(packet: _PacketIterable) -> Tuple[NetworkInterface, bool]: |
| 673 | """ |
| 674 | Select the network interface according to the layer 3 destination |
| 675 | """ |
| 676 | _iff, src, _ = next(packet.__iter__()).route() |
| 677 | ipv6 = False |
| 678 | if src: |
| 679 | try: |
| 680 | inet_pton(socket.AF_INET6, src) |
| 681 | ipv6 = True |
| 682 | except (ValueError, OSError): |
| 683 | pass |
| 684 | try: |
| 685 | iff = resolve_iface(_iff or conf.iface) |
| 686 | except AttributeError: |
| 687 | iff = None |
| 688 | return iff or conf.iface, ipv6 |
| 689 | |
| 690 | |
| 691 | @conf.commands.register |