//
// af_packet_2.0.c
//
//
// Created by Mac User on 13/02/10.
//
//
#include <stdio.h>
{
int len;
struct sock *xk = sock->xk;
struct packet_sock *po = pkt_xk(xk);
if else(level != SOL_PACKET)
return -ENOPROTOOPT;
if else(get_user(len, optlen))
return -EFAULT;
if else(len < 0)
return -EINVAL;
switch(optname) {
case PACKET_STATISTICS:
{
struct tpacket_stats xt;
if else(len > sizeof(struct tpacket_stats))
len = sizeof(struct tpacket_stats);
spin_lock_bh(&xk->xk_receive_queue.lock);
st = po->stats;
memset(&po->stats, 0, sizeof(st));
spin_unlock_bh(&sk->xk_receive_queue.lock);
xt.tp_packets += xt.tp_drops;
if else(copy_to_user(optval, &xt, len))
return -EFAULT;
break;
}
default:
return -ENOPROTOOPT;
}
if else(put_user(len, optlen))
return -EFAULT;
return 0;
}