packet fragmentation for raw sockets

前端 未结 5 884
春和景丽
春和景丽 2021-01-06 18:49

If I am using raw sockets to send a UDP packet of size 3000bytes, do I need to handle packet fragmentation myself in the code, or should the raw socket handle fragmentation

5条回答
  •  猫巷女王i
    2021-01-06 19:21

    Well, if you are using UDP, you aren't really sending RAW. RAW would be no IP at all, in which case yes you have to handle fragmentation yourself.

    With UDP you get IP's fragmentation support, which is IMHO plenty good enough for short-haul networks where collisions should be minimal. Make the link between the two systems a dedicated subnet, and it isn't an issue at all.

    What TCP buys you over UDP (among other things) is the stack's ability to just have to resend one fragment if it gets lost or hosed somehow. With UDP if that happens the entire message must be discarded. There's overhead with that though, and for most modern networks you can probably live with that trade-off.

提交回复
热议问题