30 #include <sys/types.h>
32 #include <sys/timeb.h>
34 #include <sys/fcntlcom.h>
36 #include <sys/ioctl.h>
37 #include <sys/socket.h>
38 #include <sys/stropts.h>
42 #include <net/nit_if.h>
43 #include <net/nit_pf.h>
44 #include <net/nit_buf.h>
46 #include <netinet/in.h>
47 #include <netinet/in_systm.h>
48 #include <netinet/ip.h>
49 #include <netinet/if_ether.h>
50 #include <netinet/ip_var.h>
51 #include <netinet/udp.h>
52 #include <netinet/udp_var.h>
53 #include <netinet/tcp.h>
54 #include <netinet/tcpip.h>
63 #ifdef HAVE_OS_PROTO_H
71 #define CHUNKSIZE (2*1024)
76 #define BUFSPACE (4*CHUNKSIZE)
119 register u_char *bp, *cp, *ep;
120 register struct nit_bufhdr *hdrp;
121 register struct nit_iftime *ntp;
122 register struct nit_iflen *nlp;
123 register struct nit_ifdrops *ndp;
130 if (
errno == EWOULDBLOCK)
170 hdrp = (
struct nit_bufhdr *)cp;
174 ntp = (
struct nit_iftime *)cp;
177 ndp = (
struct nit_ifdrops *)cp;
182 nlp = (
struct nit_iflen *)cp;
186 bp += hdrp->nhb_totlen;
188 caplen = nlp->nh_pktlen;
194 h.
ts = ntp->nh_timestamp;
195 h.
len = nlp->nh_pktlen;
197 (*callback)(user, &h, cp);
212 struct strbuf ctl, data;
219 ctl.len =
sizeof(*sa);
220 ctl.buf = (
char *)sa;
223 ret = putmsg(p->
fd, &ctl, &data);
238 struct timeval timeout;
245 si.ic_cmd = NIOCSCHUNK;
246 si.ic_len =
sizeof(zero);
247 si.ic_dp = (
char *)&zero;
248 if (
ioctl(p->
fd, I_STR, (
char *)&si) < 0) {
250 errno,
"NIOCSCHUNK");
254 si.ic_timout = INFTIM;
257 timeout.tv_usec = (p->
opt.
timeout * 1000) % 1000000;
258 si.ic_cmd = NIOCSTIME;
259 si.ic_len =
sizeof(timeout);
260 si.ic_dp = (
char *)&timeout;
261 if (
ioctl(p->
fd, I_STR, (
char *)&si) < 0) {
267 flags = NI_TIMESTAMP | NI_LEN | NI_DROPS;
270 si.ic_cmd = NIOCSFLAGS;
271 si.ic_len =
sizeof(flags);
272 si.ic_dp = (
char *)&flags;
273 if (
ioctl(p->
fd, I_STR, (
char *)&si) < 0) {
275 errno,
"NIOCSFLAGS");
288 static const char dev[] =
"/dev/nit";
330 p->
fd = fd = open(dev, O_RDWR);
331 if (fd < 0 &&
errno == EACCES)
332 p->
fd = fd = open(dev, O_RDONLY);
344 if (
ioctl(fd, I_SRDOPT, (
char *)RMSGD) < 0) {
350 if (
ioctl(fd, I_PUSH,
"nbuf") < 0) {
357 si.ic_cmd = NIOCSCHUNK;
358 si.ic_timout = INFTIM;
359 si.ic_len =
sizeof(chunksize);
360 si.ic_dp = (
char *)&chunksize;
361 if (
ioctl(fd, I_STR, (
char *)&si) < 0) {
363 errno,
"NIOCSCHUNK");
369 strncpy(ifr.ifr_name, p->
opt.
device,
sizeof(ifr.ifr_name));
370 ifr.ifr_name[
sizeof(ifr.ifr_name) - 1] =
'\0';
371 si.ic_cmd = NIOCBIND;
372 si.ic_len =
sizeof(ifr);
373 si.ic_dp = (
char *)𝔦
374 if (
ioctl(fd, I_STR, (
char *)&si) < 0) {
381 errno,
"NIOCBIND: %s", ifr.ifr_name);
387 si.ic_cmd = NIOCSSNAP;
390 if (
ioctl(fd, I_STR, (
char *)&si) < 0) {
401 (void)
ioctl(fd, I_FLUSH, (
char *)FLUSHR);
432 p->
dlt_list = (u_int *) malloc(
sizeof(u_int) * 2);
u_int pcap_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen, u_int buflen)
int strioctl(int fd, int cmd, int len, char *dp)
int pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf, int(*check_usable)(const char *), get_if_flags_func get_flags_func)
void pcap_fmt_errmsg_for_errno(char *errbuf, size_t errbuflen, int errnum, const char *fmt,...)
int install_bpf_program(pcap_t *p, struct bpf_program *fp)
int ioctl(int, int, caddr_t)
int read(int, char *, u_int)
#define PACKET_COUNT_IS_UNLIMITED(count)
void pcap_cleanup_live_common(pcap_t *)
int pcap_getnonblock_fd(pcap_t *)
int pcap_setnonblock_fd(pcap_t *p, int)
#define PCAP_VERSION_STRING
#define PCAP_CREATE_COMMON(ebuf, type)
static int get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf)
const char * pcap_lib_version(void)
static int pcap_activate_snit(pcap_t *p)
static int pcap_read_snit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
static int nit_setflags(int, int, int, char *)
int pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
static int pcap_stats_snit(pcap_t *p, struct pcap_stat *ps)
pcap_t * pcap_create_interface(const char *device, char *ebuf)
static int can_be_bound(const char *name)
static int pcap_inject_snit(pcap_t *p, const void *buf, int size)
#define PCAP_ERROR_PERM_DENIED
#define PCAP_ERROR_RFMON_NOTSUP
void(* pcap_handler)(u_char *, const struct pcap_pkthdr *, const u_char *)
struct bpf_insn * bf_insns
activate_op_t activate_op
setnonblock_op_t setnonblock_op
setfilter_op_t setfilter_op
getnonblock_op_t getnonblock_op
setdirection_op_t setdirection_op
set_datalink_op_t set_datalink_op