网络-网络接口

网络接口socket

内核源码 fs/net.h
struct socket {
	socket_state		state;
	short				type;
	unsigned long		flags;
	struct socket_wq	*wq;
	struct file			*file;
	struct sock			*sk;
	const struct proto_ops	*ops;//函数指针集合
};

参数1| socket_state
typedef enum {
	SS_FREE = 0,			/* not allocated		*/
	SS_UNCONNECTED,			/* unconnected to any socket	*/
	SS_CONNECTING,			/* in process of connecting	*/
	SS_CONNECTED,			/* connected to socket		*/
	SS_DISCONNECTING		/* in process of disconnecting	*/
} socket_state;

参数2| 
参数3| 

参数4| socket_wq
struct socket_wq {
	/* Note: wait MUST be first field of socket_wq */
	wait_queue_head_t	wait;
	struct fasync_struct	*fasync_list;
	unsigned long		flags; /* %SOCKWQ_ASYNC_NOSPACE, etc */
	struct rcu_head		rcu;
} ____cacheline_aligned_in_smp;

参数5| 
参数6| 

参数7| proto_ops
struct proto_ops {
	int		family;
	struct module	*owner;
	int		(*release)   (struct socket *sock);
	int		(*bind)	     (struct socket *sock,
			      struct sockaddr *myaddr,
			      int sockaddr_len);
	int		(*connect)   (struct socket *sock,
			      struct sockaddr *vaddr,
			      int sockaddr_len, int flags);
	int		(*socketpair)(struct socket *sock1,
			      struct socket *sock2);
	int		(*accept)    (struct socket *sock,
			      struct socket *newsock, int flags, bool kern);
	int		(*getname)   (struct socket *sock,
			      struct sockaddr *addr,
			      int peer);
	__poll_t	(*poll)	     (struct file *file, struct socket *sock,
			      struct poll_table_struct *wait);
	int		(*ioctl)     (struct socket *sock, unsigned int cmd,
			      unsigned long arg);
#ifdef CONFIG_COMPAT
	int	 	(*compat_ioctl) (struct socket *sock, unsigned int cmd,
			      unsigned long arg);
#endif
	int		(*listen)    (struct socket *sock, int len);
	int		(*shutdown)  (struct socket *sock, int flags);
	int		(*setsockopt)(struct socket *sock, int level,
			      int optname, char __user *optval, unsigned int optlen);
	int		(*getsockopt)(struct socket *sock, int level,
			      int optname, char __user *optval, int __user *optlen);
#ifdef CONFIG_COMPAT
	int		(*compat_setsockopt)(struct socket *sock, int level,
			      int optname, char __user *optval, unsigned int optlen);
	int		(*compat_getsockopt)(struct socket *sock, int level,
			      int optname, char __user *optval, int __user *optlen);
#endif
	int		(*sendmsg)   (struct socket *sock, struct msghdr *m,
			      size_t total_len);
	/* Notes for implementing recvmsg:
 	* ===============================
 	* msg->msg_namelen should get updated by the recvmsg handlers
 	* iff msg_name != NULL. It is by default 0 to prevent
 	* returning uninitialized memory to user space.  The recvfrom
 	* handlers can assume that msg.msg_name is either NULL or has
 	* a minimum size of sizeof(struct sockaddr_storage).
 	*/
	int		(*recvmsg)   (struct socket *sock, struct msghdr *m,
			      size_t total_len, int flags);
	int		(*mmap)	     (struct file *file, struct socket *sock,
			      struct vm_area_struct * vma);
	ssize_t		(*sendpage)  (struct socket *sock, struct page *page,
			      int offset, size_t size, int flags);
	ssize_t 	(*splice_read)(struct socket *sock,  loff_t *ppos,
			       struct pipe_inode_info *pipe, size_t len, unsigned int flags);
	int		(*set_peek_off)(struct sock *sk, int val);
	int		(*peek_len)(struct socket *sock);

	/* The following functions are called internally by kernel with
 	* sock lock already held.
 	*/
	int		(*read_sock)(struct sock *sk, read_descriptor_t *desc,
			     sk_read_actor_t recv_actor);
	int		(*sendpage_locked)(struct sock *sk, struct page *page,
				   int offset, size_t size, int flags);
	int		(*sendmsg_locked)(struct sock *sk, struct msghdr *msg,
				  size_t size);
	int		(*set_rcvlowat)(struct sock *sk, int val);
};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值