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 112740b98dSFranç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 192740b98dSFrançois Revol #define ksendmsg sendmsg 202740b98dSFranç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 332740b98dSFrançois Revol #elif defined(__HAIKU__) 342740b98dSFrançois Revol 352740b98dSFrançois Revol /* Haiku socket module */ 362740b98dSFrançois Revol #include <os/drivers/socket_interface.h> 372740b98dSFrançois Revol 382740b98dSFrançois Revol extern struct socket_module_info *gSocket; 392740b98dSFrançois Revol #define ksocket (gSocket->socket) 402740b98dSFrançois Revol #define kbind (gSocket->bind) 412740b98dSFrançois Revol #define kconnect (gSocket->connect) 422740b98dSFrançois Revol #define kgetsockname (gSocket->getsockname) 432740b98dSFrançois Revol #define kgetpeername (gSocket->getpeername) 442740b98dSFrançois Revol #define kaccept (gSocket->accept) 452740b98dSFrançois Revol //#define kaccept(_fd, _addr, _sz) ({int thesock; thesock = (gSocket->accept)(_fd, _addr, _sz); dprintf("kaccept(%d, , ) = %d\n", _fd, thesock); thesock; }) 462740b98dSFrançois Revol #define ksendmsg (gSocket->sendmsg) 472740b98dSFrançois Revol #define krecvmsg (gSocket->recvmsg) 482740b98dSFrançois Revol #define krecvfrom (gSocket->recvfrom) 492740b98dSFrançois Revol #define ksendto (gSocket->sendto) 502740b98dSFrançois Revol #define krecv (gSocket->recv) 512740b98dSFrançois Revol #define ksend (gSocket->send) 522740b98dSFrançois Revol #define klisten (gSocket->listen) 532740b98dSFrançois Revol #define kshutdown (gSocket->shutdown) 542740b98dSFrançois Revol #define kclosesocket close 552740b98dSFrançois Revol #define kmessage(fmt, ...) dprintf("ksocket: " fmt "\n", ##__VA_ARGS__) 562740b98dSFrançois Revol 57*caa76e0dSFrançois Revol extern status_t ksocket_init (void); 58*caa76e0dSFrançois Revol extern status_t ksocket_cleanup (void); 592740b98dSFrançois Revol 602740b98dSFrançois Revol #define KSOCKET_MODULE_DECL \ 612740b98dSFrançois Revol struct socket_module_info *gSocket; \ 62*caa76e0dSFrançois Revol status_t ksocket_init (void) { \ 632740b98dSFrançois Revol return get_module(B_SOCKET_MODULE_NAME, (module_info **)&gSocket); \ 642740b98dSFrançois Revol } \ 652740b98dSFrançois Revol \ 66*caa76e0dSFrançois Revol status_t ksocket_cleanup (void) { \ 672740b98dSFrançois Revol return put_module(B_SOCKET_MODULE_NAME); \ 682740b98dSFrançois Revol } 692740b98dSFranç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; }) 842740b98dSFrançois Revol #define ksendmsg _ERROR_no_sendmsg_in_BONE 852740b98dSFranç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 95*caa76e0dSFrançois Revol extern status_t ksocket_init (void); 96*caa76e0dSFrançois Revol extern status_t ksocket_cleanup (void); 97f4783a9fSFrançois Revol 98f4783a9fSFrançois Revol #define KSOCKET_MODULE_DECL \ 99f4783a9fSFrançois Revol bone_socket_info_t *gSocket; \ 100*caa76e0dSFrançois Revol status_t ksocket_init (void) { \ 101f4783a9fSFrançois Revol return get_module(BONE_SOCKET_MODULE, (module_info **)&gSocket); \ 102f4783a9fSFrançois Revol } \ 103f4783a9fSFrançois Revol \ 104*caa76e0dSFrançois Revol status_t ksocket_cleanup (void) { \ 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