123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- #define __FORCE_GLIBC
- #include <features.h>
- #include <errno.h>
- #include <syscall.h>
- #include <sys/socket.h>
- #ifdef __NR_socketcall
- extern int __socketcall(int call, unsigned long *args) attribute_hidden;
- /* Various socketcall numbers */
- #define SYS_SOCKET 1
- #define SYS_BIND 2
- #define SYS_CONNECT 3
- #define SYS_LISTEN 4
- #define SYS_ACCEPT 5
- #define SYS_GETSOCKNAME 6
- #define SYS_GETPEERNAME 7
- #define SYS_SOCKETPAIR 8
- #define SYS_SEND 9
- #define SYS_RECV 10
- #define SYS_SENDTO 11
- #define SYS_RECVFROM 12
- #define SYS_SHUTDOWN 13
- #define SYS_SETSOCKOPT 14
- #define SYS_GETSOCKOPT 15
- #define SYS_SENDMSG 16
- #define SYS_RECVMSG 17
- #endif
- #ifdef L_accept
- #ifdef __NR_accept
- #define __NR___libc_accept __NR_accept
- _syscall3(int, __libc_accept, int, call, struct sockaddr *, addr, socklen_t *,addrlen);
- #elif defined(__NR_socketcall)
- int __libc_accept(int s, struct sockaddr *addr, socklen_t * addrlen)
- {
- unsigned long args[3];
- args[0] = s;
- args[1] = (unsigned long) addr;
- args[2] = (unsigned long) addrlen;
- return __socketcall(SYS_ACCEPT, args);
- }
- #endif
- hidden_weak_alias(__libc_accept,__accept)
- weak_alias(__libc_accept,accept)
- #endif
- #ifdef L_bind
- #ifdef __NR_bind
- #define __NR___bind __NR_bind
- attribute_hidden _syscall3(int, __bind, int, sockfd, const struct sockaddr *, myaddr, socklen_t, addrlen);
- #elif defined(__NR_socketcall)
- int attribute_hidden __bind(int sockfd, const struct sockaddr *myaddr, socklen_t addrlen)
- {
- unsigned long args[3];
- args[0] = sockfd;
- args[1] = (unsigned long) myaddr;
- args[2] = addrlen;
- return __socketcall(SYS_BIND, args);
- }
- #endif
- strong_alias(__bind,bind)
- #endif
- #ifdef L_connect
- #ifdef __NR_connect
- #define __NR___libc_connect __NR_connect
- _syscall3(int, __libc_connect, int, sockfd, const struct sockaddr *, saddr, socklen_t, addrlen);
- #elif defined(__NR_socketcall)
- int __libc_connect(int sockfd, const struct sockaddr *saddr, socklen_t addrlen)
- {
- unsigned long args[3];
- args[0] = sockfd;
- args[1] = (unsigned long) saddr;
- args[2] = addrlen;
- return __socketcall(SYS_CONNECT, args);
- }
- #endif
- hidden_weak_alias(__libc_connect,__connect)
- weak_alias(__libc_connect,connect)
- #endif
- #ifdef L_getpeername
- #ifdef __NR_getpeername
- _syscall3(int, getpeername, int, sockfd, struct sockaddr *, addr, socklen_t *,paddrlen);
- #elif defined(__NR_socketcall)
- int getpeername(int sockfd, struct sockaddr *addr, socklen_t * paddrlen)
- {
- unsigned long args[3];
- args[0] = sockfd;
- args[1] = (unsigned long) addr;
- args[2] = (unsigned long) paddrlen;
- return __socketcall(SYS_GETPEERNAME, args);
- }
- #endif
- #endif
- #ifdef L_getsockname
- #ifdef __NR_getsockname
- #define __NR___getsockname __NR_getsockname
- attribute_hidden _syscall3(int, __getsockname, int, sockfd, struct sockaddr *, addr, socklen_t *,paddrlen);
- #elif defined(__NR_socketcall)
- int attribute_hidden __getsockname(int sockfd, struct sockaddr *addr, socklen_t * paddrlen)
- {
- unsigned long args[3];
- args[0] = sockfd;
- args[1] = (unsigned long) addr;
- args[2] = (unsigned long) paddrlen;
- return __socketcall(SYS_GETSOCKNAME, args);
- }
- #endif
- strong_alias(__getsockname,getsockname)
- #endif
- #ifdef L_getsockopt
- #ifdef __NR_getsockopt
- _syscall5(int, getsockopt, int, fd, int, level, int, optname, __ptr_t, optval, socklen_t *, optlen);
- #elif defined(__NR_socketcall)
- int getsockopt(int fd, int level, int optname, __ptr_t optval,
- socklen_t * optlen)
- {
- unsigned long args[5];
- args[0] = fd;
- args[1] = level;
- args[2] = optname;
- args[3] = (unsigned long) optval;
- args[4] = (unsigned long) optlen;
- return (__socketcall(SYS_GETSOCKOPT, args));
- }
- #endif
- #endif
- #ifdef L_listen
- #ifdef __NR_listen
- #define __NR___listen __NR_listen
- attribute_hidden _syscall2(int, __listen, int, sockfd, int, backlog);
- #elif defined(__NR_socketcall)
- int attribute_hidden __listen(int sockfd, int backlog)
- {
- unsigned long args[2];
- args[0] = sockfd;
- args[1] = backlog;
- return __socketcall(SYS_LISTEN, args);
- }
- #endif
- strong_alias(__listen,listen)
- #endif
- #ifdef L_recv
- #ifdef __NR_recv
- #define __NR___libc_recv __NR_recv
- _syscall4(ssize_t, __libc_recv, int, sockfd, __ptr_t, buffer, size_t, len, int, flags);
- weak_alias(__libc_recv, recv);
- #elif defined(__NR_socketcall)
- /* recv, recvfrom added by bir7@leland.stanford.edu */
- ssize_t __libc_recv(int sockfd, __ptr_t buffer, size_t len, int flags)
- {
- unsigned long args[4];
- args[0] = sockfd;
- args[1] = (unsigned long) buffer;
- args[2] = len;
- args[3] = flags;
- return (__socketcall(SYS_RECV, args));
- }
- #elif defined(__NR_recvfrom)
- ssize_t __libc_recv(int sockfd, __ptr_t buffer, size_t len, int flags)
- {
- return (__recvfrom(sockfd, buffer, len, flags, NULL, NULL));
- }
- #endif
- hidden_weak_alias(__libc_recv,__recv)
- weak_alias(__libc_recv,recv)
- #endif
- #ifdef L_recvfrom
- #ifdef __NR_recvfrom
- #define __NR___libc_recvfrom __NR_recvfrom
- _syscall6(ssize_t, __libc_recvfrom, int, sockfd, __ptr_t, buffer, size_t, len, int, flags,
- struct sockaddr *, to, socklen_t *, tolen);
- #elif defined(__NR_socketcall)
- /* recv, recvfrom added by bir7@leland.stanford.edu */
- ssize_t __libc_recvfrom(int sockfd, __ptr_t buffer, size_t len, int flags,
- struct sockaddr *to, socklen_t * tolen)
- {
- unsigned long args[6];
- args[0] = sockfd;
- args[1] = (unsigned long) buffer;
- args[2] = len;
- args[3] = flags;
- args[4] = (unsigned long) to;
- args[5] = (unsigned long) tolen;
- return (__socketcall(SYS_RECVFROM, args));
- }
- #endif
- hidden_weak_alias(__libc_recvfrom,__recvfrom)
- weak_alias(__libc_recvfrom,recvfrom)
- #endif
- #ifdef L_recvmsg
- #ifdef __NR_recvmsg
- #define __NR___libc_recvmsg __NR_recvmsg
- _syscall3(ssize_t, __libc_recvmsg, int, sockfd, struct msghdr *, msg, int, flags);
- #elif defined(__NR_socketcall)
- ssize_t __libc_recvmsg(int sockfd, struct msghdr *msg, int flags)
- {
- unsigned long args[3];
- args[0] = sockfd;
- args[1] = (unsigned long) msg;
- args[2] = flags;
- return (__socketcall(SYS_RECVMSG, args));
- }
- #endif
- hidden_weak_alias(__libc_recvmsg,__recvmsg)
- weak_alias(__libc_recvmsg,recvmsg)
- #endif
- #ifdef L_send
- #ifdef __NR_send
- #define __NR___libc_send __NR_send
- _syscall4(ssize_t, __libc_send, int, sockfd, const void *, buffer, size_t, len, int, flags);
- #elif defined(__NR_socketcall)
- /* send, sendto added by bir7@leland.stanford.edu */
- ssize_t __libc_send(int sockfd, const void *buffer, size_t len, int flags)
- {
- unsigned long args[4];
- args[0] = sockfd;
- args[1] = (unsigned long) buffer;
- args[2] = len;
- args[3] = flags;
- return (__socketcall(SYS_SEND, args));
- }
- #elif defined(__NR_sendto)
- extern ssize_t __sendto (int __fd, __const void *__buf, size_t __n,
- int __flags, __CONST_SOCKADDR_ARG __addr,
- socklen_t __addr_len) attribute_hidden;
- ssize_t __libc_send(int sockfd, const void *buffer, size_t len, int flags)
- {
- return (__sendto(sockfd, buffer, len, flags, NULL, 0));
- }
- #endif
- hidden_weak_alias(__libc_send,__send)
- weak_alias(__libc_send,send)
- #endif
- #ifdef L_sendmsg
- #ifdef __NR_sendmsg
- #define __NR___libc_sendmsg __NR_sendmsg
- _syscall3(ssize_t, __libc_sendmsg, int, sockfd, const struct msghdr *, msg, int, flags);
- #elif defined(__NR_socketcall)
- ssize_t __libc_sendmsg(int sockfd, const struct msghdr *msg, int flags)
- {
- unsigned long args[3];
- args[0] = sockfd;
- args[1] = (unsigned long) msg;
- args[2] = flags;
- return (__socketcall(SYS_SENDMSG, args));
- }
- #endif
- hidden_weak_alias(__libc_sendmsg,__sendmsg)
- weak_alias(__libc_sendmsg,sendmsg)
- #endif
- #ifdef L_sendto
- #ifdef __NR_sendto
- #define __NR___libc_sendto __NR_sendto
- _syscall6(ssize_t, __libc_sendto, int, sockfd, const void *, buffer, size_t, len,
- int, flags, const struct sockaddr *, to, socklen_t, tolen);
- #elif defined(__NR_socketcall)
- /* send, sendto added by bir7@leland.stanford.edu */
- ssize_t __libc_sendto(int sockfd, const void *buffer, size_t len, int flags,
- const struct sockaddr *to, socklen_t tolen)
- {
- unsigned long args[6];
- args[0] = sockfd;
- args[1] = (unsigned long) buffer;
- args[2] = len;
- args[3] = flags;
- args[4] = (unsigned long) to;
- args[5] = tolen;
- return (__socketcall(SYS_SENDTO, args));
- }
- #endif
- hidden_weak_alias(__libc_sendto,__sendto)
- weak_alias(__libc_sendto,sendto)
- #endif
- #ifdef L_setsockopt
- #ifdef __NR_setsockopt
- #define __NR___setsockopt __NR_setsockopt
- attribute_hidden _syscall5(int, __setsockopt, int, fd, int, level, int, optname, const void *, optval, socklen_t, optlen);
- #elif defined(__NR_socketcall)
- /* [sg]etsockoptions by bir7@leland.stanford.edu */
- int attribute_hidden __setsockopt(int fd, int level, int optname, const void *optval,
- socklen_t optlen)
- {
- unsigned long args[5];
- args[0] = fd;
- args[1] = level;
- args[2] = optname;
- args[3] = (unsigned long) optval;
- args[4] = optlen;
- return (__socketcall(SYS_SETSOCKOPT, args));
- }
- #endif
- strong_alias(__setsockopt,setsockopt)
- #endif
- #ifdef L_shutdown
- #ifdef __NR_shutdown
- _syscall2(int, shutdown, int, sockfd, int, how);
- #elif defined(__NR_socketcall)
- /* shutdown by bir7@leland.stanford.edu */
- int shutdown(int sockfd, int how)
- {
- unsigned long args[2];
- args[0] = sockfd;
- args[1] = how;
- return (__socketcall(SYS_SHUTDOWN, args));
- }
- #endif
- #endif
- #ifdef L_socket
- #ifdef __NR_socket
- #define __NR___socket __NR_socket
- attribute_hidden _syscall3(int, __socket, int, family, int, type, int, protocol);
- #elif defined(__NR_socketcall)
- int attribute_hidden __socket(int family, int type, int protocol)
- {
- unsigned long args[3];
- args[0] = family;
- args[1] = type;
- args[2] = (unsigned long) protocol;
- return __socketcall(SYS_SOCKET, args);
- }
- #endif
- strong_alias(__socket,socket)
- #endif
- #ifdef L_socketpair
- #ifdef __NR_socketpair
- _syscall4(int, socketpair, int, family, int, type, int, protocol, int *, sockvec);
- #elif defined(__NR_socketcall)
- int socketpair(int family, int type, int protocol, int sockvec[2])
- {
- unsigned long args[4];
- args[0] = family;
- args[1] = type;
- args[2] = protocol;
- args[3] = (unsigned long) sockvec;
- return __socketcall(SYS_SOCKETPAIR, args);
- }
- #endif
- #endif
|