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 #define ksocket socket
37 #define kconnect connect
38 #define kgetsockname getsockname
39 #define kgetpeername getpeername
40 #define kaccept accept
41 #define ksendmsg sendmsg
42 #define krecvmsg recvmsg
43 #define krecvfrom recvfrom
44 #define ksendto sendto
47 #define klisten listen
48 #define kshutdown shutdown
49 #define kclosesocket close
50 #define ksocket_init() ({B_OK;})
51 #define ksocket_cleanup() ({B_OK;})
52 #define kmessage(fmt, ...) printf(fmt "\n", ##__VA_ARGS__)
53 #define KSOCKET_MODULE_DECL /* nothing */
55 #elif defined(BONE_VERSION)
57 /* BONE socket module */
58 #include <sys/socket_module.h>
60 extern bone_socket_info_t
*gSocket
;
61 #define ksocket (gSocket->socket)
62 //#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;})
63 #define kbind (gSocket->bind)
64 #define kconnect (gSocket->connect)
65 #define kgetsockname (gSocket->getsockname)
66 #define kgetpeername (gSocket->getpeername)
67 #define kaccept (gSocket->accept)
68 //#define kaccept(_fd, _addr, _sz) ({int thesock; thesock = (gSocket->accept)(_fd, _addr, _sz); dprintf("kaccept(%d, , ) = %d\n", _fd, thesock); thesock; })
69 #define ksendmsg _ERROR_no_sendmsg_in_BONE
70 #define krecvmsg _ERROR_no_recvmsg_in_BONE
71 #define krecvfrom (gSocket->recvfrom)
72 #define ksendto (gSocket->sendto)
73 #define krecv (gSocket->recv)
74 #define ksend (gSocket->send)
75 #define klisten (gSocket->listen)
76 #define kshutdown (gSocket->shutdown)
77 #define kclosesocket close
78 #define kmessage(fmt, ...) dprintf("ksocket: " fmt "\n", ##__VA_ARGS__)
80 extern status_t
ksocket_init ();
81 extern status_t
ksocket_cleanup ();
83 #define KSOCKET_MODULE_DECL \
84 bone_socket_info_t *gSocket; \
85 status_t ksocket_init () { \
86 return get_module(BONE_SOCKET_MODULE, (module_info **)&gSocket); \
89 status_t ksocket_cleanup () { \
90 return put_module(BONE_SOCKET_MODULE); \
93 #else /* _KERNEL_MODE, !BONE_VERSION */
95 #error feel free to put back ksocketd support if you dare
97 #endif /* _KERNEL_MODE, BONE_VERSION */
99 #endif /* _KSOCKET_H */