socket.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #pragma once
  27. #include <bits/stdint.h>
  28. #include <sys/cdefs.h>
  29. #include <sys/types.h>
  30. #include <sys/un.h>
  31. __BEGIN_DECLS
  32. #define AF_MASK 0xff
  33. #define AF_UNSPEC 0
  34. #define AF_LOCAL 1
  35. #define AF_UNIX AF_LOCAL
  36. #define AF_INET 2
  37. #define PF_LOCAL AF_LOCAL
  38. #define PF_UNIX PF_LOCAL
  39. #define PF_INET AF_INET
  40. #define PF_UNSPEC AF_UNSPEC
  41. #define SOCK_TYPE_MASK 0xff
  42. #define SOCK_STREAM 1
  43. #define SOCK_DGRAM 2
  44. #define SOCK_RAW 3
  45. #define SOCK_NONBLOCK 04000
  46. #define SOCK_CLOEXEC 02000000
  47. #define SHUT_RD 1
  48. #define SHUT_WR 2
  49. #define SHUT_RDWR 3
  50. #define IPPROTO_IP 0
  51. #define IPPROTO_ICMP 1
  52. #define IPPROTO_TCP 6
  53. #define IPPROTO_UDP 17
  54. #define MSG_DONTWAIT 0x40
  55. struct sockaddr {
  56. uint16_t sa_family;
  57. char sa_data[14];
  58. };
  59. struct ucred {
  60. pid_t pid;
  61. uid_t uid;
  62. gid_t gid;
  63. };
  64. #define SOL_SOCKET 1
  65. #define SOMAXCONN 128
  66. #define SO_RCVTIMEO 1
  67. #define SO_SNDTIMEO 2
  68. #define SO_TYPE 3
  69. #define SO_ERROR 4
  70. #define SO_PEERCRED 5
  71. #define SO_REUSEADDR 6
  72. #define SO_BINDTODEVICE 7
  73. #define SO_KEEPALIVE 9
  74. int socket(int domain, int type, int protocol);
  75. int bind(int sockfd, const struct sockaddr* addr, socklen_t);
  76. int listen(int sockfd, int backlog);
  77. int accept(int sockfd, struct sockaddr*, socklen_t*);
  78. int connect(int sockfd, const struct sockaddr*, socklen_t);
  79. int shutdown(int sockfd, int how);
  80. ssize_t send(int sockfd, const void*, size_t, int flags);
  81. ssize_t sendto(int sockfd, const void*, size_t, int flags, const struct sockaddr*, socklen_t);
  82. ssize_t recv(int sockfd, void*, size_t, int flags);
  83. ssize_t recvfrom(int sockfd, void*, size_t, int flags, struct sockaddr*, socklen_t*);
  84. int getsockopt(int sockfd, int level, int option, void*, socklen_t*);
  85. int setsockopt(int sockfd, int level, int option, const void*, socklen_t);
  86. int getsockname(int sockfd, struct sockaddr*, socklen_t*);
  87. int getpeername(int sockfd, struct sockaddr*, socklen_t*);
  88. __END_DECLS