Looking at a representation of the TCP/IP stack, such as in this photo:
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?
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
.