1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #ifndef _LINUX_NET_H
19 #define _LINUX_NET_H
20
21
22 #include <linux/wait.h>
23 #include <linux/socket.h>
24
25
26 #define NSOCKETS 128
27 #define NPROTO 16
28
29
30 #define SYS_SOCKET 1
31 #define SYS_BIND 2
32 #define SYS_CONNECT 3
33 #define SYS_LISTEN 4
34 #define SYS_ACCEPT 5
35 #define SYS_GETSOCKNAME 6
36 #define SYS_GETPEERNAME 7
37 #define SYS_SOCKETPAIR 8
38 #define SYS_SEND 9
39 #define SYS_RECV 10
40 #define SYS_SENDTO 11
41 #define SYS_RECVFROM 12
42 #define SYS_SHUTDOWN 13
43 #define SYS_SETSOCKOPT 14
44 #define SYS_GETSOCKOPT 15
45
46
47 typedef enum {
48 SS_FREE = 0,
49 SS_UNCONNECTED,
50 SS_CONNECTING,
51 SS_CONNECTED,
52 SS_DISCONNECTING
53 } socket_state;
54
55 #define SO_ACCEPTCON (1<<16)
56
57 #ifdef __KERNEL__
58
59
60
61
62
63
64
65
66
67
68
69 struct socket {
70 short type;
71 socket_state state;
72 long flags;
73 struct proto_ops *ops;
74 void *data;
75 struct socket *conn;
76 struct socket *iconn;
77 struct socket *next;
78 struct wait_queue **wait;
79 struct inode *inode;
80 struct fasync_struct *fasync_list;
81 };
82
83 #define SOCK_INODE(S) ((S)->inode)
84
85 struct proto_ops {
86 int family;
87
88 int (*create) (struct socket *sock, int protocol);
89 int (*dup) (struct socket *newsock, struct socket *oldsock);
90 int (*release) (struct socket *sock, struct socket *peer);
91 int (*bind) (struct socket *sock, struct sockaddr *umyaddr,
92 int sockaddr_len);
93 int (*connect) (struct socket *sock, struct sockaddr *uservaddr,
94 int sockaddr_len, int flags);
95 int (*socketpair) (struct socket *sock1, struct socket *sock2);
96 int (*accept) (struct socket *sock, struct socket *newsock,
97 int flags);
98 int (*getname) (struct socket *sock, struct sockaddr *uaddr,
99 int *usockaddr_len, int peer);
100 int (*read) (struct socket *sock, char *ubuf, int size,
101 int nonblock);
102 int (*write) (struct socket *sock, char *ubuf, int size,
103 int nonblock);
104 int (*select) (struct socket *sock, int sel_type,
105 select_table *wait);
106 int (*ioctl) (struct socket *sock, unsigned int cmd,
107 unsigned long arg);
108 int (*listen) (struct socket *sock, int len);
109 int (*send) (struct socket *sock, void *buff, int len, int nonblock,
110 unsigned flags);
111 int (*recv) (struct socket *sock, void *buff, int len, int nonblock,
112 unsigned flags);
113 int (*sendto) (struct socket *sock, void *buff, int len, int nonblock,
114 unsigned flags, struct sockaddr *, int addr_len);
115 int (*recvfrom) (struct socket *sock, void *buff, int len, int nonblock,
116 unsigned flags, struct sockaddr *, int *addr_len);
117 int (*shutdown) (struct socket *sock, int flags);
118 int (*setsockopt) (struct socket *sock, int level, int optname,
119 char *optval, int optlen);
120 int (*getsockopt) (struct socket *sock, int level, int optname,
121 char *optval, int *optlen);
122 int (*fcntl) (struct socket *sock, unsigned int cmd,
123 unsigned long arg);
124 };
125
126 struct net_proto {
127 char *name;
128 void (*init_func)(struct net_proto *);
129 };
130
131 extern int sock_awaitconn(struct socket *mysock, struct socket *servsock);
132 extern int sock_wake_async(struct socket *sock);
133 extern int sock_register(int family, struct proto_ops *ops);
134 extern int sock_unregister(int family);
135
136 #endif
137 #endif