Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5e4ae30

Browse filesBrowse files
committed
tests/divert: use PF_DIVERT
Now all Python ports has been patched to support PF_DIVERT, and Python kinda promises to add support in 3.12 [1]. This reverts commit 322b5b7. [1] python/cpython#96536 (comment)
1 parent 829f0bc commit 5e4ae30
Copy full SHA for 5e4ae30

File tree

1 file changed

+4
-7
lines changed
Filter options

1 file changed

+4
-7
lines changed

‎tests/sys/common/divert.py

Copy file name to clipboardExpand all lines: tests/sys/common/divert.py
+4-7Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,13 @@
2929
#
3030

3131

32-
import socket
32+
from socket import socket, PF_DIVERT, SOCK_RAW
3333
import logging
3434
logging.getLogger("scapy").setLevel(logging.CRITICAL)
3535
import scapy.all as sc
3636
import argparse
3737

3838

39-
IPPROTO_DIVERT = 258
40-
41-
4239
def parse_args():
4340
parser = argparse.ArgumentParser(description='divert socket tester')
4441
parser.add_argument('--dip', type=str, help='destination packet IP')
@@ -52,22 +49,22 @@ def parse_args():
5249

5350
def ipdivert_ip_output_remote_success(args):
5451
packet = sc.IP(dst=args.dip) / sc.ICMP(type='echo-request')
55-
with socket.socket(socket.AF_INET, socket.SOCK_RAW, IPPROTO_DIVERT) as s:
52+
with socket(PF_DIVERT, SOCK_RAW, 0) as s:
5653
s.bind(('0.0.0.0', args.divert_port))
5754
s.sendto(bytes(packet), ('0.0.0.0', 0))
5855

5956

6057
def ipdivert_ip6_output_remote_success(args):
6158
packet = sc.IPv6(dst=args.dip) / sc.ICMPv6EchoRequest()
62-
with socket.socket(socket.AF_INET, socket.SOCK_RAW, IPPROTO_DIVERT) as s:
59+
with socket(PF_DIVERT, SOCK_RAW, 0) as s:
6360
s.bind(('0.0.0.0', args.divert_port))
6461
s.sendto(bytes(packet), ('0.0.0.0', 0))
6562

6663

6764
def ipdivert_ip_input_local_success(args):
6865
"""Sends IPv4 packet to OS stack as inbound local packet."""
6966
packet = sc.IP(dst=args.dip,src=args.sip) / sc.ICMP(type='echo-request')
70-
with socket.socket(socket.AF_INET, socket.SOCK_RAW, IPPROTO_DIVERT) as s:
67+
with socket(PF_DIVERT, SOCK_RAW, 0) as s:
7168
s.bind(('0.0.0.0', args.divert_port))
7269
s.sendto(bytes(packet), (args.dip, 0))
7370

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.