1

I will like to get some help on how to modify the TCP header as well as change the options on a TCP header. I am especially interested in the MSS section of the options.

I have tried using the setsockopt() with different options to no success.

Here is some code attempting to change the MSS:

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    #! Settings mss
    s.setsockopt(socket.IPPROTO_TCP, socket.IP_OPTIONS , b"MSS:400")

I expect the MSS to change to 400. The code runs but it doesn't change the MSS (inspected with Wireshark).

1
  • b"MSS:400" is not the correct value of the MSS option in the TCP header. TCP header options aren't strings, they're numbers. MSS is option number 2, length = 4, value = 2 bytes containing the value. Commented Jul 12, 2019 at 16:12

2 Answers 2

5

Use the TCP_MAXSEG option.

s.setsockopt(socket.IPPROTO_TCP, socket.TCP_MAXSEG, 400)
Sign up to request clarification or add additional context in comments.

3 Comments

Awesome works on Linux! This will not work on Windows I am guessing due to lack of raw socket support?!
I don't think this has anything to do with raw sockets.
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_MAXSEG, 400) print(sock.getsockopt(socket.IPPROTO_TCP, socket.TCP_MAXSEG)) MSS -> 536 Not working
0

in addition to what @Barmar said, you can find more info in the "man pages" on any unix system by typing one of:

man 7 ip
man 7 tcp
man 7 udp

man is short for manual, 7 is overview/misc section

the tcp page says this about TCP_MAXSEG:

The maximum segment size for outgoing TCP packets. In Linux 2.2 and earlier, and in Linux 2.6.28 and later, if this option is set before connection establishment, it also changes the MSS value announced to the other end in the initial packet. Values greater than the (eventual) interface MTU have no effect. TCP will also impose its minimum and maximum bounds over the value provided.

1 Comment

Awesome, Good Tip!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.