Info

typedef enum {

SS_UNCONNECTED, /*

SS_CONNECTING, /*

SS_CONNECTED, /*

SS_DISCONNECTING /*

} socket_state;

not allocated unconnected to any socket in process of connecting connected to socket in process of disconnecting

The values listed here have nothing in common with the state values used by the protocols of the transport layer when connections are set up and closed. They denote general states relevant to the outside world (i.e., to user programs).

□ file is a pointer to the file instance of a pseudo-file for communication with the socket (as discussed earlier, user applications use normal file descriptors to perform network operations).

The definition of socket is not tied to a specific protocol. This explains why proto_ops is used as a pointer to a data structure that, in turn, holds pointers to protocol-specific functions to handle the socket:

struct proto_ops { int struct module int int int unsigned int int int int int family; *owner;

(*release) (struct socket *sock); (*bind) (struct socket *sock, struct sockaddr *myaddr, int sockaddr_len); (*connect) (struct socket *sock, struct sockaddr *vaddr, int sockaddr_len, int flags); (*socketpair)(struct socket *sock1, struct socket *sock2); (*accept) (struct socket *sock, struct socket *newsock, int flags); (*getname) (struct socket *sock, struct sockaddr *addr, int *sockaddr_len, int peer); (*poll) (struct file *file, struct socket *sock, struct poll_table_struct *wait); (*ioctl) (struct socket *sock, unsigned int cmd, unsigned long arg); (*compat_ioctl) (struct socket *sock, unsigned int cmd, unsigned long arg); (*listen) (struct socket *sock, int len); (*shutdown) (struct socket *sock, int flags); (*setsockopt)(struct socket *sock, int level, int optname, char _user *optval, int optlen)

(*getsockopt)(struct socket *sock, int level, int int int ssize_t int optname, char _user *optval, int _user *optlen);

(*compat_setsockopt)(struct socket *sock, int level, int optname, char _user *optval, int optlen);

(*compat_getsockopt)(struct socket *sock, int level, int optname, char _user *optval, int _user *optlen);

(*sendmsg) (struct kiocb *iocb, struct socket *sock, struct msghdr *m, size_t total_len); (*recvmsg) (struct kiocb *iocb, struct socket *sock, struct msghdr *m, size_t total_len, int flags);

(*mmap) (struct file *file, struct socket *sock, struct vm_area_struct * vma); (*sendpage) (struct socket *sock, struct page *page, int offset, size_t size, int flags);

Many function pointers have the same name as the corresponding functions in the C standard library. This is not a coincidence because the functions are directed to the functions stored in the pointers by means of the socketcall system call.

The sock pointer also included in the structure points to a much lengthier structure that holds additional socket management data of significance to the kernel. The structure consists of a horrendous number of elements used for sometimes very subtle or seldom required features (the original definition is almost 100 lines long). Here I make do with a much shorter and simplified version. Note that the kernel itself places the most important elements in the structure sock_common that is embedded into struct sock right at the beginning. The following code excerpt shows both structures:

Continue reading here: Includenetsockh

Was this article helpful?

0 0