Live data from Hacker News

Libtins – High-level and multiplatform C++ network packet sniffing and crafting

libtins.github.io

11–20 of 23 posts

Re: Libtins – High-level and multiplatform C++ network packet sniffing and crafting

#11
post #9
post #6

The linked page says "High level != inefficient" and shows an example program which will print "every TCP packet". With no "if" anywhere in the code, I wondered how it knew to print only TCP packets and not others. And the answer turns out to be that it throws a C++ exception on every non-TCP packet! If most of the packets on your network are TCP, this is sort of OK. But if you have mostly non-TCP packets, this toy p…

There are plenty of ways they can keep the current API while eventually approaching optimal, for example, a chain of exceptions could incrementally refine the framework's idea of what the callback function expects, which could be turned into a BPF filter. So for the cost of a few expensive frames at start, afterwards no exceptions get thrown. Generally speaking though, I'm only replying because I hate people negging…

I thought the criticism was quite valid.

If high efficiency wasn't touted as a feature then it would have been fine. But when it turns out that one of the main selling points is performance (with no expressed limitations or restrictions) and regular patterns perform badly, as a consequence of the design, then it is quite valid criticism. (Whether this is the case in practice I don't know but GP brings up a very valid point)

GPs point begs the question - Why was it designed in such as way? Quite possibly the tradeoffs were considered and the current solution was targeted because of several reasons. But the page doesn't convey any of that, it simply states that "In fact, it is one of the fastest packet sniffing and interpretation libraries available.".

While I agree with your point the library isn't exactly marketed as a lone wolf effort either, and that will also affect the criticism it will receive.

Re: Libtins – High-level and multiplatform C++ network packet sniffing and crafting

#12
post #9
post #6

The linked page says "High level != inefficient" and shows an example program which will print "every TCP packet". With no "if" anywhere in the code, I wondered how it knew to print only TCP packets and not others. And the answer turns out to be that it throws a C++ exception on every non-TCP packet! If most of the packets on your network are TCP, this is sort of OK. But if you have mostly non-TCP packets, this toy p…

There are plenty of ways they can keep the current API while eventually approaching optimal, for example, a chain of exceptions could incrementally refine the framework's idea of what the callback function expects, which could be turned into a BPF filter. So for the cost of a few expensive frames at start, afterwards no exceptions get thrown. Generally speaking though, I'm only replying because I hate people negging…

A more charitable reading of my comment would be that I am recommending the use of "if" instead of C++ exceptions for hot-path control flow in high-performance libraries.

Heuristic construction of a packet filter based on previously seen exceptions is infeasible with the current API because rejection of the first N non-TCP packets does not guarantee rejection of the next one.

Re: Libtins – High-level and multiplatform C++ network packet sniffing and crafting

#13
post #6

The linked page says "High level != inefficient" and shows an example program which will print "every TCP packet". With no "if" anywhere in the code, I wondered how it knew to print only TCP packets and not others. And the answer turns out to be that it throws a C++ exception on every non-TCP packet! If most of the packets on your network are TCP, this is sort of OK. But if you have mostly non-TCP packets, this toy p…

Note that in SnifferConfiguration you can set pcap-style filters.

Re: Libtins – High-level and multiplatform C++ network packet sniffing and crafting

#14
Since commenters are weighing in on packet construction libraries, what say you in re: libnet1.0/libnet1.1?

libnet-based modular utilities that can be used in shell scripts:

http://nemesis.sourceforge.net/docs.html

Also, earlier was nc-data. Slow but allows constructing any packet from the command line. Not limited to known packet formats.

http://nc110.sourceforge.net

Let us hear your criticisms.

Re: Libtins – High-level and multiplatform C++ network packet sniffing and crafting

#16
post #7
post #5

Also check out packit[1] a command line packet crafter. It is very easy to use once you really understand how to use it. Also it has no 'restrictions' on what packets can be crafted. It lets you get away with as much as possible. It should be readily available on most package managers, atleast debian based last time I checked. [1]: http://packetfactory.openwall.net/projects/packit/

The active version appears to be hosted here: https://github.com/eribertomota/packit

No, I thought so too initially. The person is just hosting the project looking for a maintainer(he is hosting other abandoned projects too). Debian project is also looking for someone to maintain the package.

Re: Libtins – High-level and multiplatform C++ network packet sniffing and crafting

#17
post #16
post #7

Earlier quoted context omitted.

The active version appears to be hosted here: https://github.com/eribertomota/packit

No, I thought so too initially. The person is just hosting the project looking for a maintainer(he is hosting other abandoned projects too). Debian project is also looking for someone to maintain the package.

Still, Debian packages the (updated) github version.

At least in Sid.

Re: Libtins – High-level and multiplatform C++ network packet sniffing and crafting

#18
post #12
post #9

Earlier quoted context omitted.

There are plenty of ways they can keep the current API while eventually approaching optimal, for example, a chain of exceptions could incrementally refine the framework's idea of what the callback function expects, which could be turned into a BPF filter. So for the cost of a few expensive frames at start, afterwards no exceptions get thrown. Generally speaking though, I'm only replying because I hate people negging…

A more charitable reading of my comment would be that I am recommending the use of "if" instead of C++ exceptions for hot-path control flow in high-performance libraries. Heuristic construction of a packet filter based on previously seen exceptions is infeasible with the current API because rejection of the first N non-TCP packets does not guarantee rejection of the next one.

There appears to be an alternative API that doesn't throw exceptions: https://github.com/mfontanini/libtins/blob/37c92fcf5c83b034a...

(rfind_pdu uses it internally: https://github.com/mfontanini/libtins/blob/37c92fcf5c83b034a...)

Re: Libtins – High-level and multiplatform C++ network packet sniffing and crafting

#19
Somewhat related: pcapy is a useful Python library for network packet handling. We used it recently in a project after evaluating it and a few others (not very thoroughly, though). dpkt is useful too.

pcapy can read from a live stream or from a packet capture file (.pcap format).

Re: Libtins – High-level and multiplatform C++ network packet sniffing and crafting

#20
post #19

Somewhat related: pcapy is a useful Python library for network packet handling. We used it recently in a project after evaluating it and a few others (not very thoroughly, though). dpkt is useful too. pcapy can read from a live stream or from a packet capture file (.pcap format).

I've found pyshark to be great too, especially for reading from a pcap. Scapy is great but has too many performance issues.
Post reply on HN