Blame pcap_inject.3pcap

Packit 209cc3
.\" Copyright (c) 1994, 1996, 1997
Packit 209cc3
.\"	The Regents of the University of California.  All rights reserved.
Packit 209cc3
.\"
Packit 209cc3
.\" Redistribution and use in source and binary forms, with or without
Packit 209cc3
.\" modification, are permitted provided that: (1) source code distributions
Packit 209cc3
.\" retain the above copyright notice and this paragraph in its entirety, (2)
Packit 209cc3
.\" distributions including binary code include the above copyright notice and
Packit 209cc3
.\" this paragraph in its entirety in the documentation or other materials
Packit 209cc3
.\" provided with the distribution, and (3) all advertising materials mentioning
Packit 209cc3
.\" features or use of this software display the following acknowledgement:
Packit 209cc3
.\" ``This product includes software developed by the University of California,
Packit 209cc3
.\" Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
Packit 209cc3
.\" the University nor the names of its contributors may be used to endorse
Packit 209cc3
.\" or promote products derived from this software without specific prior
Packit 209cc3
.\" written permission.
Packit 209cc3
.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
Packit 209cc3
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
Packit 209cc3
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Packit 209cc3
.\"
Packit 209cc3
.TH PCAP_INJECT 3PCAP "25 July 2018"
Packit 209cc3
.SH NAME
Packit 209cc3
pcap_inject, pcap_sendpacket \- transmit a packet
Packit 209cc3
.SH SYNOPSIS
Packit 209cc3
.nf
Packit 209cc3
.ft B
Packit 209cc3
#include <pcap/pcap.h>
Packit 209cc3
.ft
Packit 209cc3
.LP
Packit 209cc3
.ft B
Packit 209cc3
int pcap_inject(pcap_t *p, const void *buf, size_t size);
Packit 209cc3
int pcap_sendpacket(pcap_t *p, const u_char *buf, int size);
Packit 209cc3
.ft
Packit 209cc3
.fi
Packit 209cc3
.SH DESCRIPTION
Packit 209cc3
.B pcap_inject()
Packit 209cc3
sends a raw packet through the network interface;
Packit 209cc3
.I buf
Packit 209cc3
points to the data of the packet, including the link-layer header, and
Packit 209cc3
.I size
Packit 209cc3
is the number of bytes in the packet.
Packit 209cc3
.PP
Packit 209cc3
Note that, even if you successfully open the network interface, you
Packit 209cc3
might not have permission to send packets on it, or it might not support
Packit 209cc3
sending packets; as
Packit 209cc3
.B pcap_open_live(3PCAP)
Packit 209cc3
doesn't have a flag to indicate whether to open for capturing, sending,
Packit 209cc3
or capturing and sending, you cannot request an open that supports
Packit 209cc3
sending and be notified at open time whether sending will be possible.
Packit 209cc3
Note also that some devices might not support sending packets.
Packit 209cc3
.PP
Packit 209cc3
Note that, on some platforms, the link-layer header of the packet that's
Packit 209cc3
sent might not be the same as the link-layer header of the packet
Packit 209cc3
supplied to
Packit 209cc3
.BR pcap_inject() ,
Packit 209cc3
as the source link-layer address, if the header contains such an
Packit 209cc3
address, might be changed to be the address assigned to the interface on
Packit 209cc3
which the packet it sent, if the platform doesn't support sending
Packit 209cc3
completely raw and unchanged packets.  Even worse, some drivers on some
Packit 209cc3
platforms might change the link-layer type field to whatever value
Packit 209cc3
libpcap used when attaching to the device, even on platforms that
Packit 209cc3
.I do
Packit 209cc3
nominally support sending completely raw and unchanged packets.
Packit 209cc3
.PP
Packit 209cc3
.B pcap_sendpacket()
Packit 209cc3
is like
Packit 209cc3
.BR pcap_inject() ,
Packit 209cc3
but it returns 0 on success, rather than returning the number of bytes
Packit 209cc3
written.
Packit 209cc3
.RB ( pcap_inject()
Packit 209cc3
comes from OpenBSD;
Packit 209cc3
.B pcap_sendpacket()
Packit 209cc3
comes from WinPcap.  Both are provided for compatibility.)
Packit 209cc3
.SH RETURN VALUE
Packit 209cc3
.B pcap_inject()
Packit 209cc3
returns the number of bytes written on success and
Packit 209cc3
.B PCAP_ERROR
Packit 209cc3
on failure.
Packit 209cc3
.PP
Packit 209cc3
.B pcap_sendpacket()
Packit 209cc3
returns 0 on success and
Packit 209cc3
.B PCAP_ERROR
Packit 209cc3
on failure.
Packit 209cc3
.PP
Packit 209cc3
If
Packit 209cc3
.B PCAP_ERROR
Packit 209cc3
is returned,
Packit 209cc3
.B pcap_geterr(3PCAP)
Packit 209cc3
or
Packit 209cc3
.B pcap_perror(3PCAP)
Packit 209cc3
may be called with
Packit 209cc3
.I p
Packit 209cc3
as an argument to fetch or display the error text.
Packit 209cc3
.SH SEE ALSO
Packit 209cc3
pcap(3PCAP)