Reputation: 7217
How can I get the TCP port number of a tcp_sock
structure in the Linux kernel? The instance of tcp_sock
is in the context of tcp_recvmsg()
.
Upvotes: 3
Views: 841
Reputation: 1
Use htons((unsigned short int)inet_sk(sk)->inet_sport)
and htons((unsigned short int)inet_sk(sk)->inet_dport)
to get ports as per wireshark
port
Upvotes: 0
Reputation: 7217
In tcp_recvmsg()
, the struct tcp_sock
object is derived from parameter struct sock sk
. You can do inet_sk(sk)->inet_sport
to get the destination port of the TCP packet. inet_sk(sk)->inet_dport
should get the source port of the packet.
Upvotes: 2