recvfrom with Raw Sockets, get just the data

后端 未结 2 1714
盖世英雄少女心
盖世英雄少女心 2021-01-27 03:29

I\'m trying to implement my own transport layer protocol, but I\'m perfectly happy to leave the network layer as-is and not need to mess with the actual IP header information.

相关标签:
2条回答
  • 2021-01-27 03:56

    Use recvmsg() with the msg[] buffers initialized so that the first one receives the IP header, then the second one will only contain data.

    0 讨论(0)
  • 2021-01-27 04:20

    The IP header will always be included when receiving on a SOCK_RAW socket.

    Per raw(7):

    The IPv4 layer generates an IP header when sending a packet unless the IP_HDRINCL socket option is enabled on the socket. When it is enabled, the packet must contain an IP header. For receiving the IP header is always included in the packet.

    Reference:

    • ip(7) man page
    • SOCK_RAW Demystified
    • Advanced TCP/IP - THE RAW SOCKET PROGRAM EXAMPLES
    0 讨论(0)
提交回复
热议问题