socketcalls.c 4.6 KB

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