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 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 krecvfrom recvfrom 20 #define ksendto sendto 21 #define krecv recv 22 #define ksend send 23 #define klisten listen 24 #define kshutdown shutdown 25 #define kclosesocket close 26 #define ksocket_init() ({B_OK;}) 27 #define ksocket_cleanup() ({B_OK;}) 28 #define kmessage(fmt, ...) printf(fmt "\n", ##__VA_ARGS__) 29 #define KSOCKET_MODULE_DECL /* nothing */ 30 31 #elif defined(BONE_VERSION) 32 33 /* BONE socket module */ 34 #include <sys/socket_module.h> 35 36 extern bone_socket_info_t *gSocket; 37 #define ksocket (gSocket->socket) 38 //#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;}) 39 #define kbind (gSocket->bind) 40 #define kconnect (gSocket->connect) 41 #define kgetsockname (gSocket->getsockname) 42 #define kgetpeername (gSocket->getpeername) 43 #define kaccept (gSocket->accept) 44 //#define kaccept(_fd, _addr, _sz) ({int thesock; thesock = (gSocket->accept)(_fd, _addr, _sz); dprintf("kaccept(%d, , ) = %d\n", _fd, thesock); thesock; }) 45 #define krecvfrom (gSocket->recvfrom) 46 #define ksendto (gSocket->sendto) 47 #define krecv (gSocket->recv) 48 #define ksend (gSocket->send) 49 #define klisten (gSocket->listen) 50 #define kshutdown (gSocket->shutdown) 51 #define kclosesocket close 52 #define kmessage(fmt, ...) dprintf("ksocket: " fmt "\n", ##__VA_ARGS__) 53 54 extern status_t ksocket_init (); 55 extern status_t ksocket_cleanup (); 56 57 #define KSOCKET_MODULE_DECL \ 58 bone_socket_info_t *gSocket; \ 59 status_t ksocket_init () { \ 60 return get_module(BONE_SOCKET_MODULE, (module_info **)&gSocket); \ 61 } \ 62 \ 63 status_t ksocket_cleanup () { \ 64 return put_module(BONE_SOCKET_MODULE); \ 65 } 66 67 #else /* _KERNEL_MODE, !BONE_VERSION */ 68 69 #error feel free to put back ksocketd support if you dare 70 71 #endif /* _KERNEL_MODE, BONE_VERSION */ 72 73 #endif /* _KSOCKET_H */ 74