socketcalls.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. #define __FORCE_GLIBC__
  2. #include <features.h>
  3. #include <errno.h>
  4. #include <syscall.h>
  5. #include <sys/socket.h>
  6. #include <sys/socketcall.h>
  7. extern int socketcall(int call, unsigned long *args);
  8. #ifdef L_accept
  9. int accept(int s, struct sockaddr *addr, socklen_t * addrlen)
  10. {
  11. unsigned long args[3];
  12. args[0] = s;
  13. args[1] = (unsigned long) addr;
  14. args[2] = (unsigned long) addrlen;
  15. return socketcall(SYS_ACCEPT, args);
  16. }
  17. #endif
  18. #ifdef L_bind
  19. int bind(int sockfd, const struct sockaddr *myaddr, socklen_t addrlen)
  20. {
  21. unsigned long args[3];
  22. args[0] = sockfd;
  23. args[1] = (unsigned long) myaddr;
  24. args[2] = addrlen;
  25. return socketcall(SYS_BIND, args);
  26. }
  27. #endif
  28. #ifdef L_connect
  29. int connect(int sockfd, const struct sockaddr *saddr, socklen_t addrlen)
  30. {
  31. unsigned long args[3];
  32. args[0] = sockfd;
  33. args[1] = (unsigned long) saddr;
  34. args[2] = addrlen;
  35. return socketcall(SYS_CONNECT, args);
  36. }
  37. #endif
  38. #ifdef L_getpeername
  39. int getpeername(int sockfd, struct sockaddr *addr, socklen_t * paddrlen)
  40. {
  41. unsigned long args[3];
  42. args[0] = sockfd;
  43. args[1] = (unsigned long) addr;
  44. args[2] = (unsigned long) paddrlen;
  45. return socketcall(SYS_GETPEERNAME, args);
  46. }
  47. #endif
  48. #ifdef L_getsockname
  49. int getsockname(int sockfd, struct sockaddr *addr, socklen_t * paddrlen)
  50. {
  51. unsigned long args[3];
  52. args[0] = sockfd;
  53. args[1] = (unsigned long) addr;
  54. args[2] = (unsigned long) paddrlen;
  55. return socketcall(SYS_GETSOCKNAME, args);
  56. }
  57. #endif
  58. #ifdef L_getsockopt
  59. int getsockopt(int fd, int level, int optname, __ptr_t optval,
  60. socklen_t * optlen)
  61. {
  62. unsigned long args[5];
  63. args[0] = fd;
  64. args[1] = level;
  65. args[2] = optname;
  66. args[3] = (unsigned long) optval;
  67. args[4] = (unsigned long) optlen;
  68. return (socketcall(SYS_GETSOCKOPT, args));
  69. }
  70. #endif
  71. #ifdef L_listen
  72. int listen(int sockfd, unsigned int backlog)
  73. {
  74. unsigned long args[2];
  75. args[0] = sockfd;
  76. args[1] = backlog;
  77. return socketcall(SYS_LISTEN, args);
  78. }
  79. #endif
  80. #ifdef L_recv
  81. /* recv, recvfrom added by bir7@leland.stanford.edu */
  82. int recv(int sockfd, __ptr_t buffer, size_t len, int flags)
  83. {
  84. unsigned long args[4];
  85. args[0] = sockfd;
  86. args[1] = (unsigned long) buffer;
  87. args[2] = len;
  88. args[3] = flags;
  89. return (socketcall(SYS_RECV, args));
  90. }
  91. #endif
  92. #ifdef L_recvfrom
  93. /* recv, recvfrom added by bir7@leland.stanford.edu */
  94. int recvfrom(int sockfd, __ptr_t buffer, size_t len, int flags,
  95. struct sockaddr *to, socklen_t * tolen)
  96. {
  97. unsigned long args[6];
  98. args[0] = sockfd;
  99. args[1] = (unsigned long) buffer;
  100. args[2] = len;
  101. args[3] = flags;
  102. args[4] = (unsigned long) to;
  103. args[5] = (unsigned long) tolen;
  104. return (socketcall(SYS_RECVFROM, args));
  105. }
  106. #endif
  107. #ifdef L_recvmsg
  108. int recvmsg(int sockfd, struct msghdr *msg, int flags)
  109. {
  110. unsigned long args[3];
  111. args[0] = sockfd;
  112. args[1] = (unsigned long) msg;
  113. args[2] = flags;
  114. return (socketcall(SYS_RECVMSG, args));
  115. }
  116. #endif
  117. #ifdef L_send
  118. /* send, sendto added by bir7@leland.stanford.edu */
  119. int send(int sockfd, const void *buffer, size_t len, int flags)
  120. {
  121. unsigned long args[4];
  122. args[0] = sockfd;
  123. args[1] = (unsigned long) buffer;
  124. args[2] = len;
  125. args[3] = flags;
  126. return (socketcall(SYS_SEND, args));
  127. }
  128. #endif
  129. #ifdef L_sendmsg
  130. int sendmsg(int sockfd, const struct msghdr *msg, int flags)
  131. {
  132. unsigned long args[3];
  133. args[0] = sockfd;
  134. args[1] = (unsigned long) msg;
  135. args[2] = flags;
  136. return (socketcall(SYS_SENDMSG, args));
  137. }
  138. #endif
  139. #ifdef L_sendto
  140. /* send, sendto added by bir7@leland.stanford.edu */
  141. int sendto(int sockfd, const void *buffer, size_t len, int flags,
  142. const struct sockaddr *to, socklen_t tolen)
  143. {
  144. unsigned long args[6];
  145. args[0] = sockfd;
  146. args[1] = (unsigned long) buffer;
  147. args[2] = len;
  148. args[3] = flags;
  149. args[4] = (unsigned long) to;
  150. args[5] = tolen;
  151. return (socketcall(SYS_SENDTO, args));
  152. }
  153. #endif
  154. #ifdef L_setsockopt
  155. /* [sg]etsockoptions by bir7@leland.stanford.edu */
  156. int setsockopt(int fd, int level, int optname, const void *optval,
  157. socklen_t optlen)
  158. {
  159. unsigned long args[5];
  160. args[0] = fd;
  161. args[1] = level;
  162. args[2] = optname;
  163. args[3] = (unsigned long) optval;
  164. args[4] = optlen;
  165. return (socketcall(SYS_SETSOCKOPT, args));
  166. }
  167. #endif
  168. #ifdef L_shutdown
  169. /* shutdown by bir7@leland.stanford.edu */
  170. int shutdown(int sockfd, int how)
  171. {
  172. unsigned long args[2];
  173. args[0] = sockfd;
  174. args[1] = how;
  175. return (socketcall(SYS_SHUTDOWN, args));
  176. }
  177. #endif
  178. #ifdef L_socket
  179. int socket(int family, int type, int protocol)
  180. {
  181. unsigned long args[3];
  182. args[0] = family;
  183. args[1] = type;
  184. args[2] = (unsigned long) protocol;
  185. return socketcall(SYS_SOCKET, args);
  186. }
  187. #endif
  188. #ifdef L_socketpair
  189. int socketpair(int family, int type, int protocol, int sockvec[2])
  190. {
  191. unsigned long args[4];
  192. args[0] = family;
  193. args[1] = type;
  194. args[2] = protocol;
  195. args[3] = (unsigned long) sockvec;
  196. return socketcall(SYS_SOCKETPAIR, args);
  197. }
  198. #endif