1PCAP_INJECT(3PCAP)                                          PCAP_INJECT(3PCAP)
2
3
4

NAME

6       pcap_inject, pcap_sendpacket - transmit a packet
7

SYNOPSIS

9       #include <pcap/pcap.h>
10
11       int pcap_inject(pcap_t *p, const void *buf, size_t size);
12       int pcap_sendpacket(pcap_t *p, const u_char *buf, int size);
13

DESCRIPTION

15       pcap_inject()  sends  a  raw  packet through the network interface; buf
16       points to the data of the packet, including the link-layer header,  and
17       size is the number of bytes in the packet.
18
19       Note  that,  even  if  you successfully open the network interface, you
20       might not have permission to send packets on it, or it might  not  sup‐
21       port  sending  packets; as pcap_open_live(3PCAP) doesn't have a flag to
22       indicate whether to open for capturing, sending, or capturing and send‐
23       ing,  you  cannot request an open that supports sending and be notified
24       at open time whether sending will be possible.  Note also that some de‐
25       vices might not support sending packets.
26
27       Note  that,  on  some  platforms,  the  link-layer header of the packet
28       that's sent might not be the same  as  the  link-layer  header  of  the
29       packet  supplied to pcap_inject(), as the source link-layer address, if
30       the header contains such an address, might be changed to be the address
31       assigned  to the interface on which the packet it sent, if the platform
32       doesn't support sending completely raw  and  unchanged  packets.   Even
33       worse,  some drivers on some platforms might change the link-layer type
34       field to whatever value libpcap used when attaching to the device, even
35       on  platforms  that do nominally support sending completely raw and un‐
36       changed packets.
37
38       pcap_sendpacket() is like pcap_inject(), but it returns 0  on  success,
39       rather  than  returning  the  number  of bytes written.  (pcap_inject()
40       comes from OpenBSD; pcap_sendpacket() comes from  WinPcap/Npcap.   Both
41       are provided for compatibility.)
42

RETURN VALUE

44       pcap_inject()  returns the number of bytes written on success, PCAP_ER‐
45       ROR_NOT_ACTIVATED if called on a capture handle that has  been  created
46       but not activated, and PCAP_ERROR on other errors.
47
48       pcap_sendpacket()  returns  0  on  success, PCAP_ERROR_NOT_ACTIVATED if
49       called on a capture handle that has been created but not activated, and
50       PCAP_ERROR on other errors.
51
52       If PCAP_ERROR is returned, pcap_geterr(3PCAP) or pcap_perror(3PCAP) may
53       be called with p as an argument to fetch or display the error text.
54

SEE ALSO

56       pcap(3PCAP)
57
58
59
60                                 5 March 2022               PCAP_INJECT(3PCAP)
Impressum