tcpdump mailing list archives

Re: pcap_send_packet vs. pcap_inject functions


From: Guy Harris <guy () alum mit edu>
Date: Mon, 20 Aug 2007 10:26:35 -0700

Mark Bednarczyk wrote:
Can someone explain to me the difference between these  two calls,
pcap_sendpacket vs. pcap_inject, introducted in 0.8.3?

The difference is that pcap_sendpacket() returns 0 on success and pcap_inject() returns the number of bytes written on success.

From what I could tell one is used on linux and came from winpcap API and
the other on bsd systems?

No.

One was originally implemented in WinPcap, for use on *Windows*; the "Win" in "WinPcap" stands for "Windows".

One was originally implemented in OpenBSD.

*Neither* was originally implemented on Linux. *Both* should work on Linux - and on OpenBSD, and on Windows, and on FreeBSD, and on NetBSD, and on DragonFly BSD, and on Solaris, and on.... The two APIs both call the same underlying routine to transmit the packet. pcap_inject() returns the return value of the underlying routine; pcap_sendpacket() checks the return value and, if it's -1, returns -1, otherwise returns 0. A programmer can use whichever of them they want, on whichever OS they want, as long as sending packets is supported on that OS.

They are both implemented exactly the same way and
accomplish same thing and take the same parameters. So I'm a little confused
what is the purpose of having 2 calls?

The purpose is to have the newer version of libpcap able to support both

programs originally written for WinPcap, using pcap_sendpacket() (just in case they check for success by testing the return value against 0, rather than checking for failure by testing the return value against -1)

and

programs originally written for OpenBSD's libpcap, using pcap_inject() (just in case they actually care, for some unknown reason, how many packets were actually written; in practice, if the write succeeds, it presumably writes all the bytes of the packet).
-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.


Current thread: