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: pcap-snf.c
#ifdef HAVE_CONFIG_H #include <config.h> #endif #ifndef _WIN32 #include <sys/param.h> #endif /* !_WIN32 */ #include <stdlib.h> #include <string.h> #include <errno.h> #include <ctype.h> #ifndef _WIN32 #include <netinet/in.h> #include <sys/mman.h> #include <sys/socket.h> #include <sys/types.h> #include <unistd.h> #endif /* !_WIN32 */ #include <snf.h> #if SNF_VERSION_API >= 0x0003 #define SNF_HAVE_INJECT_API #endif #include "pcap-int.h" #include "pcap-snf.h" /* * Private data for capturing on SNF devices. */ struct pcap_snf { snf_handle_t snf_handle; /* opaque device handle */ snf_ring_t snf_ring; /* opaque device ring handle */ #ifdef SNF_HAVE_INJECT_API snf_inject_t snf_inj; /* inject handle, if inject is used */ #endif int snf_timeout; int snf_boardnum; }; static int snf_set_datalink(pcap_t *p, int dlt) { p->linktype = dlt; return (0); } static int snf_pcap_stats(pcap_t *p, struct pcap_stat *ps) { struct snf_ring_stats stats; struct pcap_snf *snfps = p->priv; int rc; if ((rc = snf_ring_getstats(snfps->snf_ring, &stats))) { pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, rc, "snf_get_stats"); return -1; } ps->ps_recv = stats.ring_pkt_recv + stats.ring_pkt_overflow; ps->ps_drop = stats.ring_pkt_overflow; ps->ps_ifdrop = stats.nic_pkt_overflow + stats.nic_pkt_bad; return 0; } static void snf_platform_cleanup(pcap_t *p) { struct pcap_snf *ps = p->priv; #ifdef SNF_HAVE_INJECT_API if (ps->snf_inj) snf_inject_close(ps->snf_inj); #endif snf_ring_close(ps->snf_ring); snf_close(ps->snf_handle); pcap_cleanup_live_common(p); } static int snf_getnonblock(pcap_t *p) { struct pcap_snf *ps = p->priv; return (ps->snf_timeout == 0); } static int snf_setnonblock(pcap_t *p, int nonblock) { struct pcap_snf *ps = p->priv; if (nonblock) ps->snf_timeout = 0; else { if (p->opt.timeout <= 0) ps->snf_timeout = -1; /* forever */ else ps->snf_timeout = p->opt.timeout; } return (0); } #define _NSEC_PER_SEC 1000000000 static inline struct timeval snf_timestamp_to_timeval(const int64_t ts_nanosec, const int tstamp_precision) { struct timeval tv; long tv_nsec; const static struct timeval zero_timeval; if (ts_nanosec == 0) return zero_timeval; tv.tv_sec = ts_nanosec / _NSEC_PER_SEC; tv_nsec = (ts_nanosec % _NSEC_PER_SEC); /* libpcap expects tv_usec to be nanos if using nanosecond precision. */ if (tstamp_precision == PCAP_TSTAMP_PRECISION_NANO) tv.tv_usec = tv_nsec; else tv.tv_usec = tv_nsec / 1000; return tv; } static int snf_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user) { struct pcap_snf *ps = p->priv; struct pcap_pkthdr hdr; int i, flags, err, caplen, n; struct snf_recv_req req; int nonblock, timeout; if (!p) return -1; n = 0; timeout = ps->snf_timeout; while (n < cnt || PACKET_COUNT_IS_UNLIMITED(cnt)) { /* * Has "pcap_breakloop()" been called? */ if (p->break_loop) { if (n == 0) { p->break_loop = 0; return (-2); } else { return (n); } } err = snf_ring_recv(ps->snf_ring, timeout, &req); if (err) { if (err == EBUSY || err == EAGAIN) { return (n); } else if (err == EINTR) { timeout = 0; continue; } else { pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, err, "snf_read"); return -1; } } caplen = req.length; if (caplen > p->snapshot) caplen = p->snapshot; if ((p->fcode.bf_insns == NULL) || bpf_filter(p->fcode.bf_insns, req.pkt_addr, req.length, caplen)) { hdr.ts = snf_timestamp_to_timeval(req.timestamp, p->opt.tstamp_precision); hdr.caplen = caplen; hdr.len = req.length; callback(user, &hdr, req.pkt_addr); n++; } /* After one successful packet is received, we won't block * again for that timeout. */ if (timeout != 0) timeout = 0; } return (n); } static int snf_setfilter(pcap_t *p, struct bpf_program *fp) { if (!p) return -1; if (!fp) { strncpy(p->errbuf, "setfilter: No filter specified", sizeof(p->errbuf)); return -1; } /* Make our private copy of the filter */ if (install_bpf_program(p, fp) < 0) return -1; return (0); } static int snf_inject(pcap_t *p, const void *buf _U_, size_t size _U_) { #ifdef SNF_HAVE_INJECT_API struct pcap_snf *ps = p->priv; int rc; if (ps->snf_inj == NULL) { rc = snf_inject_open(ps->snf_boardnum, 0, &ps->snf_inj); if (rc) { pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, rc, "snf_inject_open"); return (-1); } } rc = snf_inject_send(ps->snf_inj, -1, 0, buf, size); if (!rc) { return (size); } else { pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, rc, "snf_inject_send"); return (-1); } #else pcap_strlcpy(p->errbuf, "Sending packets isn't supported with this snf version", PCAP_ERRBUF_SIZE); return (-1); #endif } static int snf_activate(pcap_t* p) { struct pcap_snf *ps = p->priv; char *device = p->opt.device; const char *nr = NULL; int err; int flags = -1, ring_id = -1; if (device == NULL) { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "device is NULL"); return -1; } /* In Libpcap, we set pshared by default if NUM_RINGS is set to > 1. * Since libpcap isn't thread-safe */ if ((nr = getenv("SNF_FLAGS")) && *nr) flags = strtol(nr, NULL, 0); else if ((nr = getenv("SNF_NUM_RINGS")) && *nr && atoi(nr) > 1) flags = SNF_F_PSHARED; else nr = NULL; /* Allow pcap_set_buffer_size() to set dataring_size. * Default is zero which allows setting from env SNF_DATARING_SIZE. * pcap_set_buffer_size() is in bytes while snf_open() accepts values * between 0 and 1048576 in Megabytes. Values in this range are * mapped to 1MB. */ err = snf_open(ps->snf_boardnum, 0, /* let SNF API parse SNF_NUM_RINGS, if set */ NULL, /* default RSS, or use SNF_RSS_FLAGS env */ (p->opt.buffer_size > 0 && p->opt.buffer_size < 1048576) ? 1048576 : p->opt.buffer_size, /* default to SNF_DATARING_SIZE from env */ flags, /* may want pshared */ &ps->snf_handle); if (err != 0) { pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, err, "snf_open failed"); return -1; } if ((nr = getenv("SNF_PCAP_RING_ID")) && *nr) { ring_id = (int) strtol(nr, NULL, 0); } err = snf_ring_open_id(ps->snf_handle, ring_id, &ps->snf_ring); if (err != 0) { pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, err, "snf_ring_open_id(ring=%d) failed", ring_id); return -1; } /* * Turn a negative snapshot value (invalid), a snapshot value of * 0 (unspecified), or a value bigger than the normal maximum * value, into the maximum allowed value. * * If some application really *needs* a bigger snapshot * length, we should just increase MAXIMUM_SNAPLEN. */ if (p->snapshot <= 0 || p->snapshot > MAXIMUM_SNAPLEN) p->snapshot = MAXIMUM_SNAPLEN; if (p->opt.timeout <= 0) ps->snf_timeout = -1; else ps->snf_timeout = p->opt.timeout; err = snf_start(ps->snf_handle); if (err != 0) { pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, err, "snf_start failed"); return -1; } /* * "select()" and "poll()" don't work on snf descriptors. */ #ifndef _WIN32 p->selectable_fd = -1; #endif /* !_WIN32 */ p->linktype = DLT_EN10MB; p->read_op = snf_read; p->inject_op = snf_inject; p->setfilter_op = snf_setfilter; p->setdirection_op = NULL; /* Not implemented.*/ p->set_datalink_op = snf_set_datalink; p->getnonblock_op = snf_getnonblock; p->setnonblock_op = snf_setnonblock; p->stats_op = snf_pcap_stats; p->cleanup_op = snf_platform_cleanup; #ifdef SNF_HAVE_INJECT_API ps->snf_inj = NULL; #endif return 0; } #define MAX_DESC_LENGTH 128 int snf_findalldevs(pcap_if_list_t *devlistp, char *errbuf) { pcap_if_t *dev; #ifdef _WIN32 struct sockaddr_in addr; #endif struct snf_ifaddrs *ifaddrs, *ifa; char name[MAX_DESC_LENGTH]; char desc[MAX_DESC_LENGTH]; int ret, allports = 0, merge = 0; const char *nr = NULL; if (snf_init(SNF_VERSION_API)) { (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "snf_getifaddrs: snf_init failed"); return (-1); } if (snf_getifaddrs(&ifaddrs) || ifaddrs == NULL) { pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, errno, "snf_getifaddrs"); return (-1); } if ((nr = getenv("SNF_FLAGS")) && *nr) { errno = 0; merge = strtol(nr, NULL, 0); if (errno) { (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "snf_getifaddrs: SNF_FLAGS is not a valid number"); return (-1); } merge = merge & SNF_F_AGGREGATE_PORTMASK; } for (ifa = ifaddrs; ifa != NULL; ifa = ifa->snf_ifa_next) { /* * Myricom SNF adapter ports may appear as regular * network interfaces, which would already have been * added to the list of adapters by pcap_platform_finddevs() * if this isn't an SNF-only version of libpcap. * * Our create routine intercepts pcap_create() calls for * those interfaces and arranges that they will be * opened using the SNF API instead. * * So if we already have an entry for the device, we * don't add an additional entry for it, we just * update the description for it, if any, to indicate * which snfN device it is. Otherwise, we add an entry * for it. * * In either case, if SNF_F_AGGREGATE_PORTMASK is set * in SNF_FLAGS, we add this port to the bitmask * of ports, which we use to generate a device * we can use to capture on all ports. * * Generate the description string. If port aggregation * is set, use 2^{port number} as the unit number, * rather than {port number}. * * XXX - do entries in this list have IP addresses for * the port? If so, should we add them to the * entry for the device, if they're not already in the * list of IP addresses for the device? */ (void)pcap_snprintf(desc,MAX_DESC_LENGTH,"Myricom %ssnf%d", merge ? "Merge Bitmask Port " : "", merge ? 1 << ifa->snf_ifa_portnum : ifa->snf_ifa_portnum); /* * Add the port to the bitmask. */ if (merge) allports |= 1 << ifa->snf_ifa_portnum; /* * See if there's already an entry for the device * with the name ifa->snf_ifa_name. */ dev = find_dev(devlistp, ifa->snf_ifa_name); if (dev != NULL) { /* * Yes. Update its description. */ char *desc_str; desc_str = strdup(desc); if (desc_str == NULL) { pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, errno, "snf_findalldevs strdup"); return -1; } free(dev->description); dev->description = desc_str; } else { /* * No. Add an entry for it. * * XXX - is there a notion of "up" or "running", * and can we determine whether something's * plugged into the adapter and set * PCAP_IF_CONNECTION_STATUS_CONNECTED or * PCAP_IF_CONNECTION_STATUS_DISCONNECTED? */ dev = add_dev(devlistp, ifa->snf_ifa_name, 0, desc, errbuf); if (dev == NULL) return -1; #ifdef _WIN32 /* * On Windows, fill in IP# from device name */ ret = inet_pton(AF_INET, dev->name, &addr.sin_addr); if (ret == 1) { /* * Successful conversion of device name * to IPv4 address. */ addr.sin_family = AF_INET; if (add_addr_to_dev(dev, &addr, sizeof(addr), NULL, 0, NULL, 0, NULL, 0, errbuf) == -1) return -1; } else if (ret == -1) { /* * Error. */ pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, errno, "sinf_findalldevs inet_pton"); return -1; } #endif _WIN32 } } snf_freeifaddrs(ifaddrs); /* * Create a snfX entry if port aggregation is enabled */ if (merge) { /* * Add a new entry with all ports bitmask */ (void)pcap_snprintf(name,MAX_DESC_LENGTH,"snf%d",allports); (void)pcap_snprintf(desc,MAX_DESC_LENGTH,"Myricom Merge Bitmask All Ports snf%d", allports); /* * XXX - is there any notion of "up" and "running" that * would apply to this device, given that it handles * multiple ports? * * Presumably, there's no notion of "connected" vs. * "disconnected", as "is this plugged into a network?" * would be a per-port property. */ if (add_dev(devlistp, name, PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE, desc, errbuf) == NULL) return (-1); /* * XXX - should we give it a list of addresses with all * the addresses for all the ports? */ } return 0; } pcap_t * snf_create(const char *device, char *ebuf, int *is_ours) { pcap_t *p; int boardnum = -1; struct snf_ifaddrs *ifaddrs, *ifa; size_t devlen; struct pcap_snf *ps; if (snf_init(SNF_VERSION_API)) { /* Can't initialize the API, so no SNF devices */ *is_ours = 0; return NULL; } /* * Match a given interface name to our list of interface names, from * which we can obtain the intended board number */ if (snf_getifaddrs(&ifaddrs) || ifaddrs == NULL) { /* Can't get SNF addresses */ *is_ours = 0; return NULL; } devlen = strlen(device) + 1; ifa = ifaddrs; while (ifa) { if (strncmp(device, ifa->snf_ifa_name, devlen) == 0) { boardnum = ifa->snf_ifa_boardnum; break; } ifa = ifa->snf_ifa_next; } snf_freeifaddrs(ifaddrs); if (ifa == NULL) { /* * If we can't find the device by name, support the name "snfX" * and "snf10gX" where X is the board number. */ if (sscanf(device, "snf10g%d", &boardnum) != 1 && sscanf(device, "snf%d", &boardnum) != 1) { /* Nope, not a supported name */ *is_ours = 0; return NULL; } } /* OK, it's probably ours. */ *is_ours = 1; p = pcap_create_common(ebuf, sizeof (struct pcap_snf)); if (p == NULL) return NULL; ps = p->priv; /* * We support microsecond and nanosecond time stamps. */ p->tstamp_precision_count = 2; p->tstamp_precision_list = malloc(2 * sizeof(u_int)); if (p->tstamp_precision_list == NULL) { pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno, "malloc"); pcap_close(p); return NULL; } p->tstamp_precision_list[0] = PCAP_TSTAMP_PRECISION_MICRO; p->tstamp_precision_list[1] = PCAP_TSTAMP_PRECISION_NANO; p->activate_op = snf_activate; ps->snf_boardnum = boardnum; return p; } #ifdef SNF_ONLY /* * This libpcap build supports only SNF cards, not regular network * interfaces.. */ /* * There are no regular interfaces, just SNF interfaces. */ int pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf) { return (0); } /* * Attempts to open a regular interface fail. */ pcap_t * pcap_create_interface(const char *device, char *errbuf) { pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "This version of libpcap only supports SNF cards"); return NULL; } /* * Libpcap version string. */ const char * pcap_lib_version(void) { return (PCAP_VERSION_STRING " (SNF-only)"); } #endif
Upload File
Create Folder