xref: /haiku/src/add-ons/kernel/file_systems/nfs/ksocket.h (revision 1e36cfc2721ef13a187c6f7354dc9cbc485e89d3)
1 /*
2  * kernel-level support for sockets, includes userland support as well for testing.
3  * François Revol.
4  */
5 
6 #ifndef _KSOCKET_H
7 #define _KSOCKET_H
8 
9 #include <sys/socket.h>
10 
11 #ifndef _KERNEL_MODE /* userland wrapper */
12 
13 #define ksocket socket
14 #define kbind bind
15 #define kconnect connect
16 #define kgetsockname getsockname
17 #define kgetpeername getpeername
18 #define kaccept accept
19 #define ksendmsg sendmsg
20 #define krecvmsg recvmsg
21 #define krecvfrom recvfrom
22 #define ksendto sendto
23 #define krecv recv
24 #define ksend send
25 #define klisten listen
26 #define kshutdown shutdown
27 #define kclosesocket close
28 #define ksocket_init() ({B_OK;})
29 #define ksocket_cleanup() ({B_OK;})
30 #define kmessage(fmt, ...) printf(fmt "\n", ##__VA_ARGS__)
31 #define KSOCKET_MODULE_DECL /* nothing */
32 
33 #elif defined(__HAIKU__)
34 
35 /* Haiku socket module */
36 #include <os/drivers/socket_interface.h>
37 
38 extern struct socket_module_info *gSocket;
39 #define ksocket (gSocket->socket)
40 #define kbind (gSocket->bind)
41 #define kconnect (gSocket->connect)
42 #define kgetsockname (gSocket->getsockname)
43 #define kgetpeername (gSocket->getpeername)
44 #define kaccept (gSocket->accept)
45 //#define kaccept(_fd, _addr, _sz) ({int thesock; thesock = (gSocket->accept)(_fd, _addr, _sz); dprintf("kaccept(%d, , ) = %d\n", _fd, thesock); thesock; })
46 #define ksendmsg (gSocket->sendmsg)
47 #define krecvmsg (gSocket->recvmsg)
48 #define krecvfrom (gSocket->recvfrom)
49 #define ksendto (gSocket->sendto)
50 #define krecv (gSocket->recv)
51 #define ksend (gSocket->send)
52 #define klisten (gSocket->listen)
53 #define kshutdown (gSocket->shutdown)
54 #define kclosesocket close
55 #define kmessage(fmt, ...) dprintf("ksocket: " fmt "\n", ##__VA_ARGS__)
56 
57 extern status_t ksocket_init (void);
58 extern status_t ksocket_cleanup (void);
59 
60 #define KSOCKET_MODULE_DECL \
61 struct socket_module_info *gSocket; \
62 status_t ksocket_init (void) { \
63 	return get_module(B_SOCKET_MODULE_NAME, (module_info **)&gSocket); \
64 } \
65  \
66 status_t ksocket_cleanup (void) { \
67 	return put_module(B_SOCKET_MODULE_NAME); \
68 }
69 
70 #elif defined(BONE_VERSION)
71 
72 /* BONE socket module */
73 #include <sys/socket_module.h>
74 
75 extern bone_socket_info_t *gSocket;
76 #define ksocket (gSocket->socket)
77 //#define ksocket(_fam, _typ, _pro) ({int thesock; thesock = (gSocket->socket)(_fam, _typ, _pro); dprintf("ksocket(%d, %d, %d) = %d\n", _fam, _typ, _pro, thesock); thesock;})
78 #define kbind (gSocket->bind)
79 #define kconnect (gSocket->connect)
80 #define kgetsockname (gSocket->getsockname)
81 #define kgetpeername (gSocket->getpeername)
82 #define kaccept (gSocket->accept)
83 //#define kaccept(_fd, _addr, _sz) ({int thesock; thesock = (gSocket->accept)(_fd, _addr, _sz); dprintf("kaccept(%d, , ) = %d\n", _fd, thesock); thesock; })
84 #define ksendmsg _ERROR_no_sendmsg_in_BONE
85 #define krecvmsg _ERROR_no_recvmsg_in_BONE
86 #define krecvfrom (gSocket->recvfrom)
87 #define ksendto (gSocket->sendto)
88 #define krecv (gSocket->recv)
89 #define ksend (gSocket->send)
90 #define klisten (gSocket->listen)
91 #define kshutdown (gSocket->shutdown)
92 #define kclosesocket close
93 #define kmessage(fmt, ...) dprintf("ksocket: " fmt "\n", ##__VA_ARGS__)
94 
95 extern status_t ksocket_init (void);
96 extern status_t ksocket_cleanup (void);
97 
98 #define KSOCKET_MODULE_DECL \
99 bone_socket_info_t *gSocket; \
100 status_t ksocket_init (void) { \
101 	return get_module(BONE_SOCKET_MODULE, (module_info **)&gSocket); \
102 } \
103  \
104 status_t ksocket_cleanup (void) { \
105 	return put_module(BONE_SOCKET_MODULE); \
106 }
107 
108 #else /* _KERNEL_MODE, !BONE_VERSION */
109 
110 #error feel free to put back ksocketd support if you dare
111 
112 #endif /* _KERNEL_MODE, BONE_VERSION */
113 
114 #endif /* _KSOCKET_H */
115