Copyright © 2014 CORE SECURITY TECHNOLOGIES
Revision History | ||
---|---|---|
Revision: 1.2 | Date: 2003/10/23 | Author: jkohen |
Initial revision |
Table of Contents
Table of Contents
open_liveis used to obtain a packet capture descriptor to look at packets on the network. deviceis a string that specifies the network device to open; on Linux systems with 2.2 or later kernels, a device argument of anyor NULLcan be used to capture packets from all interfaces. snaplen specifies the maximum number of bytes to capture. promiscspecifies if the interface is to be put into promiscuous mode. (Note that even if this parameter is false, the interface could well be in promiscuous mode for some other reason.) For now, this doesn't work on the anydevice; if an argument of anyor NULLis supplied, the promiscflag is ignored. to_msspecifies the read timeout in milliseconds. The read timeout is used to arrange that the read not necessarily return immediately when a packet is seen, but that it wait for some amount of time to allow more packets to arrive and to read multiple packets from the OS kernel in one operation. Not all platforms support a read timeout; on platforms that don't, the read timeout is ignored.
findalldevsconstructs a list of network devices that can be opened with open_live. (Note that there may be network devices that cannot be opened with open_live, because, for example, that process might not have sufficient privileges to open them for capturing; if so, those devices will not appear on the list.)
dispatchis used to collect and process packets. maxcantspecifies the maximum number of packets to process before returning. This is not a minimum number; when reading a live capture, only one bufferful of packets is read at a time, so fewer than maxcantpackets may be processed. A cntof -1 processes all the packets received in one buffer when reading a live capture, or all the packets in the file when reading a savefile. callback specifies a routine to be called with two arguments: a Pkthdrinstance describing the data passed and the data itself.
The number of packets read is returned. 0 is returned if no packets were read from a live capture (if, for example, they were discarded because they didn't pass the packet filter, or if, on platforms that support a read timeout that starts before any packets arrive, the timeout expires before any packets arrive, or if the file descriptor for the capture device is in non–blocking mode and no packets were available to be read) or if no more packets are available in a savefile.
When reading a live capture, dispatch will not necessarily return when the read times out; on some platforms, the read timeout isn't supported, and, on other platforms, the timer doesn't start until at least one packet arrives. This means that the read timeout should not be used in, for example, an interactive application, to allow the packet capture loop to poll for user input periodically, as there's no guarantee that dispatchwill return after the timeout expires.
loopis similar to dispatchexcept it keeps reading packets until maxcantpackets are processed or an error occurs. It does not return when live read timeouts occur. Rather, specifying a non–zero read timeout to open_liveand then calling dispatchallows the reception and processing of any packets that arrive when the timeout occurs. A negative maxcantcauses loopto loop forever (or at least until an error occurs). 0 is returned if maxcantis exhausted.
datalinkreturns the link layer type; link layer types it can return include:
BSD loopback encapsulation; the link layer header is a 4–byte field, in host byte order, containing a PF_ value from socket.hfor the network–layer protocol of the packet.
“host byte order” is the byte order of the machine on which the packets are captured, and the PF_values are for the OS of the machine on which the packets are captured; if a live capture is being done, “host byte order” is the byte order of the machine capturing the packets, and the PF_values are those of the OS of the machine capturing the packets, but if a savefile is being read, the byte order and PF_ values are not necessarily those of the machine reading the capture file.
Ethernet (10Mb, 100Mb, 1000Mb, and up)
IEEE 802.5 Token Ring
ARCNET
SLIP; the link layer header contains, in order:
a 1–byte flag, which is 0for packets received by the machine and 1for packets sent by the machine.
a 1–byte field, the upper 4 bits of which indicate the type of packet, as per RFC 1144:
0x40; an unmodified IP datagram (TYPE_IP)
0x70; an uncompressed–TCP/IP datagram (UNCOMPRESSED_TCP), with that byte being the first byte of the raw IP header on the wire, containing the connection number in the protocol field
0x80; a compressed–TCP/IP datagram (COMPRESSED_TCP), with that byte being the first byte of the compressed TCP/IP datagram header
for UNCOMPRESSED_TCP, the rest of the modified IP header, and for COMPRESSED_TCP, the compressed TCP/IP datagram header
PPP; if the first 2 bytes are 0xffand 0x03, it's PPP in HDLC–like framing, with the PPP header following those two bytes, otherwise it's PPP without framing, and the packet begins with the PPP header.
FDDI
RFC 1483 LLC/SNAP–encapsulated ATM; the packet begins with an IEEE 802.2 LLC header.
Raw IP; the packet begins with an IP header.
PPP in HDLC–like framing, as per RFC 1662, or Cisco PPP with HDLC framing, as per section §4.3.1 of RFC 1547; the first byte will be 0xFFfor PPP in HDLC–like framing, and will be 0x0For 0x8Ffor Cisco PPP with HDLC framing.
PPPoE; the packet begins with a PPPoE header, as per RFC 2516.
Cisco PPP with HDLC framing, as per section § 4.3.1 of RFC 1547.
IEEE 802.11 wireless LAN.
OpenBSD loopback encapsulation; the link layer header is a 4–byte field, in network byte order, containing a PF_value from OpenBSD's socket.hfor the network–layer protocol of the packet.
Linux cooked capture encapsulation; the link layer header contains, in order:
a 2–byte "packet type", in network byte order, which is one of:
a 2–byte field, in network byte order, containing a Linux ARPHRD_value for the link layer device type.
a 2–byte field, in network byte order, containing the length of the link layer address of the sender of the packet (which could be 0).
an 8–byte field containing that number of bytes of the link layer header (if there are more than 8 bytes, only the first 8 are present).
a 2–byte field containing an Ethernet protocol type, in network byte order, or containing 1for Novell 802.3 frames without an 802.2 LLC header or 4for frames beginning with an 802.2 LLC header.
Apple LocalTalk; the packet begins with an AppleTalk LLAP header.
getnonblockreturns the current non–blocking state of the capture descriptor; it always returns 0 on savefiles.
setnonblockputs a capture descriptor, opened with open_live, into non–blocking mode, or takes it out of non–blocking mode, depending on whether the stateargument is non–zero or zero. It has no effect on savefiles. In non–blocking mode, an attempt to read from the capture descriptor with dispatchwill, if no packets are currently available to be read, return 0 immediately rather than blocking waiting for packets to arrive. loopand nextwill not work in non–blocking mode.
Table of Contents
Table of Contents
getts, getcaplen and getlenreturn the timestamp, capture length and total length fields of the packet header, respectively.
Timestamp is a tuple with two elements: the number of seconds since the Epoch, and the amount of microseconds past the current second. The capture length is the number of bytes of the packet that are available from the capture. Finally, total length gives the length of the packet, in bytes (which might be more than the number of bytes available from the capture, if the length of the packet is larger than the maximum number of bytes to capture).
Table of Contents