TCP handshake with SOCK_RAW socket

后端 未结 7 1210
灰色年华
灰色年华 2020-12-23 22:19

Ok, I realize this situation is somewhat unusual, but I need to establish a TCP connection (the 3-way handshake) using only raw sockets (in C, in linux) -- i.e. I need to co

相关标签:
7条回答
  • 2020-12-23 23:14

    There are structures for IP and TCP headers declared in netinet/ip.h & netinet/tcp.h respectively. You may want to look at the other headers in this directory for extra macros & stuff that may be of use.

    You send a packet with the SYN flag set and a random sequence number (x). You should receive a SYN+ACK from the other side. This packet will have an acknowledgement number (y) that indicates the next sequence number the other side is expecting to receive as well as another sequence number (z). You send back an ACK packet that has sequence number x+1 and ack number z+1 to complete the connection.

    You also need to make sure you calculate appropriate TCP/IP checksums & fill out the remainder of the header for the packets you send. Also, don't forget about things like host & network byte order.

    TCP is defined in RFC 793, available here: http://www.faqs.org/rfcs/rfc793.html

    0 讨论(0)
提交回复
热议问题