packet fragmentation for raw sockets

前端 未结 5 880
春和景丽
春和景丽 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条回答
  •  情深已故
    2021-01-06 19:11

    Depending on your system this can be handled quite differently. For example on Linux you can ask the lower layers to handle path MTU discovery and give an error (EMSGSIZE) if you try and send something larger than the (known) path MTU.

    How "raw" is the raw socket you're talking about? Other systems could just let you control the DF bit (or you might be constructing most of the IP header yourself) in which case the behaviour will also depend on this.

    As a rule if you transmit with DF set you will usually get a choice of seeing an error in userspace, or having the lower levels on your host handle PMTU discovery and stopping you sending something too large. If you don't set DF then you (probably) will see appropriate fragmentation from router(s) along the path.

提交回复
热议问题