errors_freebsd.odin 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. //+build freebsd
  2. package net
  3. /*
  4. Package net implements cross-platform Berkeley Sockets, DNS resolution and associated procedures.
  5. For other protocols and their features, see subdirectories of this package.
  6. */
  7. /*
  8. Copyright 2022 Tetralux <[email protected]>
  9. Copyright 2022 Colin Davidson <[email protected]>
  10. Copyright 2022 Jeroen van Rijn <[email protected]>.
  11. Copyright 2024 Feoramund <[email protected]>.
  12. Made available under Odin's BSD-3 license.
  13. List of contributors:
  14. Tetralux: Initial implementation
  15. Colin Davidson: Linux platform code, OSX platform code, Odin-native DNS resolver
  16. Jeroen van Rijn: Cross platform unification, code style, documentation
  17. Feoramund: FreeBSD platform code
  18. */
  19. import "core:c"
  20. import "core:sys/freebsd"
  21. Create_Socket_Error :: enum c.int {
  22. None = 0,
  23. Access_Denied = cast(c.int)freebsd.Errno.EACCES,
  24. Family_Not_Supported_For_This_Socket = cast(c.int)freebsd.Errno.EAFNOSUPPORT,
  25. Full_Per_Process_Descriptor_Table = cast(c.int)freebsd.Errno.EMFILE,
  26. Full_System_File_Table = cast(c.int)freebsd.Errno.ENFILE,
  27. No_Buffer_Space_Available = cast(c.int)freebsd.Errno.ENOBUFS,
  28. Insufficient_Permission = cast(c.int)freebsd.Errno.EPERM,
  29. Protocol_Unsupported_In_Family = cast(c.int)freebsd.Errno.EPROTONOSUPPORT,
  30. Socket_Type_Unsupported_By_Protocol = cast(c.int)freebsd.Errno.EPROTOTYPE,
  31. }
  32. Dial_Error :: enum c.int {
  33. None = 0,
  34. Port_Required = -1,
  35. Not_Descriptor = cast(c.int)freebsd.Errno.EBADF,
  36. Invalid_Namelen = cast(c.int)freebsd.Errno.EINVAL,
  37. Not_Socket = cast(c.int)freebsd.Errno.ENOTSOCK,
  38. Address_Unavailable = cast(c.int)freebsd.Errno.EADDRNOTAVAIL,
  39. Wrong_Family_For_Socket = cast(c.int)freebsd.Errno.EAFNOSUPPORT,
  40. Already_Connected = cast(c.int)freebsd.Errno.EISCONN,
  41. Timeout = cast(c.int)freebsd.Errno.ETIMEDOUT,
  42. Refused_By_Remote_Host = cast(c.int)freebsd.Errno.ECONNREFUSED,
  43. // `Refused` alias for `core:net` tests.
  44. // The above default name `Refused_By_Remote_Host` is more explicit.
  45. Refused = Refused_By_Remote_Host,
  46. Reset_By_Remote_Host = cast(c.int)freebsd.Errno.ECONNRESET,
  47. Network_Unreachable = cast(c.int)freebsd.Errno.ENETUNREACH,
  48. Host_Unreachable = cast(c.int)freebsd.Errno.EHOSTUNREACH,
  49. Address_In_Use = cast(c.int)freebsd.Errno.EADDRINUSE,
  50. Invalid_Address_Space = cast(c.int)freebsd.Errno.EFAULT,
  51. In_Progress = cast(c.int)freebsd.Errno.EINPROGRESS,
  52. Interrupted_By_Signal = cast(c.int)freebsd.Errno.EINTR,
  53. Previous_Attempt_Incomplete = cast(c.int)freebsd.Errno.EALREADY,
  54. Broadcast_Unavailable = cast(c.int)freebsd.Errno.EACCES,
  55. Auto_Port_Unavailable = cast(c.int)freebsd.Errno.EAGAIN,
  56. // NOTE: There are additional connect() error possibilities, but they are
  57. // strictly for addresses in the UNIX domain.
  58. }
  59. Bind_Error :: enum c.int {
  60. None = 0,
  61. Kernel_Resources_Unavailable = cast(c.int)freebsd.Errno.EAGAIN,
  62. Not_Descriptor = cast(c.int)freebsd.Errno.EBADF,
  63. // NOTE: bind() can also return EINVAL if the underlying `addrlen` is an
  64. // invalid length for the address family. This shouldn't happen for the net
  65. // package, but it's worth noting.
  66. Already_Bound = cast(c.int)freebsd.Errno.EINVAL,
  67. Not_Socket = cast(c.int)freebsd.Errno.ENOTSOCK,
  68. Given_Nonlocal_Address = cast(c.int)freebsd.Errno.EADDRNOTAVAIL,
  69. Address_In_Use = cast(c.int)freebsd.Errno.EADDRINUSE,
  70. Address_Family_Mismatch = cast(c.int)freebsd.Errno.EAFNOSUPPORT,
  71. Protected_Address = cast(c.int)freebsd.Errno.EACCES,
  72. Invalid_Address_Space = cast(c.int)freebsd.Errno.EFAULT,
  73. // NOTE: There are additional bind() error possibilities, but they are
  74. // strictly for addresses in the UNIX domain.
  75. }
  76. Listen_Error :: enum c.int {
  77. None = 0,
  78. Not_Descriptor = cast(c.int)freebsd.Errno.EBADF,
  79. Socket_Not_Bound = cast(c.int)freebsd.Errno.EDESTADDRREQ,
  80. Already_Connected = cast(c.int)freebsd.Errno.EINVAL,
  81. Not_Socket = cast(c.int)freebsd.Errno.ENOTSOCK,
  82. Listening_Not_Supported_For_This_Socket = cast(c.int)freebsd.Errno.EOPNOTSUPP,
  83. }
  84. Accept_Error :: enum c.int {
  85. None = 0,
  86. Not_Descriptor = cast(c.int)freebsd.Errno.EBADF,
  87. Interrupted = cast(c.int)freebsd.Errno.EINTR,
  88. Full_Per_Process_Descriptor_Table = cast(c.int)freebsd.Errno.EMFILE,
  89. Full_System_File_Table = cast(c.int)freebsd.Errno.ENFILE,
  90. Not_Socket = cast(c.int)freebsd.Errno.ENOTSOCK,
  91. Listen_Not_Called_On_Socket_Yet = cast(c.int)freebsd.Errno.EINVAL,
  92. Address_Not_Writable = cast(c.int)freebsd.Errno.EFAULT,
  93. // NOTE: This is the same as EWOULDBLOCK.
  94. No_Connections_Available = cast(c.int)freebsd.Errno.EAGAIN,
  95. // `Would_Block` alias for `core:net` tests.
  96. Would_Block = cast(c.int)freebsd.Errno.EAGAIN,
  97. New_Connection_Aborted = cast(c.int)freebsd.Errno.ECONNABORTED,
  98. }
  99. TCP_Recv_Error :: enum c.int {
  100. None = 0,
  101. Not_Descriptor = cast(c.int)freebsd.Errno.EBADF,
  102. Connection_Closed = cast(c.int)freebsd.Errno.ECONNRESET,
  103. Not_Connected = cast(c.int)freebsd.Errno.ENOTCONN,
  104. Not_Socket = cast(c.int)freebsd.Errno.ENOTSOCK,
  105. // NOTE(Feoramund): The next two errors are only relevant for recvmsg(),
  106. // but I'm including them for completeness's sake.
  107. Full_Table_And_Pending_Data = cast(c.int)freebsd.Errno.EMFILE,
  108. Invalid_Message_Size = cast(c.int)freebsd.Errno.EMSGSIZE,
  109. Timeout = cast(c.int)freebsd.Errno.EAGAIN,
  110. Interrupted_By_Signal = cast(c.int)freebsd.Errno.EINTR,
  111. Buffer_Pointer_Outside_Address_Space = cast(c.int)freebsd.Errno.EFAULT,
  112. }
  113. UDP_Recv_Error :: enum c.int {
  114. None = 0,
  115. Not_Descriptor = cast(c.int)freebsd.Errno.EBADF,
  116. Connection_Closed = cast(c.int)freebsd.Errno.ECONNRESET,
  117. Not_Connected = cast(c.int)freebsd.Errno.ENOTCONN,
  118. Not_Socket = cast(c.int)freebsd.Errno.ENOTSOCK,
  119. // NOTE(Feoramund): The next two errors are only relevant for recvmsg(),
  120. // but I'm including them for completeness's sake.
  121. Full_Table_And_Data_Discarded = cast(c.int)freebsd.Errno.EMFILE,
  122. Invalid_Message_Size = cast(c.int)freebsd.Errno.EMSGSIZE,
  123. Timeout = cast(c.int)freebsd.Errno.EAGAIN,
  124. Interrupted_By_Signal = cast(c.int)freebsd.Errno.EINTR,
  125. Buffer_Pointer_Outside_Address_Space = cast(c.int)freebsd.Errno.EFAULT,
  126. }
  127. TCP_Send_Error :: enum c.int {
  128. None = 0,
  129. Connection_Closed = cast(c.int)freebsd.Errno.ECONNRESET,
  130. Not_Descriptor = cast(c.int)freebsd.Errno.EBADF,
  131. Broadcast_Status_Mismatch = cast(c.int)freebsd.Errno.EACCES,
  132. Not_Connected = cast(c.int)freebsd.Errno.ENOTCONN,
  133. Not_Socket = cast(c.int)freebsd.Errno.ENOTSOCK,
  134. Argument_In_Invalid_Address_Space = cast(c.int)freebsd.Errno.EFAULT,
  135. Message_Size_Breaks_Atomicity = cast(c.int)freebsd.Errno.EMSGSIZE,
  136. /* The socket is marked non-blocking, or MSG_DONTWAIT is
  137. specified, and the requested operation would block. */
  138. Would_Block = cast(c.int)freebsd.Errno.EAGAIN,
  139. /* NOTE: This error arises for two distinct reasons:
  140. 1. The system was unable to allocate an internal buffer.
  141. The operation may succeed when buffers become available.
  142. 2. The output queue for a network interface was full.
  143. This generally indicates that the interface has stopped
  144. sending, but may be caused by transient congestion.
  145. */
  146. No_Buffer_Space_Available = cast(c.int)freebsd.Errno.ENOBUFS,
  147. Host_Unreachable = cast(c.int)freebsd.Errno.EHOSTUNREACH,
  148. Already_Connected = cast(c.int)freebsd.Errno.EISCONN,
  149. ICMP_Unreachable = cast(c.int)freebsd.Errno.ECONNREFUSED,
  150. Host_Down = cast(c.int)freebsd.Errno.EHOSTDOWN,
  151. Network_Down = cast(c.int)freebsd.Errno.ENETDOWN,
  152. Jailed_Socket_Tried_To_Escape = cast(c.int)freebsd.Errno.EADDRNOTAVAIL,
  153. Cannot_Send_More_Data = cast(c.int)freebsd.Errno.EPIPE,
  154. }
  155. // NOTE(Feoramund): The same as TCP errors go, as far as I'm aware.
  156. UDP_Send_Error :: distinct TCP_Send_Error
  157. Shutdown_Manner :: enum c.int {
  158. Receive = cast(c.int)freebsd.Shutdown_Method.RD,
  159. Send = cast(c.int)freebsd.Shutdown_Method.WR,
  160. Both = cast(c.int)freebsd.Shutdown_Method.RDWR,
  161. }
  162. Shutdown_Error :: enum c.int {
  163. None = 0,
  164. Not_Descriptor = cast(c.int)freebsd.Errno.EBADF,
  165. Invalid_Manner = cast(c.int)freebsd.Errno.EINVAL,
  166. Not_Connected = cast(c.int)freebsd.Errno.ENOTCONN,
  167. Not_Socket = cast(c.int)freebsd.Errno.ENOTSOCK,
  168. }
  169. Socket_Option_Error :: enum c.int {
  170. None = 0,
  171. Value_Out_Of_Range = -1,
  172. Not_Descriptor = cast(c.int)freebsd.Errno.EBADF,
  173. Not_Socket = cast(c.int)freebsd.Errno.ENOTSOCK,
  174. Unknown_Option_For_Level = cast(c.int)freebsd.Errno.ENOPROTOOPT,
  175. Argument_In_Invalid_Address_Space = cast(c.int)freebsd.Errno.EFAULT,
  176. // This error can arise for many different reasons.
  177. Invalid_Value = cast(c.int)freebsd.Errno.EINVAL,
  178. System_Memory_Allocation_Failed = cast(c.int)freebsd.Errno.ENOMEM,
  179. Insufficient_System_Resources = cast(c.int)freebsd.Errno.ENOBUFS,
  180. }
  181. Set_Blocking_Error :: enum c.int {
  182. None = 0,
  183. Not_Descriptor = cast(c.int)freebsd.Errno.EBADF,
  184. Wrong_Descriptor = cast(c.int)freebsd.Errno.ENOTTY,
  185. }