1 #ifndef _KERN_SOCK_H
2 #define _KERN_SOCK_H
3 #undef SOCK_DEBUG
4 #define NSOCKETS 128
5
6 typedef enum {
7 SS_FREE = 0,
8 SS_UNCONNECTED,
9 SS_CONNECTING,
10 SS_CONNECTED,
11 SS_DISCONNECTING,
12 } socket_state;
13
14 #define SO_ACCEPTCON (1<<16)
15
16
17
18
19
20
21
22
23
24
25
26
27 struct socket {
28 short type;
29 socket_state state;
30 long flags;
31 struct proto_ops *ops;
32 void *data;
33 struct socket *conn;
34 struct socket *iconn;
35 struct socket *next;
36 struct wait_queue **wait;
37 void *dummy;
38 };
39
40 struct proto_ops {
41 int (*init)(void);
42 int (*create)(struct socket *sock, int protocol);
43 int (*dup)(struct socket *newsock, struct socket *oldsock);
44 int (*release)(struct socket *sock, struct socket *peer);
45 int (*bind)(struct socket *sock, struct sockaddr *umyaddr,
46 int sockaddr_len);
47 int (*connect)(struct socket *sock, struct sockaddr *uservaddr,
48 int sockaddr_len, int flags);
49 int (*socketpair)(struct socket *sock1, struct socket *sock2);
50 int (*accept)(struct socket *sock, struct socket *newsock, int flags);
51 int (*getname)(struct socket *sock, struct sockaddr *uaddr,
52 int *usockaddr_len, int peer);
53 int (*read)(struct socket *sock, char *ubuf, int size, int nonblock);
54 int (*write)(struct socket *sock, char *ubuf, int size, int nonblock);
55 int (*select)(struct socket *sock, int sel_type, select_table * wait);
56 int (*ioctl)(struct socket *sock, unsigned int cmd, unsigned long arg);
57 int (*listen)(struct socket *sock, int len);
58 int (*send)(struct socket *sock, void *buff, int len, int nonblock,
59 unsigned flags);
60 int (*recv)(struct socket *sock, void *buff, int len, int nonblock,
61 unsigned flags);
62 int (*sendto)(struct socket *sock, void *buff, int len, int nonblock,
63 unsigned flags, struct sockaddr *, int addr_len);
64 int (*recvfrom)(struct socket *sock, void *buff, int len, int nonblock,
65 unsigned flags, struct sockaddr *, int *addr_len);
66 int (*shutdown)(struct socket *sock, int flags);
67 int (*setsockopt)(struct socket *sock, int level, int optname,
68 char *optval, int optlen);
69 int (*getsockopt)(struct socket *sock, int level, int optname,
70 char *optval, int *optlen);
71 int (*fcntl) (struct socket *sock, unsigned int cmd,
72 unsigned long arg);
73 };
74
75 extern int sock_awaitconn(struct socket *mysock, struct socket *servsock);
76
77 #ifdef SOCK_DEBUG
78 #define PRINTK printk
79 #else
80 #define PRINTK (void)
81 #endif
82
83 #endif