003 File Manager
Current Path:
/usr/src/contrib/libpcap
usr
/
src
/
contrib
/
libpcap
/
📁
..
📄
CHANGES
(41.04 KB)
📄
CMakeLists.txt
(84.97 KB)
📄
CONTRIBUTING.md
(1.41 KB)
📄
CREDITS
(11.47 KB)
📁
ChmodBPF
📄
INSTALL.md
(15.44 KB)
📄
LICENSE
(868 B)
📄
Makefile-devel-adds
(614 B)
📄
Makefile.in
(23.68 KB)
📄
README.md
(3.71 KB)
📄
TODO
(1.51 KB)
📄
VERSION
(6 B)
📁
Win32
📄
aclocal.m4
(30.92 KB)
📄
arcnet.h
(2.39 KB)
📄
atmuni31.h
(3.87 KB)
📄
bpf_dump.c
(1.9 KB)
📄
bpf_filter.c
(12.22 KB)
📄
bpf_image.c
(7.38 KB)
📄
chmod_bpf
(757 B)
📁
cmake
📄
cmake_uninstall.cmake.in
(1.01 KB)
📄
cmakeconfig.h.in
(11.15 KB)
📄
config.guess
(43.17 KB)
📄
config.h.in
(10.25 KB)
📄
config.sub
(34.93 KB)
📄
configure
(331.21 KB)
📄
configure.ac
(64.36 KB)
📄
diag-control.h
(8.3 KB)
📄
dlpisubs.c
(9.41 KB)
📄
dlpisubs.h
(702 B)
📁
doc
📄
etherent.c
(3.43 KB)
📄
ethertype.h
(3.47 KB)
📄
extract.h
(9.23 KB)
📄
fad-getad.c
(8.62 KB)
📄
fad-gifc.c
(12.84 KB)
📄
fad-glifc.c
(9.37 KB)
📄
fmtutils.c
(6.35 KB)
📄
fmtutils.h
(2.19 KB)
📄
ftmacros.h
(4.22 KB)
📄
gencode.c
(257 KB)
📄
gencode.h
(11.44 KB)
📄
grammar.y
(24.66 KB)
📄
ieee80211.h
(5.25 KB)
📄
install-sh
(5.45 KB)
📁
lbl
📄
libpcap.pc.in
(484 B)
📄
llc.h
(2.56 KB)
📁
missing
📄
mkdep
(2.43 KB)
📁
msdos
📄
nametoaddr.c
(18.83 KB)
📄
nametoaddr.h
(2.12 KB)
📄
nlpid.h
(1.66 KB)
📄
nomkdep
(135 B)
📄
optimize.c
(62.27 KB)
📄
optimize.h
(1.29 KB)
📄
org.tcpdump.chmod_bpf.plist
(441 B)
📁
pcap
📄
pcap-bpf.c
(84.02 KB)
📄
pcap-bpf.h
(2.24 KB)
📄
pcap-bt-linux.c
(11.42 KB)
📄
pcap-bt-linux.h
(1.76 KB)
📄
pcap-bt-monitor-linux.c
(7.84 KB)
📄
pcap-bt-monitor-linux.h
(1.64 KB)
📄
pcap-common.c
(47.14 KB)
📄
pcap-common.h
(2.29 KB)
📄
pcap-config.1
(2.27 KB)
📄
pcap-config.in
(1.8 KB)
📄
pcap-dag.c
(37.15 KB)
📄
pcap-dag.h
(457 B)
📄
pcap-dbus.c
(10.03 KB)
📄
pcap-dbus.h
(112 B)
📄
pcap-dll.rc
(1.03 KB)
📄
pcap-dlpi.c
(47.56 KB)
📄
pcap-dos.c
(35.9 KB)
📄
pcap-dos.h
(6.7 KB)
📄
pcap-enet.c
(4.74 KB)
📄
pcap-filter.manmisc.in
(33.54 KB)
📄
pcap-int.h
(16.94 KB)
📄
pcap-libdlpi.c
(12.11 KB)
📄
pcap-linktype.manmisc.in
(2.33 KB)
📄
pcap-linux.c
(207.89 KB)
📄
pcap-namedb.h
(1.98 KB)
📄
pcap-netfilter-linux.c
(20.48 KB)
📄
pcap-netfilter-linux.h
(1.67 KB)
📄
pcap-netmap.c
(7.82 KB)
📄
pcap-netmap.h
(126 B)
📄
pcap-new.c
(12.79 KB)
📄
pcap-nit.c
(10.2 KB)
📄
pcap-npf.c
(51.61 KB)
📄
pcap-null.c
(1.9 KB)
📄
pcap-pf.c
(18.48 KB)
📄
pcap-rdmasniff.c
(10.98 KB)
📄
pcap-rdmasniff.h
(140 B)
📄
pcap-rpcap-int.h
(3.43 KB)
📄
pcap-rpcap.c
(96.91 KB)
📄
pcap-rpcap.h
(2.19 KB)
📄
pcap-savefile.manfile.in
(5.11 KB)
📄
pcap-septel.c
(8.69 KB)
📄
pcap-septel.h
(512 B)
📄
pcap-sita.c
(36.34 KB)
📄
pcap-sita.h
(224 B)
📄
pcap-sita.html
(37.43 KB)
📄
pcap-snf.c
(14.75 KB)
📄
pcap-snf.h
(110 B)
📄
pcap-snit.c
(12.67 KB)
📄
pcap-snoop.c
(13.26 KB)
📄
pcap-tc.c
(34.21 KB)
📄
pcap-tc.h
(1.9 KB)
📄
pcap-tstamp.manmisc.in
(7.7 KB)
📄
pcap-types.h
(1.93 KB)
📄
pcap-usb-linux.c
(35.89 KB)
📄
pcap-usb-linux.h
(1.75 KB)
📄
pcap.3pcap.in
(29.62 KB)
📄
pcap.c
(103.69 KB)
📄
pcap.h
(2.17 KB)
📄
pcap_activate.3pcap
(3.8 KB)
📄
pcap_breakloop.3pcap
(3.98 KB)
📄
pcap_can_set_rfmon.3pcap
(2.63 KB)
📄
pcap_close.3pcap
(1.47 KB)
📄
pcap_compile.3pcap.in
(3.02 KB)
📄
pcap_create.3pcap
(2.19 KB)
📄
pcap_datalink.3pcap.in
(2.39 KB)
📄
pcap_datalink_name_to_val.3pcap
(1.82 KB)
📄
pcap_datalink_val_to_name.3pcap
(2.47 KB)
📄
pcap_dump.3pcap
(1.73 KB)
📄
pcap_dump_close.3pcap
(1.49 KB)
📄
pcap_dump_file.3pcap
(1.54 KB)
📄
pcap_dump_flush.3pcap
(1.69 KB)
📄
pcap_dump_ftell.3pcap
(2.11 KB)
📄
pcap_dump_open.3pcap.in
(3.31 KB)
📄
pcap_file.3pcap
(2.06 KB)
📄
pcap_fileno.3pcap
(2 KB)
📄
pcap_findalldevs.3pcap
(6.25 KB)
📄
pcap_freecode.3pcap
(1.67 KB)
📄
pcap_get_required_select_timeout.3pcap
(3.04 KB)
📄
pcap_get_selectable_fd.3pcap
(4.66 KB)
📄
pcap_get_tstamp_precision.3pcap.in
(1.83 KB)
📄
pcap_geterr.3pcap
(1.84 KB)
📄
pcap_inject.3pcap
(3.34 KB)
📄
pcap_is_swapped.3pcap
(1.91 KB)
📄
pcap_lib_version.3pcap
(1.6 KB)
📄
pcap_list_datalinks.3pcap.in
(2.54 KB)
📄
pcap_list_tstamp_types.3pcap.in
(2.98 KB)
📄
pcap_lookupdev.3pcap
(2.47 KB)
📄
pcap_lookupnet.3pcap
(1.95 KB)
📄
pcap_loop.3pcap
(6.58 KB)
📄
pcap_major_version.3pcap
(1.96 KB)
📄
pcap_next_ex.3pcap
(4.86 KB)
📄
pcap_offline_filter.3pcap
(1.95 KB)
📄
pcap_open_dead.3pcap.in
(2.65 KB)
📄
pcap_open_live.3pcap
(2.65 KB)
📄
pcap_open_offline.3pcap.in
(3.8 KB)
📄
pcap_set_buffer_size.3pcap
(1.79 KB)
📄
pcap_set_datalink.3pcap
(1.84 KB)
📄
pcap_set_immediate_mode.3pcap.in
(3.27 KB)
📄
pcap_set_promisc.3pcap
(1.82 KB)
📄
pcap_set_protocol_linux.3pcap
(2.81 KB)
📄
pcap_set_rfmon.3pcap
(1.82 KB)
📄
pcap_set_snaplen.3pcap
(1.74 KB)
📄
pcap_set_timeout.3pcap
(2.15 KB)
📄
pcap_set_tstamp_precision.3pcap.in
(2.38 KB)
📄
pcap_set_tstamp_type.3pcap.in
(2.73 KB)
📄
pcap_setdirection.3pcap
(2.36 KB)
📄
pcap_setfilter.3pcap
(1.79 KB)
📄
pcap_setnonblock.3pcap
(2.82 KB)
📄
pcap_snapshot.3pcap
(1.91 KB)
📄
pcap_stats.3pcap
(3.35 KB)
📄
pcap_statustostr.3pcap
(1.55 KB)
📄
pcap_strerror.3pcap
(1.54 KB)
📄
pcap_tstamp_type_name_to_val.3pcap
(1.87 KB)
📄
pcap_tstamp_type_val_to_name.3pcap
(1.99 KB)
📄
portability.h
(5.46 KB)
📄
ppp.h
(2.62 KB)
📄
rpcap-protocol.c
(6.67 KB)
📄
rpcap-protocol.h
(18.61 KB)
📁
rpcapd
📄
savefile.c
(13.72 KB)
📄
scanner.l
(14.36 KB)
📄
sf-pcap.c
(30.33 KB)
📄
sf-pcap.h
(1.69 KB)
📄
sf-pcapng.c
(38.9 KB)
📄
sf-pcapng.h
(1.41 KB)
📄
sockutils.c
(52.26 KB)
📄
sockutils.h
(5.22 KB)
📄
sunatmpos.h
(2.09 KB)
📁
testprogs
📁
tests
📄
varattrs.h
(2.38 KB)
Editing: dlpisubs.c
/* * This code is derived from code formerly in pcap-dlpi.c, originally * contributed by Atanu Ghosh (atanu@cs.ucl.ac.uk), University College * London, and subsequently modified by Guy Harris (guy@alum.mit.edu), * Mark Pizzolato <List-tcpdump-workers@subscriptions.pizzolato.net>, * Mark C. Brown (mbrown@hp.com), and Sagun Shakya <Sagun.Shakya@Sun.COM>. */ /* * This file contains dlpi/libdlpi related common functions used * by pcap-[dlpi,libdlpi].c. */ #ifdef HAVE_CONFIG_H #include <config.h> #endif #ifndef DL_IPATM #define DL_IPATM 0x12 /* ATM Classical IP interface */ #endif #ifdef HAVE_SYS_BUFMOD_H /* * Size of a bufmod chunk to pass upstream; that appears to be the * biggest value to which you can set it, and setting it to that value * (which is bigger than what appears to be the Solaris default of 8192) * reduces the number of packet drops. */ #define CHUNKSIZE 65536 /* * Size of the buffer to allocate for packet data we read; it must be * large enough to hold a chunk. */ #define PKTBUFSIZE CHUNKSIZE #else /* HAVE_SYS_BUFMOD_H */ /* * Size of the buffer to allocate for packet data we read; this is * what the value used to be - there's no particular reason why it * should be tied to MAXDLBUF, but we'll leave it as this for now. */ #define MAXDLBUF 8192 #define PKTBUFSIZE (MAXDLBUF * sizeof(bpf_u_int32)) #endif #include <sys/types.h> #include <sys/time.h> #ifdef HAVE_SYS_BUFMOD_H #include <sys/bufmod.h> #endif #include <sys/dlpi.h> #include <sys/stream.h> #include <errno.h> #include <memory.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stropts.h> #include <unistd.h> #ifdef HAVE_LIBDLPI #include <libdlpi.h> #endif #include "pcap-int.h" #include "dlpisubs.h" #ifdef HAVE_SYS_BUFMOD_H static void pcap_stream_err(const char *, int, char *); #endif /* * Get the packet statistics. */ int pcap_stats_dlpi(pcap_t *p, struct pcap_stat *ps) { struct pcap_dlpi *pd = p->priv; /* * "ps_recv" counts packets handed to the filter, not packets * that passed the filter. As filtering is done in userland, * this would not include packets dropped because we ran out * of buffer space; in order to make this more like other * platforms (Linux 2.4 and later, BSDs with BPF), where the * "packets received" count includes packets received but dropped * due to running out of buffer space, and to keep from confusing * applications that, for example, compute packet drop percentages, * we also make it count packets dropped by "bufmod" (otherwise we * might run the risk of the packet drop count being bigger than * the received-packet count). * * "ps_drop" counts packets dropped by "bufmod" because of * flow control requirements or resource exhaustion; it doesn't * count packets dropped by the interface driver, or packets * dropped upstream. As filtering is done in userland, it counts * packets regardless of whether they would've passed the filter. * * These statistics don't include packets not yet read from * the kernel by libpcap, but they may include packets not * yet read from libpcap by the application. */ *ps = pd->stat; /* * Add in the drop count, as per the above comment. */ ps->ps_recv += ps->ps_drop; return (0); } /* * Loop through the packets and call the callback for each packet. * Return the number of packets read. */ int pcap_process_pkts(pcap_t *p, pcap_handler callback, u_char *user, int count, u_char *bufp, int len) { struct pcap_dlpi *pd = p->priv; int n, caplen, origlen; u_char *ep, *pk; struct pcap_pkthdr pkthdr; #ifdef HAVE_SYS_BUFMOD_H struct sb_hdr *sbp; #ifdef LBL_ALIGN struct sb_hdr sbhdr; #endif #endif /* Loop through packets */ ep = bufp + len; n = 0; #ifdef HAVE_SYS_BUFMOD_H while (bufp < ep) { /* * Has "pcap_breakloop()" been called? * If so, return immediately - if we haven't read any * packets, clear the flag and return -2 to indicate * that we were told to break out of the loop, otherwise * leave the flag set, so that the *next* call will break * out of the loop without having read any packets, and * return the number of packets we've processed so far. */ if (p->break_loop) { if (n == 0) { p->break_loop = 0; return (-2); } else { p->bp = bufp; p->cc = ep - bufp; return (n); } } #ifdef LBL_ALIGN if ((long)bufp & 3) { sbp = &sbhdr; memcpy(sbp, bufp, sizeof(*sbp)); } else #endif sbp = (struct sb_hdr *)bufp; pd->stat.ps_drop = sbp->sbh_drops; pk = bufp + sizeof(*sbp); bufp += sbp->sbh_totlen; origlen = sbp->sbh_origlen; caplen = sbp->sbh_msglen; #else origlen = len; caplen = min(p->snapshot, len); pk = bufp; bufp += caplen; #endif ++pd->stat.ps_recv; if (bpf_filter(p->fcode.bf_insns, pk, origlen, caplen)) { #ifdef HAVE_SYS_BUFMOD_H pkthdr.ts.tv_sec = sbp->sbh_timestamp.tv_sec; pkthdr.ts.tv_usec = sbp->sbh_timestamp.tv_usec; #else (void) gettimeofday(&pkthdr.ts, NULL); #endif pkthdr.len = origlen; pkthdr.caplen = caplen; /* Insure caplen does not exceed snapshot */ if (pkthdr.caplen > (bpf_u_int32)p->snapshot) pkthdr.caplen = (bpf_u_int32)p->snapshot; (*callback)(user, &pkthdr, pk); if (++n >= count && !PACKET_COUNT_IS_UNLIMITED(count)) { p->cc = ep - bufp; p->bp = bufp; return (n); } } #ifdef HAVE_SYS_BUFMOD_H } #endif p->cc = 0; return (n); } /* * Process the mac type. Returns -1 if no matching mac type found, otherwise 0. */ int pcap_process_mactype(pcap_t *p, u_int mactype) { int retv = 0; switch (mactype) { case DL_CSMACD: case DL_ETHER: p->linktype = DLT_EN10MB; p->offset = 2; /* * This is (presumably) a real Ethernet capture; give it a * link-layer-type list with DLT_EN10MB and DLT_DOCSIS, so * that an application can let you choose it, in case you're * capturing DOCSIS traffic that a Cisco Cable Modem * Termination System is putting out onto an Ethernet (it * doesn't put an Ethernet header onto the wire, it puts raw * DOCSIS frames out on the wire inside the low-level * Ethernet framing). */ p->dlt_list = (u_int *)malloc(sizeof(u_int) * 2); /* * If that fails, just leave the list empty. */ if (p->dlt_list != NULL) { p->dlt_list[0] = DLT_EN10MB; p->dlt_list[1] = DLT_DOCSIS; p->dlt_count = 2; } break; case DL_FDDI: p->linktype = DLT_FDDI; p->offset = 3; break; case DL_TPR: /* XXX - what about DL_TPB? Is that Token Bus? */ p->linktype = DLT_IEEE802; p->offset = 2; break; #ifdef HAVE_SOLARIS case DL_IPATM: p->linktype = DLT_SUNATM; p->offset = 0; /* works for LANE and LLC encapsulation */ break; #endif #ifdef DL_IPV4 case DL_IPV4: p->linktype = DLT_IPV4; p->offset = 0; break; #endif #ifdef DL_IPV6 case DL_IPV6: p->linktype = DLT_IPV6; p->offset = 0; break; #endif #ifdef DL_IPNET case DL_IPNET: /* * XXX - DL_IPNET devices default to "raw IP" rather than * "IPNET header"; see * * http://seclists.org/tcpdump/2009/q1/202 * * We'd have to do DL_IOC_IPNET_INFO to enable getting * the IPNET header. */ p->linktype = DLT_RAW; p->offset = 0; break; #endif default: pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "unknown mactype 0x%x", mactype); retv = -1; } return (retv); } #ifdef HAVE_SYS_BUFMOD_H /* * Push and configure the buffer module. Returns -1 for error, otherwise 0. */ int pcap_conf_bufmod(pcap_t *p, int snaplen) { struct timeval to; bpf_u_int32 ss, chunksize; /* Non-standard call to get the data nicely buffered. */ if (ioctl(p->fd, I_PUSH, "bufmod") != 0) { pcap_stream_err("I_PUSH bufmod", errno, p->errbuf); return (-1); } ss = snaplen; if (ss > 0 && strioctl(p->fd, SBIOCSSNAP, sizeof(ss), (char *)&ss) != 0) { pcap_stream_err("SBIOCSSNAP", errno, p->errbuf); return (-1); } if (p->opt.immediate) { /* Set the timeout to zero, for immediate delivery. */ to.tv_sec = 0; to.tv_usec = 0; if (strioctl(p->fd, SBIOCSTIME, sizeof(to), (char *)&to) != 0) { pcap_stream_err("SBIOCSTIME", errno, p->errbuf); return (-1); } } else { /* Set up the bufmod timeout. */ if (p->opt.timeout != 0) { to.tv_sec = p->opt.timeout / 1000; to.tv_usec = (p->opt.timeout * 1000) % 1000000; if (strioctl(p->fd, SBIOCSTIME, sizeof(to), (char *)&to) != 0) { pcap_stream_err("SBIOCSTIME", errno, p->errbuf); return (-1); } } /* Set the chunk length. */ chunksize = CHUNKSIZE; if (strioctl(p->fd, SBIOCSCHUNK, sizeof(chunksize), (char *)&chunksize) != 0) { pcap_stream_err("SBIOCSCHUNKP", errno, p->errbuf); return (-1); } } return (0); } #endif /* HAVE_SYS_BUFMOD_H */ /* * Allocate data buffer. Returns -1 if memory allocation fails, else 0. */ int pcap_alloc_databuf(pcap_t *p) { p->bufsize = PKTBUFSIZE; p->buffer = malloc(p->bufsize + p->offset); if (p->buffer == NULL) { pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, errno, "malloc"); return (-1); } return (0); } /* * Issue a STREAMS I_STR ioctl. Returns -1 on error, otherwise * length of returned data on success. */ int strioctl(int fd, int cmd, int len, char *dp) { struct strioctl str; int retv; str.ic_cmd = cmd; str.ic_timout = -1; str.ic_len = len; str.ic_dp = dp; if ((retv = ioctl(fd, I_STR, &str)) < 0) return (retv); return (str.ic_len); } #ifdef HAVE_SYS_BUFMOD_H /* * Write stream error message to errbuf. */ static void pcap_stream_err(const char *func, int err, char *errbuf) { pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, err, "%s", func); } #endif
Upload File
Create Folder