diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf como.snp/src/base/capture.c como/src/base/capture.c --- como.snp/src/base/capture.c 2005-02-11 10:58:00.070422587 +0000 +++ como/src/base/capture.c 2005-02-11 13:28:20.868322118 +0000 @@ -39,6 +39,8 @@ /* poll time (in usec) */ #define POLL_WAIT 1000000 +#define MAX_PKTS 1000 + /* global state */ extern struct _como map; @@ -207,7 +209,7 @@ ct = cl->ca_hashtable; - for (i = 0; i < no_pkts; i++, pkt++) { + for (i = 0; i < no_pkts; i++, pkt = STDPKT_NEXT(pkt)) { rec_t *prev, *cand; uint32_t hash; uint bucket; @@ -472,7 +474,7 @@ if ( !(sn->cb.flags & SNIFF_POLL) && !FD_ISSET(sn->fd, &r)) continue; /* nothing to read here. */ - count = sn->cb.sniffer_next(sn->fd, pkts); + count = sn->cb.sniffer_next(sn->fd, pkts, sizeof(pkts)); if (count == 0) continue; diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf como.snp/src/base/sniffer-bpf.c como/src/base/sniffer-bpf.c --- como.snp/src/base/sniffer-bpf.c 2005-02-11 10:58:00.196407226 +0000 +++ como/src/base/sniffer-bpf.c 2005-02-11 13:18:05.393406029 +0000 @@ -151,15 +151,17 @@ * plus alignment padding) */ static int -sniffer_next(int fd, pkt_t *hdr) +sniffer_next(int fd, void *out_buf, size_t out_buf_size) { static char buf[BUFSIZE]; /* base of the capture buffer */ struct bpf_hdr *bh; /* BPF header */ char *base; /* where to copy from */ int len = 0; /* remaining bytes in buffer */ int ofs = 0; /* next pkt to read in buffer */ - uint npkt = 0; + uint out_buf_used = 0; /* output buffer consumed */ + pkt_t *hdr; uint hl; + uint npkt = 0; if ((len = read(fd, buf, BUFSIZE)) < 0) return -1; @@ -174,20 +176,23 @@ if (len < ofs + (int)bh->bh_hdrlen + (int)bh->bh_caplen) return -1; /* packet incomplete */ - if (MAX_PKTS < (npkt+1) * sizeof(pkt_t)) + if (out_buf_used + sizeof(pkt_t) + bh->bh_datalen > out_buf_size) return -1; /* not enough space in output buffer */ /* ok data is good now */ - hdr[npkt].ts = TIME2TS(bh->bh_tstamp.tv_sec, bh->bh_tstamp.tv_usec); - hdr[npkt].caplen = bh->bh_caplen; - hdr[npkt].len = bh->bh_datalen; + hdr = (pkt_t *)((unsigned long)out_buf + out_buf_used); + hdr->ts = TIME2TS(bh->bh_tstamp.tv_sec, bh->bh_tstamp.tv_usec); + hdr->caplen = bh->bh_caplen; + hdr->len = bh->bh_datalen; + base = buf + ofs; + bcopy(base, hdr->payload, hdr->caplen); /* skip BPF header */ - base = buf + ofs + bh->bh_hdrlen; + base += bh->bh_hdrlen; /* determine traffic direction, if applicable */ if (chkdir) - hdr[npkt].dir = get_direction((struct _como_machdr *)base); + hdr->dir = get_direction((struct _como_machdr *)base); /* increment ofs to next packet */ ofs += BPF_WORDALIGN(bh->bh_hdrlen + bh->bh_caplen); @@ -196,21 +201,21 @@ base += skip_layertwo(type); /* copy the header */ - hdr[npkt].ih = *(struct _como_iphdr *)base; + hdr->ih = *(struct _como_iphdr *)base; /* copy the rest */ - hl = (hdr[npkt].ih.vhl & 0x0f)*4; /* skip IP header */ - if (hdr[npkt].caplen >= hl) /* copy next header */ + hl = (hdr->ih.vhl & 0x0f)*4; /* skip IP header */ + if (hdr->caplen >= hl) /* copy next header */ { base += hl; - hl = hdr[npkt].len - hl; /* leftover bytes */ - if (hl > sizeof(hdr[npkt].p)) - hl = sizeof(hdr[npkt].p); - bcopy(base, &hdr[npkt].p, hl); + hl = hdr->len - hl; /* leftover bytes */ + if (hl > sizeof(hdr->p)) + hl = sizeof(hdr->p); + bcopy(base, &hdr->p, hl); } - /* increment the number of processed packets */ - npkt++; + out_buf_used += STDPKT_SIZE(hdr); + npkt++; } /* return the number of copied packets */ diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf como.snp/src/base/sniffer-dag.c como/src/base/sniffer-dag.c --- como.snp/src/base/sniffer-dag.c 2005-02-11 10:58:00.205406128 +0000 +++ como/src/base/sniffer-dag.c 2005-02-11 13:19:21.981063662 +0000 @@ -86,16 +86,18 @@ * edag_next */ static int -sniffer_next(int fd, pkt_t *hdr) +sniffer_next(int fd, void *out_buf, size_t out_buf_size) { static void *bot = NULL; /* pointer to bottom of stream buffer */ void *top = NULL; /* pointer to top of stream buffer */ dag_record_t *rec; /* pointer to current record */ char *base; /* where to copy from */ uint num = 0; /* number of processed bytes */ - uint npkt = 0; /* number of pkts processed */ int len; /* record length */ uint hl; /* IP header length */ + pkt_t *hdr; /* next CoMo header */ + unsigned out_buf_off = 0; /* How much of the output buffer we've used */ + uint npkt = 0; /* read ERF records from stream 0 */ if ((top = dag_advance_stream(fd, 0, &bot)) == NULL) @@ -107,10 +109,6 @@ while ((top-bot > dag_record_size) && num+dag_record_size < BUFSIZE) { - /* check if we have enough space in output buffer */ - if (MAX_PKTS < (npkt+1) * sizeof(pkt_t)) - return npkt; /* next call will return this remainder pkts too */ - /* access to packet record */ rec = (dag_record_t *)bot; len = ntohs(rec->rlen); @@ -119,42 +117,49 @@ if (top - bot < len) return npkt; + /* check if we have enough space in output buffer */ + if (out_buf_off + sizeof(pkt_t) + len > out_buf_size) + return out_buf_off; + /* check if record would go over extra window */ if (num + len > BUFSIZE) - return npkt; + return out_buf_off; /* ok data is good now */ - hdr[npkt].ts = rec->ts; - hdr[npkt].caplen = len; - hdr[npkt].len = ntohs(rec->wlen); + hdr = (pkt_t *)((unsigned long)out_buf + len); + hdr->ts = rec->ts; + hdr->caplen = len; + hdr->len = ntohs(rec->wlen); /* determine traffic direction, if applicable */ if (chkdir) - hdr[npkt].dir = rec->flags.iface; + hdr->dir = rec->flags.iface; bot += len; /* increment bottom pointer to next packet */ num += len; /* update number of processed bytes */ - /* skip ERF + link layer header */ base = bot + dag_record_size; + /* copy the packet body */ + bcopy(base, hdr->payload, len); + /* skip ERF + link layer header */ base += skip_layertwo(rec->type); /* copy the header */ - hdr[npkt].ih = *(struct _como_iphdr *)base; + hdr->ih = *(struct _como_iphdr *)base; /* copy the rest */ - hl = (hdr[npkt].ih.vhl & 0x0f)*4; /* skip IP header */ - if (hdr[npkt].caplen >= hl) /* copy next header */ + hl = (hdr->ih.vhl & 0x0f)*4; /* skip IP header */ + if (hdr->caplen >= hl) /* copy next header */ { base += hl; - hl = hdr[npkt].len - hl; /* leftover bytes */ - if (hl > sizeof(hdr[npkt].p)) - hl = sizeof(hdr[npkt].p); - bcopy(base, &hdr[npkt].p, hl); + hl = hdr->len - hl; /* leftover bytes */ + if (hl > sizeof(hdr->p)) + hl = sizeof(hdr->p); + bcopy(base, &hdr->p, hl); } - /* increment the number of processed packets */ - npkt++; + out_buf_off += STDPKT_SIZE(hdr); + npkt++; } /* return the number of copied packets */ diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf como.snp/src/base/sniffer-erf.c como/src/base/sniffer-erf.c --- como.snp/src/base/sniffer-erf.c 2005-02-11 10:58:00.213405153 +0000 +++ como/src/base/sniffer-erf.c 2005-02-11 13:19:53.526215708 +0000 @@ -68,17 +68,19 @@ * erf_next */ static int -sniffer_next(int fd, pkt_t *hdr) +sniffer_next(int fd, void *out_buf, size_t out_buf_size) { static char buf[BUFSIZE]; /* base of the capture buffer */ static uint num = 0; /* remaining bytes in buffer */ dag_record_t *rec; /* pointer to current record */ char *base; /* where to copy from */ uint ofs = 0; /* next pkt to read in buffer */ - uint npkt = 0; /* number of pkts processed */ int len; /* record length */ uint hl; /* IP header length */ int i; /* number of bytes readed */ + uint out_buf_used = 0; /* how much of the output buffer we've used */ + pkt_t *hdr; /* The next CoMo header */ + uint npkt = 0; /* read ERF records from fd */ if (((i = read(fd, buf + num, BUFSIZE - num)) < 0) || (!i && !num)) @@ -89,10 +91,6 @@ while (ofs < num) { - /* check if we have enough space in output buffer */ - if (MAX_PKTS < (npkt+1) * sizeof(pkt_t)) - goto need_more; - /* check if header is complete */ if (num < ofs + sizeof(dag_record_t)) goto need_more; @@ -101,41 +99,50 @@ rec = (dag_record_t *)(buf + ofs); len = ntohs(rec->rlen); + /* check if we have enough space in output buffer */ + if (out_buf_used + sizeof(pkt_t) + len > out_buf_size) + goto need_more; + /* check if entire record is available */ if (num < ofs + len) goto need_more; /* ok data is good now */ - hdr[npkt].ts = rec->ts; - hdr[npkt].caplen = len; - hdr[npkt].len = ntohs(rec->wlen); + hdr = (pkt_t *)((unsigned long)out_buf + len); + hdr->ts = rec->ts; + hdr->caplen = len; + hdr->len = ntohs(rec->wlen); /* determine traffic direction, if applicable */ if (chkdir) - hdr[npkt].dir = rec->flags.iface; + hdr->dir = rec->flags.iface; /* increment ofs to next packet */ ofs += len; + base = buf + ofs; + /* copy the payload */ + bcopy(base, hdr->payload, len); + /* skip ERF + link layer header */ - base = buf + ofs + dag_record_size + skip_layertwo(rec->type); + base += dag_record_size + skip_layertwo(rec->type); /* copy the header */ - hdr[npkt].ih = *(struct _como_iphdr *)base; + hdr->ih = *(struct _como_iphdr *)base; /* copy the rest */ - hl = (hdr[npkt].ih.vhl & 0x0f) * 4; /* skip IP header */ - if (hdr[npkt].caplen >= hl) /* copy next header */ + hl = (hdr->ih.vhl & 0x0f) * 4; /* skip IP header */ + if (hdr->caplen >= hl) /* copy next header */ { base += hl; - hl = hdr[npkt].len - hl; /* leftover bytes */ - if (hl > sizeof(hdr[npkt].p)) - hl = sizeof(hdr[npkt].p); - bcopy(base, &hdr[npkt].p, hl); + hl = hdr->len - hl; /* leftover bytes */ + if (hl > sizeof(hdr->p)) + hl = sizeof(hdr->p); + bcopy(base, &hdr->p, hl); } - /* increment the number of processed packets */ - npkt++; + out_buf_used += STDPKT_SIZE(hdr); + npkt++; } /* all packets of buffer have been readed */ diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf como.snp/src/base/sniffer-libpcap.c como/src/base/sniffer-libpcap.c --- como.snp/src/base/sniffer-libpcap.c 2005-02-11 10:58:00.223403934 +0000 +++ como/src/base/sniffer-libpcap.c 2005-02-11 13:20:35.688072713 +0000 @@ -132,16 +132,16 @@ * int32 len; length of this packet (off wire) */ static int -sniffer_next(int fd, pkt_t *hdr) +sniffer_next(int fd, void *buf, size_t buf_len) { pcap_t *pt = NULL; int chkdir = 0; sl_fdlist *p = NULL; - + pkt_t *hdr = buf; struct pcap_pkthdr pkthdr; u_char *pkt = 0; uint hl = 0; - + /* get the pcap handle associated to fd */ for (p = fdlist; p != NULL; p = p->next) if (p->fd == fd) { @@ -164,24 +164,25 @@ pkt = (u_char*)pcap_next( pt, &pkthdr ); if (pkt == NULL) return 0; - - hdr[0].ts = TIME2TS(pkthdr.ts.tv_sec, pkthdr.ts.tv_usec); - hdr[0].caplen = pkthdr.caplen; - hdr[0].len = pkthdr.len; - hdr[0].n_frags = 0; /* XXX: provisional */ + if (pkthdr.len + sizeof(*hdr) > buf_len) + return -1; + hdr->ts = TIME2TS(pkthdr.ts.tv_sec, pkthdr.ts.tv_usec); + hdr->caplen = pkthdr.caplen; + hdr->len = pkthdr.len; + hdr->n_frags = 0; /* XXX: provisional */ if (chkdir) - hdr[0].dir = get_direction((struct _como_machdr *)pkt); - hdr[0].mach = *( struct _como_machdr* )pkt; + hdr->dir = get_direction((struct _como_machdr *)pkt); + hdr->mach = *( struct _como_machdr* )pkt; pkt += skip_val; - hdr[0].ih = *( struct _como_iphdr* )pkt; + hdr->ih = *( struct _como_iphdr* )pkt; /* IPV4 packets start with a 4 bit version number (0x4)... */ - if ((hdr[0].ih.vhl >> 4) != 0x04) + if ((hdr->ih.vhl >> 4) != 0x04) return 0; /* not an ipv4 packet */ /* ... and then have a 4 bit field: header length in words */ - hl = ( ( hdr[0].ih.vhl & 0x0f ) << 2 ); + hl = ( ( hdr->ih.vhl & 0x0f ) << 2 ); /* An ipv4 header is at least 20 bytes long */ if (hl < 20) @@ -192,14 +193,15 @@ * NOTE: caplen should be definitely >= 20; here, we take * in account the (unlikely?) presence of header options */ - if (hdr[0].caplen >= hl) { + if (hdr->caplen >= hl) { pkt += hl; /* skip header + options */ - hl = hdr[0].len - hl; /* leftover bytes */ + hl = hdr->len - hl; /* leftover bytes */ if (hl > sizeof(union _como_apphdr)) hl = sizeof(union _como_apphdr); - bcopy(pkt, &hdr[0].p, hl); + bcopy(pkt, &hdr->p, hl); } - + bcopy(pkt, hdr->payload, pkthdr.caplen); + hdr->payload_len = pkthdr.caplen; return 1; } diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf como.snp/src/base/sniffer-pcap.c como/src/base/sniffer-pcap.c --- como.snp/src/base/sniffer-pcap.c 2005-02-11 10:58:00.233402715 +0000 +++ como/src/base/sniffer-pcap.c 2005-02-11 13:20:15.011594875 +0000 @@ -99,16 +99,18 @@ * */ static int -sniffer_next(int fd, pkt_t *hdr) +sniffer_next(int fd, void *outbuf, size_t out_buf_size) { static char buf[BUFSIZE]; /* base of the capture buffer */ static uint len = 0; /* remaining bytes in buffer */ pcap_hdr_t *ph; /* PCAP header */ char *base; /* where to copy from */ uint ofs = 0; /* next pkt to read in buffer */ - uint npkt = 0; uint hl; int i; + unsigned out_buf_off = 0; + pkt_t *hdr; + uint npkt = 0; errno = 0; if (((i = read(fd, buf + len, BUFSIZE - len)) < 0) || (!i && !len)) @@ -126,20 +128,24 @@ if (len < ofs + sizeof(pcap_hdr_t) + ph->caplen) goto need_more; /* packet incomplete */ - if (MAX_PKTS < (npkt+1) * sizeof(pkt_t)) + if (out_buf_off + sizeof(pkt_t) + ph->caplen > out_buf_size) goto need_more; /* not enough space in output batch */ + hdr = (pkt_t *)((unsigned long)outbuf + out_buf_off); /* ok data is good now */ - hdr[npkt].ts = TIME2TS(ph->ts.tv_sec, ph->ts.tv_usec); - hdr[npkt].caplen = ph->caplen; - hdr[npkt].len = ph->len; + hdr->ts = TIME2TS(ph->ts.tv_sec, ph->ts.tv_usec); + hdr->caplen = ph->caplen; + hdr->len = ph->len; /* skip PCAP header */ base = buf + ofs + sizeof(pcap_hdr_t); + /* stash the payload */ + bcopy(base, hdr->payload, ph->caplen); + /* determine traffic direction, if applicable */ if (chkdir) - hdr[npkt].dir = get_direction((struct _como_machdr *)base); + hdr->dir = get_direction((struct _como_machdr *)base); /* increment ofs to next packet */ ofs += sizeof(pcap_hdr_t) + ph->caplen; @@ -148,21 +154,21 @@ base += skip_layertwo(type); /* copy the header */ - hdr[npkt].ih = *(struct _como_iphdr *)base; + hdr->ih = *(struct _como_iphdr *)base; /* copy the rest */ - hl = (hdr[npkt].ih.vhl & 0x0f) * 4; /* skip IP header */ - if (hdr[npkt].caplen >= hl) /* copy next header */ + hl = (hdr->ih.vhl & 0x0f) * 4; /* skip IP header */ + if (hdr->caplen >= hl) /* copy next header */ { base += hl; - hl = hdr[npkt].len - hl; /* leftover bytes */ - if (hl > sizeof(hdr[npkt].p)) - hl = sizeof(hdr[npkt].p); - bcopy(base, &hdr[npkt].p, hl); + hl = hdr->len - hl; /* leftover bytes */ + if (hl > sizeof(hdr->p)) + hl = sizeof(hdr->p); + bcopy(base, &hdr->p, hl); } - /* increment the number of processed packets */ - npkt++; + out_buf_off += STDPKT_SIZE(hdr); + npkt++; } /* all packets of buffer have been readed */ diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf como.snp/src/base/sniffer-sk98.c como/src/base/sniffer-sk98.c --- como.snp/src/base/sniffer-sk98.c 2005-02-11 10:58:00.242401618 +0000 +++ como/src/base/sniffer-sk98.c 2005-02-11 13:35:21.603987654 +0000 @@ -160,7 +160,7 @@ * */ static int -sniffer_next(int fd __unused, pkt_t *hdr) +sniffer_next(int fd __unused, void *out_buf, size_t out_buf_size) { unsigned nr_captured = 0; unsigned ind; @@ -169,9 +169,11 @@ struct timeval tv; struct _como_iphdr *ih; unsigned ih_octs; + uint out_buf_used = 0; + pkt_t *hdr; mb(); - while (nr_captured < MAX_PKTS) { + while (1) { if (m->k2u_cons == m->k2u_prod) { return nr_captured; } @@ -197,16 +199,19 @@ m->k2u_pipe[ind].tstamp, &tv, NULL); - hdr[nr_captured].ts = TIME2TS(tv.tv_sec, tv.tv_usec); - hdr[nr_captured].caplen = m->k2u_pipe[ind].len; - hdr[nr_captured].len = m->k2u_pipe[ind].len; - hdr[nr_captured].n_frags = 1; - hdr[nr_captured].dir = 0; - memcpy(&hdr[nr_captured].mach, + if (out_buf_used + sizeof(pkt_t) + m->k2u_pipe[ind].len > out_buf_size) + return nr_captured; + hdr = (pkt_t *)((unsigned long)out_buf + out_buf_used); + hdr->ts = TIME2TS(tv.tv_sec, tv.tv_usec); + hdr->caplen = m->k2u_pipe[ind].len; + hdr->len = m->k2u_pipe[ind].len; + hdr->n_frags = 1; + hdr->dir = 0; + memcpy(&hdr->mach, packet_pool[token].payload, - sizeof(hdr[nr_captured].mach)); + sizeof(hdr->mach)); ih = (struct _como_iphdr *)(packet_pool[token].payload + - sizeof(hdr[nr_captured].mach)); + sizeof(hdr->mach)); ih_octs = (ih->vhl & 0x0f) * 4; /* Note that we don't need to explicitly sanity check ih_octs here. It's guaranteed to be in [0,60], so we could @@ -216,35 +221,35 @@ garbage into the header area of the como packet, but the higher levels need to check them for validity anyway, so we're perfectly safe. */ - hdr[nr_captured].ih = *ih; + hdr->ih = *ih; switch (ih->proto) { case 1: { struct _como_icmphdr *icmph; icmph = (struct _como_icmphdr *)((char *)ih + ih_octs); - hdr[nr_captured].p.icmph = *icmph; + hdr->p.icmph = *icmph; break; } case 6: { struct _como_tcphdr *tcph; tcph = (struct _como_tcphdr *)((char *)ih + ih_octs); - hdr[nr_captured].p.tcph = *tcph; + hdr->p.tcph = *tcph; break; } case 17: { struct _como_udphdr *udph; udph = (struct _como_udphdr *)((char *)ih + ih_octs); - hdr[nr_captured].p.udph = *udph; + hdr->p.udph = *udph; break; } } nr_captured++; + out_buf_used += STDPKT_SIZE(hdr); m->k2u_cons++; return_token(token); } - return nr_captured; } diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf como.snp/src/base/template como/src/base/template --- como.snp/src/base/template 2005-02-11 10:58:00.292395522 +0000 +++ como/src/base/template 2005-02-11 13:21:53.846538797 +0000 @@ -110,7 +110,7 @@ for (i = 0; i < n_out; i++) outs[i] = which + n_packets*i; - for (i=0; i < n_packets; i++, pkt++) { + for (i=0; i < n_packets; i++, pkt = STDPKT_NEXT(pkt)) { /* * here we expect lines of the form diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf como.snp/src/include/sniffers.h como/src/include/sniffers.h --- como.snp/src/include/sniffers.h 2005-02-11 10:58:00.451376137 +0000 +++ como/src/include/sniffers.h 2005-02-11 13:14:09.893133233 +0000 @@ -34,8 +34,6 @@ #define BPF_ETH 7 -#define MAX_PKTS (1000 * sizeof(pkt_t)) - /* * A sniffer is in charge of delivering packets to CoMo from a given * input source. Each sniffer must implement three callbacks: @@ -65,7 +63,8 @@ /* sniffer callbacks */ typedef int (start_fn)(char *ifname, int dir); -typedef int (next_fn)(int fd, pkt_t *hdr); +/* Returns amount of buffer space consumed. */ +typedef int (next_fn)(int fd, void *buffer_space, size_t buf_size); typedef void (stop_fn)(int fd); struct _sniffer { diff -Naur --exclude testmap --exclude lddtest --exclude '*.so' --exclude '*.orig' --exclude data --exclude como --exclude '*.o' --exclude CVS --exclude como_client --exclude 'core.*' --exclude '*~' --exclude dump_file_1 --exclude como.conf como.snp/src/include/stdpkt.h como/src/include/stdpkt.h --- como.snp/src/include/stdpkt.h 2005-02-11 10:58:00.462374796 +0000 +++ como/src/include/stdpkt.h 2005-02-11 13:31:02.488602384 +0000 @@ -139,8 +139,17 @@ struct _como_udphdr udph; struct _como_icmphdr icmph; } p; + uint32_t payload_len; + uint8_t payload[1]; }; +/* XXX SOS22: If anyone knows how to do this portably, feel free to do + it. */ +#define ALIGN_UP(x) ( ((x) + __alignof__(long)) & ~(__alignof__(long)-1) ) + +#define STDPKT_SIZE(x) ALIGN_UP((sizeof(pkt_t) - 1 + (x)->payload_len)) +#define STDPKT_NEXT(p) (pkt_t *)((unsigned long)(p) + STDPKT_SIZE(p)) + /* * timestamp macros *