PCAP_INJECT(3PCAP)

πŸ“¦
version 1.10.7 Β· 3 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, centos-stream 10, debian bookworm, debian trixie, fedora 43, fedora 44, nixos 26.05, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

hii bestie πŸ’– welcome to the PCAP_INJECT(3PCAP) manual page β€” yes, the one about pcap_inject and pcap_sendpacket, aka the β€œtransmit a packet” duo. this is your group-chat cheat sheet, and we are keeping every single technical crumb. no cap. ✨

πŸ’– NAME πŸ’–

pcap_inject, pcap_sendpacket β€” transmit a packet. that’s the whole assignment, and they ate. πŸ’…

✨ SYNOPSIS ✨

#include <pcap/pcap.h>

int pcap_inject(pcap_t *p, const void *buf, size_t size);
int pcap_sendpacket(pcap_t *p, const u_char *buf, int size);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so pcap_inject() sends a raw packet through the network interface. buf points to the data of the packet, including the link-layer header, and size is the number of bytes in the packet. iconic behavior. 🫢

🚨 heads up, bestie: even if you successfully open the network interface, you might not have permission to send packets on it, or it might not support sending packets. because pcap_open_live(3PCAP) doesn’t have a flag to indicate whether to open for capturing, sending, or capturing and sending, you cannot request an open that supports sending and be notified at open time whether sending will be possible. also note that some devices might not support sending packets. πŸ™ˆ

platform tea time: on some platforms, the link-layer header of the packet that’s sent might not be the same as the link-layer header of the packet supplied to pcap_inject(). why? because the source link-layer address, if the header contains such an address, might be changed to be the address assigned to the interface on which the packet it sent, if the platform doesn’t support sending completely raw and unchanged packets. 😭 and even worse: some drivers on some platforms might change the link-layer type field to whatever value libpcap used when attaching to the device, even on platforms that do nominally support sending completely raw and unchanged packets. πŸ’€

pcap_sendpacket() is like pcap_inject(), but it returns 0 on success, rather than returning the number of bytes written. periodt. (pcap_inject() comes from OpenBSD; pcap_sendpacket() comes from WinPcap/Npcap. Both are provided for compatibility.) 🌈

πŸŽ€ RETURN VALUE πŸŽ€

  • pcap_inject() returns the number of bytes written on success, PCAP_ERROR_NOT_ACTIVATED if called on a capture handle that has been created but not activated, and PCAP_ERROR on other errors. ✨
  • pcap_sendpacket() returns 0 on success, PCAP_ERROR_NOT_ACTIVATED if called on a capture handle that has been created but not activated, and PCAP_ERROR on other errors. πŸ’–

if PCAP_ERROR is returned, pcap_geterr(3PCAP) or pcap_perror(3PCAP) may be called with p as an argument to fetch or display the error text. 🫢

πŸ”₯ SEE ALSO πŸ”₯

  • pcap(3PCAP) πŸ‘‘

mwah πŸ’‹ this little masterpiece is from the PCAP_INJECT(3PCAP) source/version, dated 5 March 2022 β€” bye bestie, go send packets responsibly πŸŽ€πŸ’…

πŸ“¦ where this page comes from