1PCAP_INJECT(3PCAP) PCAP_INJECT(3PCAP)
2
3
4
6 pcap_inject, pcap_sendpacket - transmit a packet
7
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
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
25 devices 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
36 unchanged 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
44 pcap_inject() returns the number of bytes written on success and
45 PCAP_ERROR on failure.
46
47 pcap_sendpacket() returns 0 on success and PCAP_ERROR on failure.
48
49 If PCAP_ERROR is returned, pcap_geterr(3PCAP) or pcap_perror(3PCAP) may
50 be called with p as an argument to fetch or display the error text.
51
53 pcap(3PCAP)
54
55
56
57 25 July 2018 PCAP_INJECT(3PCAP)