1

I am trying to integrate multipath tcp (https://www.multipath-tcp.org/) into a project, and I would like to modify the source code in order to manually choose the outgoing socket port for a new mptcp subflow so that I can identify the packets going in and out within my application.

The address is created with:

inet_create(sock_net(meta_sk), &sock, IPPROTO_TCP, 1);

and bound:

sock.ops->bind(&sock, (struct sockaddr *)&loc_in, sizeof(struct sockaddr_in));

and then connected:

sock.ops->connect(&sock, (struct sockaddr *)&rem_in,
            sizeof(struct sockaddr_in), O_NONBLOCK);

My question is this: How can I manually set the outgoing port of a socket at kernel level, and/or where is the port set in this sequence of calls, so I can modify it?

1 Answer 1

2

You would set the outgoing port in the loc_in structure that you use to bind() the socket to a local adapter/interface, eg:

struct sockaddr_in loc_in;
loc_in.sin_family = AF_INET;

// desired port...
loc_in.sin_port = htons(...);

// IP of desired adapter to connect() from...
loc_in.sin_addr.s_addr = inet_addr("...");
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Exactly what I needed.

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.