Skip to content

Commit

Permalink
[AF_PACKET]: annotate
Browse files Browse the repository at this point in the history
Weirdness: the third argument of socket() is net-endian
here.  Oh, well - it's documented in packet(7).

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Al Viro authored and David S. Miller committed Dec 3, 2006
1 parent 3fbd418 commit 0e11c91
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
6 changes: 4 additions & 2 deletions include/linux/if_packet.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#ifndef __LINUX_IF_PACKET_H
#define __LINUX_IF_PACKET_H

#include <linux/types.h>

struct sockaddr_pkt
{
unsigned short spkt_family;
unsigned char spkt_device[14];
unsigned short spkt_protocol;
__be16 spkt_protocol;
};

struct sockaddr_ll
{
unsigned short sll_family;
unsigned short sll_protocol;
__be16 sll_protocol;
int sll_ifindex;
unsigned short sll_hatype;
unsigned char sll_pkttype;
Expand Down
18 changes: 10 additions & 8 deletions net/packet/af_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ struct packet_sock {
spinlock_t bind_lock;
char running; /* prot_hook is attached*/
int ifindex; /* bound device */
unsigned short num;
__be16 num;
#ifdef CONFIG_PACKET_MULTICAST
struct packet_mclist *mclist;
#endif
Expand Down Expand Up @@ -331,7 +331,7 @@ static int packet_sendmsg_spkt(struct kiocb *iocb, struct socket *sock,
struct sockaddr_pkt *saddr=(struct sockaddr_pkt *)msg->msg_name;
struct sk_buff *skb;
struct net_device *dev;
unsigned short proto=0;
__be16 proto=0;
int err;

/*
Expand Down Expand Up @@ -704,7 +704,7 @@ static int packet_sendmsg(struct kiocb *iocb, struct socket *sock,
struct sockaddr_ll *saddr=(struct sockaddr_ll *)msg->msg_name;
struct sk_buff *skb;
struct net_device *dev;
unsigned short proto;
__be16 proto;
unsigned char *addr;
int ifindex, err, reserve = 0;

Expand Down Expand Up @@ -858,7 +858,7 @@ static int packet_release(struct socket *sock)
* Attach a packet hook.
*/

static int packet_do_bind(struct sock *sk, struct net_device *dev, int protocol)
static int packet_do_bind(struct sock *sk, struct net_device *dev, __be16 protocol)
{
struct packet_sock *po = pkt_sk(sk);
/*
Expand Down Expand Up @@ -983,6 +983,7 @@ static int packet_create(struct socket *sock, int protocol)
{
struct sock *sk;
struct packet_sock *po;
__be16 proto = (__force __be16)protocol; /* weird, but documented */
int err;

if (!capable(CAP_NET_RAW))
Expand Down Expand Up @@ -1010,7 +1011,7 @@ static int packet_create(struct socket *sock, int protocol)

po = pkt_sk(sk);
sk->sk_family = PF_PACKET;
po->num = protocol;
po->num = proto;

sk->sk_destruct = packet_sock_destruct;
atomic_inc(&packet_socks_nr);
Expand All @@ -1027,8 +1028,8 @@ static int packet_create(struct socket *sock, int protocol)
#endif
po->prot_hook.af_packet_priv = sk;

if (protocol) {
po->prot_hook.type = protocol;
if (proto) {
po->prot_hook.type = proto;
dev_add_pack(&po->prot_hook);
sock_hold(sk);
po->running = 1;
Expand Down Expand Up @@ -1624,7 +1625,8 @@ static int packet_set_ring(struct sock *sk, struct tpacket_req *req, int closing
{
char **pg_vec = NULL;
struct packet_sock *po = pkt_sk(sk);
int was_running, num, order = 0;
int was_running, order = 0;
__be16 num;
int err = 0;

if (req->tp_block_nr) {
Expand Down

0 comments on commit 0e11c91

Please sign in to comment.