/*
 * netsniff-ng - the packet sniffing beast
 * Copyright 2009 - 2013 Daniel Borkmann.
 * Subject to the GPL, version 2.
 */

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>

#include "pcap_io.h"
#include "built_in.h"
#include "xutils.h"
#include "xio.h"
#include "die.h"

static ssize_t pcap_rw_write(int fd, pcap_pkthdr_t *phdr, enum pcap_type type,
			     const uint8_t *packet, size_t len)
{
	ssize_t ret, hdrsize = pcap_get_hdr_length(phdr, type), hdrlen = 0;

	ret = write_or_die(fd, &phdr->raw, hdrsize);
	if (unlikely(ret != hdrsize))
		panic("Failed to write pkt header!\n");

	hdrlen = pcap_get_length(phdr, type);
	if (unlikely(hdrlen != len))
		return -EINVAL;

	ret = write_or_die(fd, packet, hdrlen);
	if (unlikely(ret != hdrlen))
		panic("Failed to write pkt payload!\n");

	return hdrsize + hdrlen;
}

static ssize_t pcap_rw_read(int fd, pcap_pkthdr_t *phdr, enum pcap_type type,
			    uint8_t *packet, size_t len)
{
	ssize_t ret, hdrsize = pcap_get_hdr_length(phdr, type), hdrlen = 0;

	ret = read_or_die(fd, &phdr->raw, hdrsize);
	if (unlikely(ret != hdrsize))
		return -EIO;

	hdrlen = pcap_get_length(phdr, type);
	if (unlikely(hdrlen == 0 || hdrlen > len))
                return -EINVAL;

	ret = read(fd, packet, hdrlen);
	if (unlikely(ret != hdrlen))
		return -EIO;

	return hdrsize + hdrlen;
}

static int pcap_rw_prepare_access(int fd, enum pcap_mode mode, bool jumbo)
{
	set_ioprio_rt();

	return 0;
}

static void pcap_rw_fsync(int fd)
{
	fdatasync(fd);
}

const struct pcap_file_ops pcap_rw_ops = {
	.pull_fhdr_pcap = pcap_generic_pull_fhdr,
	.push_fhdr_pcap = pcap_generic_push_fhdr,
	.prepare_access_pcap = pcap_rw_prepare_access,
	.read_pcap = pcap_rw_read,
	.write_pcap = pcap_rw_write,
	.fsync_pcap = pcap_rw_fsync,
};
t-next.git/tree/sound/oss/ulaw.h?h=nds-private-remove&amp;id=16a16cd35ee29d9bea54dd60e55d9c1cc685a37d'>tree</a><a href='/cgit.cgi/linux/net-next.git/commit/sound/oss/ulaw.h?h=nds-private-remove&amp;id=16a16cd35ee29d9bea54dd60e55d9c1cc685a37d'>commit</a><a href='/cgit.cgi/linux/net-next.git/diff/sound/oss/ulaw.h?h=nds-private-remove&amp;id=16a16cd35ee29d9bea54dd60e55d9c1cc685a37d'>diff</a></td><td class='form'><form class='right' method='get' action='/cgit.cgi/linux/net-next.git/log/sound/oss/ulaw.h'>
<input type='hidden' name='h' value='nds-private-remove'/><input type='hidden' name='id' value='16a16cd35ee29d9bea54dd60e55d9c1cc685a37d'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/cgit.cgi/linux/net-next.git/log/?h=nds-private-remove&amp;id=16a16cd35ee29d9bea54dd60e55d9c1cc685a37d'>root</a>/<a href='/cgit.cgi/linux/net-next.git/log/sound?h=nds-private-remove&amp;id=16a16cd35ee29d9bea54dd60e55d9c1cc685a37d'>sound</a>/<a href='/cgit.cgi/linux/net-next.git/log/sound/oss?h=nds-private-remove&amp;id=16a16cd35ee29d9bea54dd60e55d9c1cc685a37d'>oss</a>/<a href='/cgit.cgi/linux/net-next.git/log/sound/oss/ulaw.h?h=nds-private-remove&amp;id=16a16cd35ee29d9bea54dd60e55d9c1cc685a37d'>ulaw.h</a></div><div class='content'><table class='list nowrap'><tr class='nohover'><th class='left'>Age</th><th class='left'>Commit message (<a href='/cgit.cgi/linux/net-next.git/log/sound/oss/ulaw.h?h=nds-private-remove&amp;id=16a16cd35ee29d9bea54dd60e55d9c1cc685a37d&amp;showmsg=1'>Expand</a>)</th><th class='left'>Author</th><th class='left'>Files</th><th class='left'>Lines</th></tr>