3

Looking at a representation of the TCP/IP stack, such as in this photo: enter image description here

I would be interested (just out of curiosity) to try and read the layer 2 (data link) headers. Is this possible? I think that the net module only gives access to the transport layer packets. I see there is a udp module as well, but similarly I doubt that I could get data link-layer packet information from this.

Is the above correct? Am I correct in thinking that transport-layer packet data is made available to the JavaScript runtime via the v8/etc implementation and that lower level packet data (i.e. ethernet layer) is NOT exposed to Node.js runtimes?

Zach Smith
  • 8,458
  • 13
  • 59
  • 133
  • Why the downvote? (I'm aware that I may have a complete and basic misunderstanding of this subject. if this is the case a comment as to why would be helpful, rather than just a downvote) – Zach Smith Oct 21 '18 at 14:20
  • 2
    You can check table of contents to make sure what you can do and what you can't https://nodejs.org/api/ . Ethernet layer is obviously not exposed. I assume can access you whatever you wish with native addons. – Estus Flask Oct 21 '18 at 14:29

1 Answers1

1

node.js has access to layer 3 and above. To capture layer 2 packets you need to call external programs like wireshark, or use modules that integrate these low level tools.

Wireshark has a command line interface, you could invoke it from node using child_process.

mihai
  • 37,072
  • 9
  • 60
  • 86