socket.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #ifndef _SYS_SOCKET_H
  2. #define _SYS_SOCKET_H
  3. #include <features.h>
  4. #include <errno.h>
  5. #include <sys/types.h>
  6. #include <linux/socket.h>
  7. #ifdef _MIT_POSIX_THREADS
  8. #include <pthread/mit/posix.h>
  9. #endif
  10. __BEGIN_DECLS
  11. /* struct msghdr is not defined in linux 1.2. This will allow sendmsg
  12. and recvmsg in libc 5.2.9 to compile under 1.2.x and shouldn't cause
  13. any problem for 1.3.x */
  14. struct msghdr;
  15. /* Create a new socket of type TYPE in domain DOMAIN, using
  16. protocol PROTOCOL. If PROTOCOL is zero, one is chosen
  17. automatically. Returns a file descriptor for the new socket,
  18. or -1 for errors. */
  19. int socket __P ((int __family, int __type, int __protocol));
  20. /* Create two new sockets, of type TYPE in domain DOMAIN and using
  21. protocol PROTOCOL, which are connected to each other, and put file
  22. descriptors for them in FDS[0] and FDS[1]. If PROTOCOL is zero,
  23. one will be chosen automatically. Returns 0 on success, -1
  24. for errors. */
  25. int socketpair __P ((int __family, int __type, int __protocol,
  26. int __sockvec[2]));
  27. /* Give the socket FD the local address ADDR (which is LEN bytes
  28. long). */
  29. int bind __P ((int __sockfd, __const struct sockaddr *__my_addr,
  30. int __addrlen));
  31. /* Open a connection on socket FD to peer at ADDR (which LEN bytes
  32. long). For connectionless socket types, just set the default
  33. address to send to and the only address from which to accept
  34. transmissions. Return 0 on success, -1 for errors. */
  35. int connect __P ((int __sockfd, __const struct sockaddr *__serv_addr,
  36. int __addrlen));
  37. /* Prepare to accept connections on socket FD.
  38. N connection requests will be queued before further requests are
  39. refused. Returns 0 on success, -1 for errors. */
  40. int listen __P ((int __sockfd, int __n));
  41. /* Await a connection on socket FD.
  42. When a connection arrives, open a new socket to communicate with it,
  43. set *ADDR (which is *ADDR_LEN bytes long) to the address of the
  44. connecting peer and *ADDR_LEN to the address's actual length, and
  45. return the new socket's descriptor, or -1 for errors. */
  46. int accept __P ((int __sockfd, __const struct sockaddr *__peer,
  47. int *__paddrlen));
  48. /* Put the current value for socket FD's option OPTNAME at protocol
  49. level LEVEL into OPTVAL (which is *OPTLEN bytes long), and set
  50. *OPTLEN to the value's actual length. Returns 0 on success, -1 for
  51. errors. */
  52. int getsockopt __P ((int __s, int __level, int __optname,
  53. void *__optval, int *__optlen));
  54. /* Set socket FD's option OPTNAME at protocol level LEVEL
  55. to *OPTVAL (which is OPTLEN bytes long).
  56. Returns 0 on success, -1 for errors. */
  57. int setsockopt __P ((int __s, int __level, int __optname,
  58. __const void *__optval, int optlen));
  59. /* Put the local address of FD into *ADDR and its length in *LEN. */
  60. int getsockname __P ((int __sockfd, struct sockaddr *__addr,
  61. int *__paddrlen));
  62. /* Put the address of the peer connected to socket FD into *ADDR
  63. (which is *LEN bytes long), and its actual length into *LEN. */
  64. int getpeername __P ((int __sockfd, struct sockaddr *__peer,
  65. int *__paddrlen));
  66. /* Send N bytes of BUF to socket FD. Returns the number sent or -1. */
  67. int send __P ((int __sockfd, __const void *__buff, size_t __len,
  68. unsigned int __flags));
  69. /* Read N bytes into BUF from socket FD.
  70. Returns the number read or -1 for errors. */
  71. int recv __P ((int __sockfd, void *__buff, size_t __len,
  72. unsigned int __flags));
  73. /* Send N bytes of BUF on socket FD to peer at address ADDR (which is
  74. ADDR_LEN bytes long). Returns the number sent, or -1 for errors. */
  75. int sendto __P ((int __sockfd, __const void *__buff, size_t __len,
  76. unsigned int __flags, __const struct sockaddr *__to,
  77. int __tolen));
  78. /* Read N bytes into BUF through socket FD.
  79. If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address
  80. of the sender, and store the actual size of the address in
  81. *ADDR_LEN. Returns the number of bytes read or -1 for errors. */
  82. int recvfrom __P ((int __sockfd, void *__buff, size_t __len,
  83. unsigned int __flags, struct sockaddr *__from,
  84. int *__fromlen));
  85. /* Send a message described MESSAGE on socket FD.
  86. Returns the number of bytes sent, or -1 for errors. */
  87. extern int sendmsg __P ((int __fd, __const struct msghdr *__message,
  88. unsigned int __flags));
  89. /* Receive a message as described by MESSAGE from socket FD.
  90. Returns the number of bytes read or -1 for errors. */
  91. extern int recvmsg __P ((int __fd, struct msghdr *__message,
  92. unsigned int __flags));
  93. /* Shut down all or part of the connection open on socket FD.
  94. HOW determines what to shut down:
  95. 0 = No more receptions;
  96. 1 = No more transmissions;
  97. 2 = No more receptions or transmissions.
  98. Returns 0 on success, -1 for errors. */
  99. int shutdown __P ((int __sockfd, int __how));
  100. /* belongs here or elsewhere? */
  101. int rcmd __P ((char **__ahost, unsigned short __inport,
  102. __const char *__locuser, __const char *__remuser,
  103. __const char *__cmd, int *__fd2p));
  104. int rresvport __P ((int *__port));
  105. int ruserok __P ((__const char *__rhost, int __superuser,
  106. __const char *__ruser, __const char *__luser));
  107. int rexec __P ((char **__ahost, int __inport, __const char *__user,
  108. __const char *__passwd, __const char *__cmd,
  109. int *__fd2p));
  110. __END_DECLS
  111. #endif /* _SYS_SOCKET_H */