2 * kernel-level support for sockets, includes userland support as well for testing.
9 #include <sys/socket.h>
11 #ifndef _KERNEL_MODE /* userland wrapper */
13 #define ksocket socket
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
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 */
33 #elif defined(__HAIKU__)
35 /* Haiku now has kernel calls for those, no need for a socket module anymore. */
37 #define ksocket socket
39 #define kconnect connect
40 #define kgetsockname getsockname
41 #define kgetpeername getpeername
42 #define kaccept accept
43 #define ksendmsg sendmsg
44 #define krecvmsg recvmsg
45 #define krecvfrom recvfrom
46 #define ksendto sendto
49 #define klisten listen
50 #define kshutdown shutdown
51 #define kclosesocket close
52 #define ksocket_init() ({B_OK;})
53 #define ksocket_cleanup() ({B_OK;})
54 #define kmessage(fmt, ...) dprintf(fmt "\n", ##__VA_ARGS__)
55 #define KSOCKET_MODULE_DECL /* nothing */
57 #elif defined(BONE_VERSION)
59 /* BONE socket module */
60 #include <sys/socket_module.h>
62 extern bone_socket_info_t
*gSocket
;
63 #define ksocket (gSocket->socket)
64 //#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;})
65 #define kbind (gSocket->bind)
66 #define kconnect (gSocket->connect)
67 #define kgetsockname (gSocket->getsockname)
68 #define kgetpeername (gSocket->getpeername)
69 #define kaccept (gSocket->accept)
70 //#define kaccept(_fd, _addr, _sz) ({int thesock; thesock = (gSocket->accept)(_fd, _addr, _sz); dprintf("kaccept(%d, , ) = %d\n", _fd, thesock); thesock; })
71 #define ksendmsg _ERROR_no_sendmsg_in_BONE
72 #define krecvmsg _ERROR_no_recvmsg_in_BONE
73 #define krecvfrom (gSocket->recvfrom)
74 #define ksendto (gSocket->sendto)
75 #define krecv (gSocket->recv)
76 #define ksend (gSocket->send)
77 #define klisten (gSocket->listen)
78 #define kshutdown (gSocket->shutdown)
79 #define kclosesocket close
80 #define kmessage(fmt, ...) dprintf("ksocket: " fmt "\n", ##__VA_ARGS__)
82 extern status_t
ksocket_init (void);
83 extern status_t
ksocket_cleanup (void);
85 #define KSOCKET_MODULE_DECL \
86 bone_socket_info_t *gSocket; \
87 status_t ksocket_init (void) { \
88 return get_module(BONE_SOCKET_MODULE, (module_info **)&gSocket); \
91 status_t ksocket_cleanup (void) { \
92 return put_module(BONE_SOCKET_MODULE); \
95 #else /* _KERNEL_MODE, !BONE_VERSION */
97 #error feel free to put back ksocketd support if you dare
99 #endif /* _KERNEL_MODE, BONE_VERSION */
101 #endif /* _KSOCKET_H */