您的位置: 旅游网 > 影视

struct sock结构的简单注释_a

发布时间:2020-01-16 21:46:54

内核网络四层结构:BSD socket层、INET socket层、IP层、数据链路层

sock结构工作在INET socket层,所有BSD socket层的操作都通过struct sock

及其域字段prot指针转化为prot锁指向的函数处理,所以sock结构是维系

BSD socket层和INET socket层的纽带,其重要性是不言而喻的。

下面是对sock结构的简单注释,有些没有的待我弄懂后再来修改,^_^

struct sock {

/* Socket demultiplex comparisons on incoming packets. */

__u32daddr;/* 外部IP地址*/

__u32rcv_saddr;/* 绑定的本地IP地址*/

__u16dport;/* 目标端口*/

unsigned shortnum;/* 本地端口*/

intbound_dev_if;/* 绑定网卡接口的索引 不为0*/

/* 用于各种协议查找表的哈希链表 */

struct sock*next;

struct sock**pprev;

struct sock*bind_next;

struct sock**bind_pprev;

volatile unsigned charstate,/* 连接状态*/

zapped;/* In ax25 & ipx means not linked*/

__u16sport;/* 源端口*/

unsigned shortfamily;/* 地址簇*/

unsigned charreuse;/* SO_REUSEADDR设置,表示地址重用*/

unsigned charshutdown;/* 半关闭标志 SEND_SHUTDOWN和RCV_SHUTDOWN掩码 */

atomic_trefcnt;/* 引用计数*/

socket_lock_tlock;/* 同步锁.*/

intrcvbuf;/* 接受缓冲区长度(单位:字节)*/

wait_queue_head_t*sleep;/* 等待队列,通常指向socket的wait域*/

struct dst_entry*dst_cache;/* 目的地缓存,用于路由查找结果*/

rwlock_tdst_lock;/* 目的地缓存锁*/

atomic_trmem_alloc;/* 已接收队列字节数*/

struct sk_buff_headreceive_queue;/* 接收包队列*/

atomic_twmem_alloc;/* 已发送字节数*/

struct sk_buff_headwrite_queue;/* 包发送队列*/

atomic_tomem_alloc;/* "o"是"option"(选项)或"other"(其它)的意思 */

intwmem_queued;/* 稳定的队列长度 */

intforward_alloc;/* 提前分配的空间 */

__u32saddr;/* 发送源地址*/

unsigned intallocation;/* 分配模式*/

intsndbuf;/* 发送缓冲区长度(单位:字节)*/

struct sock*prev;

/* Not all are volatile, but some are, so we might as well say they all are.

* XXX Make this a flag word -DaveM

*/

volatile chardead,

done,

urginline,

keepopen,

linger,

destroy,

no_check, /*SO_NO_CHECK标志,表示是否检查包*/

broadcast,

bsdism;

unsigned chardebug;

unsigned charrcvtstamp;

unsigned charuserlocks;/*SO_SNDBUF和SO_RCVBUF标志 */

intproc;

unsigned long lingertime;

inthashent;

struct sock*pair;

/* The backlog queue is special, it is always used with

* the per-socket spinlock held and requires low latency

* access. Therefore we special case it's implementation.

*/

struct {

struct sk_buff *head;

struct sk_buff *tail;

} backlog;

rwlock_tcallback_lock;/*用于结构末尾的回调函数互斥*/

/* 错误队列,很少使用 */

struct sk_buff_headerror_queue;

struct proto*prot;/*网络地址簇内部协议处理*/

#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)

union {

struct ipv6_pinfoaf_inet6;

} net_pinfo;

#endif

union {

struct tcp_optaf_tcp;

#if defined(CONFIG_INET) || defined (CONFIG_INET_MODULE)

struct raw_opttp_raw4;

#endif

#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)

struct raw6_opttp_raw;

#endif /* CONFIG_IPV6 */

#if defined(CONFIG_SPX) || defined (CONFIG_SPX_MODULE)

struct spx_optaf_spx;

#endif /* CONFIG_SPX */

} tp_pinfo;

interr, err_soft;/* Soft holds errors that don't

cause failure but are the cause

of a persistent failure not just

'timed out' */

unsigned shortack_backlog;

unsigned shortmax_ack_backlog;

__u32priority;

unsigned shorttype;/*socket类型,如:SOCK_STREAM*/

unsigned charlocalroute;/* 仅用于本地路由 */

unsigned charprotocol;/*socket 所属网络地址簇的协议*/

struct ucredpeercred;/*对端sock信息 SO_PEERCRED标志设置*/

intrcvlowat;/*SO_RCVLOWAT标志位*/

longrcvtimeo;/*SO_RCVTIMEO标志位*/

longsndtimeo;/*SO_SNDTIMEO标志位*/

#ifdef CONFIG_FILTER

/* Socket过滤指令 */

struct sk_filter *filter;

#endif /* CONFIG_FILTER */

/* This is where all the private (optional) areas that don't

* overlap will eventually live.

*/

union {

void *destruct_hook;

struct unix_optaf_unix;

#if defined(CONFIG_INET) || defined (CONFIG_INET_MODULE)

struct inet_opt af_inet;

#endif

#if defined(CONFIG_ATALK) || defined(CONFIG_ATALK_MODULE)

struct atalk_sockaf_at;

#endif

#if defined(CONFIG_IPX) || defined(CONFIG_IPX_MODULE)

struct ipx_optaf_ipx;

#endif

#if defined (CONFIG_DECNET) || defined(CONFIG_DECNET_MODULE)

struct dn_scp dn;

#endif

#if defined (CONFIG_PACKET) || defined(CONFIG_PACKET_MODULE)

struct packet_opt*af_packet;

#endif

#if defined(CONFIG_X25) || defined(CONFIG_X25_MODULE)

x25_cb*x25;

#endif

#if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)

ax25_cb*ax25;

#endif

#if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE)

nr_cb*nr;

#endif

#if defined(CONFIG_ROSE) || defined(CONFIG_ROSE_MODULE)

rose_cb*rose;

#endif

#if defined(CONFIG_PPPOE) || defined(CONFIG_PPPOE_MODULE)

struct pppox_opt*pppox;

#endif

#ifdef CONFIG_NETLINK

struct netlink_opt*af_netlink;

#endif

#if defined(CONFIG_ECONET) || defined(CONFIG_ECONET_MODULE)

struct econet_opt*af_econet;

#endif

#if defined(CONFIG_ATM) || defined(CONFIG_ATM_MODULE)

struct atm_vcc*af_atm;

#endif

#if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)

struct irda_sock *irda;

#endif

} protinfo; /*私有数据区,网络地址簇规范*/

/* This part is used for the timeout functions. */

struct timer_listtimer;/* sock清除定时器. */

struct timevalstamp;/*最后到达的包的时间戳*/

/* Identd and reporting IO signals */

struct socket*socket;/*BSD socket层套接字*/

/* RPC层私有数据 */

void*user_data;

/* 回调函数 */

void(*state_change)(struct sock *sk);

void(*data_ready)(struct sock *sk,int bytes);

void(*write_space)(struct sock *sk);

void(*error_report)(struct sock *sk);

int(*backlog_rcv) (struct sock *sk,

struct sk_buff *skb);

void (*destruct)(struct sock *sk);

};

月经有血块如何调理
专为儿童研制的止咳药
老是口腔溃疡怎么办
他达拉非药房可以买到吗
猜你会喜欢的
猜你会喜欢的