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