1

This question suggests that the Node.js Net module doesn't handle ip-fragmentation: Node.js how to handle packet fragmentation with net.Server

I can almost not imagine it's true, but I can't find any documentation about this (please forgive me if it shouldn't be too hard to find information about this :-) ). Is it true?

If not: thank you, that's a real day-safer to me :-).

If it is true: how to handle this problem if I don't know how large the whole datagram is?

Situation: I have a TCP connection with an embedded system (Wiznet W5500). The MSS (Maximum Segment Size, mostly equal to MTU - 40) will be set to 536 and data packages are a variable size and may be over 4kb in size. So the data package will be send in multiple segments. Will the 'on data' event be triggered once a segment is received or only when the whole package is received?

Side question: Am I right that the data segment (about what Wiznet is talking in the explanation of the MSS register) equel is to a ip-fragment? So if I have to send 4000byte (ie payload) and the MSS is set to 536 I will receive consecutively: segment1: 536bytes payload segment2: 536bytes payload segment3: 536bytes payload segment4: 536bytes payload segment5: 536bytes payload segment6: 536bytes payload segment7: 536bytes payload segment8: 248bytes payload May the 'on data' event only be triggered after segment 8 an will the 'data argument' contain the whole package or may it happen that the 'on data' event will be triggered after every separately received segment?

How can I make 100% sure that I get the whole package before I continue to process it? Solution I thought of:

  • First 2 byte of the data package is the byte length of the whole length, I keep concattenating received data until I have received as many bytes. If I received more than the package size, I'll assume these successive bytes are the start of a subsequent data package.

I do believe this 'solution' is somewhat tricky and I hope it's not required.

Thanks in advance! If any information is missing: I'm sorry, please feel free to ask for it :-).

Community
  • 1
  • 1
Sander
  • 171
  • 1
  • 10
  • 1
    I still didn't find the answer unfortunately. I'll post an answer as soon as I know one so others can profit. – Sander Jan 16 '17 at 09:48

1 Answers1

0

I am a big fan of nodeJS, but in this case you should use python with scapy :)

http://www.secdev.org/projects/scapy/

Mech45
  • 321
  • 1
  • 9
  • My application is, after weeks of work, finally almost ready to launch. Just tweaking the last potential bugs. But I'll look into it. Maybe I'll use it in the future. Thanks for your suggestion. – Sander Jan 12 '17 at 22:01
  • But does this mean that NodeJS does indeed not handle ip fragmentation before calling the 'on event'? – Sander Jan 16 '17 at 09:47