Amir
Amir

Reputation: 6186

Perl counting number of packets in a connection

I want to write a perl script in which I download an object from a webserver and count the number of packets till the whole object is downloaded. I was thinking to use raw sockets in perl. Another alternative would be to use libpcap in perl, yet that requires root access (i believe) that I want to avoid.

Is there an easier way to do that?

Thanks,

Upvotes: 0

Views: 145

Answers (1)

Celada
Celada

Reputation: 22261

Raw sockets and libpcap will both require root access (or CAP_NET_ADMIN), so neither has the advantage there.

In fact the raw sockets approach might be slightly cleaner than the libpcap approach, but it requires you to write your own TCP stack from scratch. Since you almost certainly don't want to do that, I would recommend the libpcap approach.

Another approach might be to use iptables to count packets, but it's not portable (requires Linux) and it still doesn't remove the root access requirement.

Upvotes: 1

Related Questions