FreeBSD/contrib/pf/pflogd/pflogd.c
/* append packet to the buffer, flushing if necessary */
append packet to the buffer, flushing if necessary
append packet to the buffer flushing if necessary
void
dump_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
{
	FILE *f = (FILE *)user;
#ifdef __FreeBSD__
	struct pcap_sf_pkthdr sh;
	size_t len = sizeof(sh) + h->caplen;
#else
	size_t len = sizeof(*h) + h->caplen;
#endif
	if (len < sizeof(*h) || h->caplen > (size_t)cur_snaplen) {
		logmsg(LOG_NOTICE, "invalid size %u (%u/%u), packet dropped",
		       len, cur_snaplen, snaplen);
		packets_dropped++;
		return;
	}
	if (len <= bufleft)
		goto append;
	if (suspended) {
		packets_dropped++;
		return;
	}
	if (flush_buffer(f)) {
		packets_dropped++;
		return;
	}
	if (len > bufleft) {
		dump_packet_nobuf(user, h, sp);
		return;
	}
 append:       
#ifdef __FreeBSD__
	sh.ts.tv_sec = (bpf_int32)h->ts.tv_sec;
	sh.ts.tv_usec = (bpf_int32)h->ts.tv_usec;
	sh.caplen = h->caplen;
	sh.len = h->len;
	memcpy(bufpos, &sh, sizeof(sh));
	memcpy(bufpos + sizeof(sh), sp, h->caplen);
#else
	memcpy(bufpos, h, sizeof(*h));
	memcpy(bufpos + sizeof(*h), sp, h->caplen);
#endif
	bufpos += len;
	bufleft -= len;
	bufpkt++;
	return;
}
void dump_packet ( u_char * user , const struct pcap_pkthdr * h , const u_char * sp ) { FILE * f = ( FILE * ) user ; #ifdef __FreeBSD__ struct pcap_sf_pkthdr sh ; size_t len = sizeof ( sh ) + h -> caplen ; #else size_t len = sizeof ( * h ) + h -> caplen ; #endif if ( len < sizeof ( * h ) || h -> caplen > ( size_t ) cur_snaplen ) { logmsg ( LOG_NOTICE , " " , len , cur_snaplen , snaplen ) ; packets_dropped ++ ; return ; } if ( len <= bufleft ) goto append ; if ( suspended ) { packets_dropped ++ ; return ; } if ( flush_buffer ( f ) ) { packets_dropped ++ ; return ; } if ( len > bufleft ) { dump_packet_nobuf ( user , h , sp ) ; return ; } append : #ifdef __FreeBSD__ sh . ts . tv_sec = ( bpf_int32 ) h -> ts . tv_sec ; sh . ts . tv_usec = ( bpf_int32 ) h -> ts . tv_usec ; sh . caplen = h -> caplen ; sh . len = h -> len ; memcpy ( bufpos , & sh , sizeof ( sh ) ) ; memcpy ( bufpos + sizeof ( sh ) , sp , h -> caplen ) ; #else memcpy ( bufpos , h , sizeof ( * h ) ) ; memcpy ( bufpos + sizeof ( * h ) , sp , h -> caplen ) ; #endif bufpos += len ; bufleft -= len ; bufpkt ++ ; return ; }
append packet to the buffer, flushing if necessary
append packet to the buffer flushing if necessary