posix_linux_amd64.nim 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. #
  2. #
  3. # Nim's Runtime Library
  4. # (c) Copyright 2012 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. # Types here should conform to the glibc ABI on linux / x86_64
  10. # When adding a type, the order and size of fields must match
  11. # To be included from posix.nim!
  12. const
  13. hasSpawnH = not defined(haiku) # should exist for every Posix system nowadays
  14. hasAioH = defined(linux)
  15. # On Linux:
  16. # timer_{create,delete,settime,gettime},
  17. # clock_{getcpuclockid, getres, gettime, nanosleep, settime} lives in librt
  18. {.passl: "-lrt".}
  19. when defined(nimHasStyleChecks):
  20. {.push styleChecks: off.}
  21. # Types
  22. type
  23. DIR* {.importc: "DIR", header: "<dirent.h>",
  24. incompleteStruct.} = object
  25. ## A type representing a directory stream.
  26. type
  27. SocketHandle* = distinct cint # The type used to represent socket descriptors
  28. type
  29. Time* {.importc: "time_t", header: "<time.h>".} = distinct clong
  30. Timespec* {.importc: "struct timespec",
  31. header: "<time.h>", final, pure.} = object ## struct timespec
  32. tv_sec*: Time ## Seconds.
  33. tv_nsec*: clong ## Nanoseconds.
  34. Dirent* {.importc: "struct dirent",
  35. header: "<dirent.h>", final, pure.} = object ## dirent_t struct
  36. d_ino*: Ino
  37. d_off*: Off
  38. d_reclen*: cushort
  39. d_type*: int8 # uint8 really!
  40. d_name*: array[256, cchar]
  41. Tflock* {.importc: "struct flock", final, pure,
  42. header: "<fcntl.h>".} = object ## flock type
  43. l_type*: cshort ## Type of lock; F_RDLCK, F_WRLCK, F_UNLCK.
  44. l_whence*: cshort ## Flag for starting offset.
  45. l_start*: Off ## Relative offset in bytes.
  46. l_len*: Off ## Size; if 0 then until EOF.
  47. l_pid*: Pid ## Process ID of the process holding the lock;
  48. ## returned with F_GETLK.
  49. # no struct FTW on linux
  50. Glob* {.importc: "glob_t", header: "<glob.h>",
  51. final, pure.} = object ## glob_t
  52. gl_pathc*: csize_t ## Count of paths matched by pattern.
  53. gl_pathv*: cstringArray ## Pointer to a list of matched pathnames.
  54. gl_offs*: csize_t ## Slots to reserve at the beginning of gl_pathv.
  55. gl_flags*: cint
  56. gl_closedir*: pointer
  57. gl_readdir*: pointer
  58. gl_opendir*: pointer
  59. gl_lstat*: pointer
  60. gl_stat*: pointer
  61. Group* {.importc: "struct group", header: "<grp.h>",
  62. final, pure.} = object ## struct group
  63. gr_name*: cstring ## The name of the group.
  64. gr_passwd*: cstring
  65. gr_gid*: Gid ## Numerical group ID.
  66. gr_mem*: cstringArray ## Pointer to a null-terminated array of character
  67. ## pointers to member names.
  68. Iconv* {.importc: "iconv_t", header: "<iconv.h>".} = pointer
  69. ## Identifies the conversion from one codeset to another.
  70. Lconv* {.importc: "struct lconv", header: "<locale.h>", final,
  71. pure.} = object
  72. decimal_point*: cstring
  73. thousands_sep*: cstring
  74. grouping*: cstring
  75. int_curr_symbol*: cstring
  76. currency_symbol*: cstring
  77. mon_decimal_point*: cstring
  78. mon_thousands_sep*: cstring
  79. mon_grouping*: cstring
  80. positive_sign*: cstring
  81. negative_sign*: cstring
  82. int_frac_digits*: char
  83. frac_digits*: char
  84. p_cs_precedes*: char
  85. p_sep_by_space*: char
  86. n_cs_precedes*: char
  87. n_sep_by_space*: char
  88. p_sign_posn*: char
  89. n_sign_posn*: char
  90. int_p_cs_precedes*: char
  91. int_p_sep_by_space*: char
  92. int_n_cs_precedes*: char
  93. int_n_sep_by_space*: char
  94. int_p_sign_posn*: char
  95. int_n_sign_posn*: char
  96. Mqd* {.importc: "mqd_t", header: "<mqueue.h>".} = cint
  97. MqAttr* {.importc: "struct mq_attr",
  98. header: "<mqueue.h>",
  99. final, pure.} = object ## message queue attribute
  100. mq_flags*: clong ## Message queue flags.
  101. mq_maxmsg*: clong ## Maximum number of messages.
  102. mq_msgsize*: clong ## Maximum message size.
  103. mq_curmsgs*: clong ## Number of messages currently queued.
  104. pad: array[4, clong]
  105. Passwd* {.importc: "struct passwd", header: "<pwd.h>",
  106. final, pure.} = object ## struct passwd
  107. pw_name*: cstring ## User's login name.
  108. pw_passwd*: cstring
  109. pw_uid*: Uid ## Numerical user ID.
  110. pw_gid*: Gid ## Numerical group ID.
  111. pw_gecos*: cstring
  112. pw_dir*: cstring ## Initial working directory.
  113. pw_shell*: cstring ## Program to use as shell.
  114. Blkcnt* {.importc: "blkcnt_t", header: "<sys/types.h>".} = clong
  115. ## used for file block counts
  116. Blksize* {.importc: "blksize_t", header: "<sys/types.h>".} = clong
  117. ## used for block sizes
  118. Clock* {.importc: "clock_t", header: "<sys/types.h>".} = clong
  119. ClockId* {.importc: "clockid_t", header: "<sys/types.h>".} = cint
  120. Dev* {.importc: "dev_t", header: "<sys/types.h>".} = culong
  121. Fsblkcnt* {.importc: "fsblkcnt_t", header: "<sys/types.h>".} = culong
  122. Fsfilcnt* {.importc: "fsfilcnt_t", header: "<sys/types.h>".} = culong
  123. Gid* {.importc: "gid_t", header: "<sys/types.h>".} = cuint
  124. Id* {.importc: "id_t", header: "<sys/types.h>".} = cuint
  125. Ino* {.importc: "ino_t", header: "<sys/types.h>".} = culong
  126. Key* {.importc: "key_t", header: "<sys/types.h>".} = cint
  127. Mode* {.importc: "mode_t", header: "<sys/types.h>".} = uint32
  128. Nlink* {.importc: "nlink_t", header: "<sys/types.h>".} = culong
  129. Off* {.importc: "off_t", header: "<sys/types.h>".} = clong
  130. Pid* {.importc: "pid_t", header: "<sys/types.h>".} = cint
  131. Pthread_attr* {.importc: "pthread_attr_t", header: "<sys/types.h>",
  132. pure, final.} = object
  133. abi: array[56 div sizeof(clong), clong]
  134. Pthread_barrier* {.importc: "pthread_barrier_t",
  135. header: "<sys/types.h>", pure, final.} = object
  136. abi: array[32 div sizeof(clong), clong]
  137. Pthread_barrierattr* {.importc: "pthread_barrierattr_t",
  138. header: "<sys/types.h>", pure, final.} = object
  139. abi: array[4 div sizeof(cint), cint]
  140. Pthread_cond* {.importc: "pthread_cond_t", header: "<sys/types.h>",
  141. pure, final.} = object
  142. abi: array[48 div sizeof(clonglong), clonglong]
  143. Pthread_condattr* {.importc: "pthread_condattr_t",
  144. header: "<sys/types.h>", pure, final.} = object
  145. abi: array[4 div sizeof(cint), cint]
  146. Pthread_key* {.importc: "pthread_key_t", header: "<sys/types.h>".} = cuint
  147. Pthread_mutex* {.importc: "pthread_mutex_t", header: "<sys/types.h>",
  148. pure, final.} = object
  149. abi: array[40 div sizeof(clong), clong]
  150. Pthread_mutexattr* {.importc: "pthread_mutexattr_t",
  151. header: "<sys/types.h>", pure, final.} = object
  152. abi: array[4 div sizeof(cint), cint]
  153. Pthread_once* {.importc: "pthread_once_t", header: "<sys/types.h>".} = cint
  154. Pthread_rwlock* {.importc: "pthread_rwlock_t",
  155. header: "<sys/types.h>", pure, final.} = object
  156. abi: array[56 div sizeof(clong), clong]
  157. Pthread_rwlockattr* {.importc: "pthread_rwlockattr_t",
  158. header: "<sys/types.h>".} = object
  159. abi: array[8 div sizeof(clong), clong]
  160. Pthread_spinlock* {.importc: "pthread_spinlock_t",
  161. header: "<sys/types.h>".} = cint
  162. Pthread* {.importc: "pthread_t", header: "<sys/types.h>".} = culong
  163. Suseconds* {.importc: "suseconds_t", header: "<sys/types.h>".} = clong
  164. #Ttime* {.importc: "time_t", header: "<sys/types.h>".} = int
  165. Timer* {.importc: "timer_t", header: "<sys/types.h>".} = pointer
  166. Uid* {.importc: "uid_t", header: "<sys/types.h>".} = cuint
  167. Useconds* {.importc: "useconds_t", header: "<sys/types.h>".} = cuint
  168. Utsname* {.importc: "struct utsname",
  169. header: "<sys/utsname.h>",
  170. final, pure.} = object ## struct utsname
  171. sysname*, ## Name of this implementation of the operating system.
  172. nodename*, ## Name of this node within the communications
  173. ## network to which this node is attached, if any.
  174. release*, ## Current release level of this implementation.
  175. version*, ## Current version level of this release.
  176. machine*, ## Name of the hardware type on which the
  177. ## system is running.
  178. domainname*: array[65, char]
  179. Sem* {.importc: "sem_t", header: "<semaphore.h>", final, pure.} = object
  180. abi: array[32 div sizeof(clong), clong]
  181. Ipc_perm* {.importc: "struct ipc_perm",
  182. header: "<sys/ipc.h>", final, pure.} = object ## struct ipc_perm
  183. key: Key
  184. uid*: Uid ## Owner's user ID.
  185. gid*: Gid ## Owner's group ID.
  186. cuid*: Uid ## Creator's user ID.
  187. cgid*: Gid ## Creator's group ID.
  188. mode*: cshort ## Read/write permission.
  189. pad1: cshort
  190. seq1: cshort
  191. pad2: cshort
  192. reserved1: culong
  193. reserved2: culong
  194. Stat* {.importc: "struct stat",
  195. header: "<sys/stat.h>", final, pure.} = object ## struct stat
  196. st_dev*: Dev ## Device ID of device containing file.
  197. st_ino*: Ino ## File serial number.
  198. st_nlink*: Nlink ## Number of hard links to the file.
  199. st_mode*: Mode ## Mode of file (see below).
  200. st_uid*: Uid ## User ID of file.
  201. st_gid*: Gid ## Group ID of file.
  202. pad0 {.importc: "__pad0".}: cint
  203. st_rdev*: Dev ## Device ID (if file is character or block special).
  204. st_size*: Off ## For regular files, the file size in bytes.
  205. ## For symbolic links, the length in bytes of the
  206. ## pathname contained in the symbolic link.
  207. ## For a shared memory object, the length in bytes.
  208. ## For a typed memory object, the length in bytes.
  209. ## For other file types, the use of this field is
  210. ## unspecified.
  211. st_blksize*: Blksize ## A file system-specific preferred I/O block size
  212. ## for this object. In some file system types, this
  213. ## may vary from file to file.
  214. st_blocks*: Blkcnt ## Number of blocks allocated for this object.
  215. st_atim*: Timespec ## Time of last access.
  216. st_mtim*: Timespec ## Time of last data modification.
  217. st_ctim*: Timespec ## Time of last status change.
  218. Statvfs* {.importc: "struct statvfs", header: "<sys/statvfs.h>",
  219. final, pure.} = object ## struct statvfs
  220. f_bsize*: culong ## File system block size.
  221. f_frsize*: culong ## Fundamental file system block size.
  222. f_blocks*: Fsblkcnt ## Total number of blocks on file system
  223. ## in units of f_frsize.
  224. f_bfree*: Fsblkcnt ## Total number of free blocks.
  225. f_bavail*: Fsblkcnt ## Number of free blocks available to
  226. ## non-privileged process.
  227. f_files*: Fsfilcnt ## Total number of file serial numbers.
  228. f_ffree*: Fsfilcnt ## Total number of free file serial numbers.
  229. f_favail*: Fsfilcnt ## Number of file serial numbers available to
  230. ## non-privileged process.
  231. f_fsid*: culong ## File system ID.
  232. f_flag*: culong ## Bit mask of f_flag values.
  233. f_namemax*: culong ## Maximum filename length.
  234. f_spare: array[6, cint]
  235. # No Posix_typed_mem_info
  236. Tm* {.importc: "struct tm", header: "<time.h>",
  237. final, pure.} = object ## struct tm
  238. tm_sec*: cint ## Seconds [0,60].
  239. tm_min*: cint ## Minutes [0,59].
  240. tm_hour*: cint ## Hour [0,23].
  241. tm_mday*: cint ## Day of month [1,31].
  242. tm_mon*: cint ## Month of year [0,11].
  243. tm_year*: cint ## Years since 1900.
  244. tm_wday*: cint ## Day of week [0,6] (Sunday =0).
  245. tm_yday*: cint ## Day of year [0,365].
  246. tm_isdst*: cint ## Daylight Savings flag.
  247. tm_gmtoff*: clong
  248. tm_zone*: cstring
  249. Itimerspec* {.importc: "struct itimerspec", header: "<time.h>",
  250. final, pure.} = object ## struct itimerspec
  251. it_interval*: Timespec ## Timer period.
  252. it_value*: Timespec ## Timer expiration.
  253. Sig_atomic* {.importc: "sig_atomic_t", header: "<signal.h>".} = cint
  254. ## Possibly volatile-qualified integer type of an object that can be
  255. ## accessed as an atomic entity, even in the presence of asynchronous
  256. ## interrupts.
  257. Sigset* {.importc: "sigset_t", header: "<signal.h>", final, pure.} = object
  258. abi: array[1024 div (8 * sizeof(culong)), culong]
  259. SigEvent* {.importc: "struct sigevent",
  260. header: "<signal.h>", final, pure.} = object ## struct sigevent
  261. sigev_value*: SigVal ## Signal value.
  262. sigev_signo*: cint ## Signal number.
  263. sigev_notify*: cint ## Notification type.
  264. sigev_notify_function*: proc (x: SigVal) {.noconv.} ## Notification func.
  265. sigev_notify_attributes*: ptr Pthread_attr ## Notification attributes.
  266. abi: array[12, int]
  267. SigVal* {.importc: "union sigval",
  268. header: "<signal.h>", final, pure.} = object ## struct sigval
  269. sival_ptr*: pointer ## pointer signal value;
  270. ## integer signal value not defined!
  271. Sigaction* {.importc: "struct sigaction",
  272. header: "<signal.h>", final, pure.} = object ## struct sigaction
  273. sa_handler*: proc (x: cint) {.noconv.} ## Pointer to a signal-catching
  274. ## function or one of the macros
  275. ## SIG_IGN or SIG_DFL.
  276. sa_mask*: Sigset ## Set of signals to be blocked during execution of
  277. ## the signal handling function.
  278. sa_flags*: cint ## Special flags.
  279. sa_restorer: proc() {.noconv.} ## not intended for application use.
  280. Stack* {.importc: "stack_t",
  281. header: "<signal.h>", final, pure.} = object ## stack_t
  282. ss_sp*: pointer ## Stack base or pointer.
  283. ss_size*: int ## Stack size.
  284. ss_flags*: cint ## Flags.
  285. SigStack* {.importc: "struct sigstack",
  286. header: "<signal.h>", final, pure.} = object ## struct sigstack
  287. ss_onstack*: cint ## Non-zero when signal stack is in use.
  288. ss_sp*: pointer ## Signal stack pointer.
  289. SigInfo* {.importc: "siginfo_t",
  290. header: "<signal.h>", final, pure.} = object ## siginfo_t
  291. si_signo*: cint ## Signal number.
  292. si_errno*: cint ## If non-zero, an errno value associated with
  293. ## this signal, as defined in <errno.h>.
  294. si_code*: cint ## Signal code.
  295. si_pid*: Pid ## Sending process ID.
  296. si_uid*: Uid ## Real user ID of sending process.
  297. si_addr*: pointer ## Address of faulting instruction.
  298. si_status*: cint ## Exit value or signal.
  299. si_band*: int ## Band event for SIGPOLL.
  300. si_value*: SigVal ## Signal value.
  301. pad {.importc: "_pad".}: array[128 - 56, uint8]
  302. template sa_sigaction*(v: Sigaction): proc (x: cint, y: ptr SigInfo, z: pointer) {.noconv.} =
  303. cast[proc (x: cint, y: ptr SigInfo, z: pointer) {.noconv.}](v.sa_handler)
  304. proc `sa_sigaction=`*(v: var Sigaction, x: proc (x: cint, y: ptr SigInfo, z: pointer) {.noconv.}) =
  305. v.sa_handler = cast[proc (x: cint) {.noconv.}](x)
  306. type
  307. Nl_item* {.importc: "nl_item", header: "<nl_types.h>".} = cint
  308. Nl_catd* {.importc: "nl_catd", header: "<nl_types.h>".} = pointer
  309. Sched_param* {.importc: "struct sched_param",
  310. header: "<sched.h>",
  311. final, pure.} = object ## struct sched_param
  312. sched_priority*: cint
  313. Timeval* {.importc: "struct timeval", header: "<sys/select.h>",
  314. final, pure.} = object ## struct timeval
  315. tv_sec*: Time ## Seconds.
  316. tv_usec*: Suseconds ## Microseconds.
  317. TFdSet* {.importc: "fd_set", header: "<sys/select.h>",
  318. final, pure.} = object
  319. abi: array[1024 div (8 * sizeof(clong)), clong]
  320. Mcontext* {.importc: "mcontext_t", header: "<ucontext.h>",
  321. final, pure.} = object
  322. gregs: array[23, clonglong]
  323. fpregs: pointer
  324. reserved1: array[8, clonglong]
  325. Ucontext* {.importc: "ucontext_t", header: "<ucontext.h>",
  326. final, pure.} = object ## ucontext_t
  327. uc_flags: clong
  328. uc_link*: ptr Ucontext ## Pointer to the context that is resumed
  329. ## when this context returns.
  330. uc_stack*: Stack ## The stack used by this context.
  331. uc_mcontext*: Mcontext ## A machine-specific representation of the saved
  332. ## context.
  333. uc_sigmask*: Sigset ## The set of signals that are blocked when this
  334. ## context is active.
  335. # todo fpregds_mem
  336. type
  337. Taiocb* {.importc: "struct aiocb", header: "<aio.h>",
  338. final, pure.} = object ## struct aiocb
  339. aio_fildes*: cint ## File descriptor.
  340. aio_lio_opcode*: cint ## Operation to be performed.
  341. aio_reqprio*: cint ## Request priority offset.
  342. aio_buf*: pointer ## Location of buffer.
  343. aio_nbytes*: csize_t ## Length of transfer.
  344. aio_sigevent*: SigEvent ## Signal number and value.
  345. next_prio: pointer
  346. abs_prio: cint
  347. policy: cint
  348. error_Code: cint
  349. return_value: clong
  350. aio_offset*: Off ## File offset.
  351. reserved: array[32, uint8]
  352. when hasSpawnH:
  353. type
  354. Tposix_spawnattr* {.importc: "posix_spawnattr_t",
  355. header: "<spawn.h>", final, pure.} = object
  356. flags: cshort
  357. pgrp: Pid
  358. sd: Sigset
  359. ss: Sigset
  360. sp: Sched_param
  361. policy: cint
  362. pad: array[16, cint]
  363. Tposix_spawn_file_actions* {.importc: "posix_spawn_file_actions_t",
  364. header: "<spawn.h>", final, pure.} = object
  365. allocated: cint
  366. used: cint
  367. actions: pointer
  368. pad: array[16, cint]
  369. # from sys/un.h
  370. const Sockaddr_un_path_length* = 108
  371. type
  372. SockLen* {.importc: "socklen_t", header: "<sys/socket.h>".} = cuint
  373. TSa_Family* {.importc: "sa_family_t", header: "<sys/socket.h>".} = cushort
  374. SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>",
  375. pure, final.} = object ## struct sockaddr
  376. sa_family*: TSa_Family ## Address family.
  377. sa_data*: array[14, char] ## Socket address (variable-length data).
  378. Sockaddr_un* {.importc: "struct sockaddr_un", header: "<sys/un.h>",
  379. pure, final.} = object ## struct sockaddr_un
  380. sun_family*: TSa_Family ## Address family.
  381. sun_path*: array[108, char] ## Socket path
  382. Sockaddr_storage* {.importc: "struct sockaddr_storage",
  383. header: "<sys/socket.h>",
  384. pure, final.} = object ## struct sockaddr_storage
  385. ss_family*: TSa_Family ## Address family.
  386. ss_padding {.importc: "__ss_padding".}: array[128 - sizeof(cshort) - sizeof(culong), char]
  387. ss_align {.importc: "__ss_align".}: clong
  388. Tif_nameindex* {.importc: "struct if_nameindex", final,
  389. pure, header: "<net/if.h>".} = object ## struct if_nameindex
  390. if_index*: cuint ## Numeric index of the interface.
  391. if_name*: cstring ## Null-terminated name of the interface.
  392. IOVec* {.importc: "struct iovec", pure, final,
  393. header: "<sys/uio.h>".} = object ## struct iovec
  394. iov_base*: pointer ## Base address of a memory region for input or output.
  395. iov_len*: csize_t ## The size of the memory pointed to by iov_base.
  396. Tmsghdr* {.importc: "struct msghdr", pure, final,
  397. header: "<sys/socket.h>".} = object ## struct msghdr
  398. msg_name*: pointer ## Optional address.
  399. msg_namelen*: SockLen ## Size of address.
  400. msg_iov*: ptr IOVec ## Scatter/gather array.
  401. msg_iovlen*: csize_t ## Members in msg_iov.
  402. msg_control*: pointer ## Ancillary data; see below.
  403. msg_controllen*: csize_t ## Ancillary data buffer len.
  404. msg_flags*: cint ## Flags on received message.
  405. Tcmsghdr* {.importc: "struct cmsghdr", pure, final,
  406. header: "<sys/socket.h>".} = object ## struct cmsghdr
  407. cmsg_len*: csize_t ## Data byte count, including the cmsghdr.
  408. cmsg_level*: cint ## Originating protocol.
  409. cmsg_type*: cint ## Protocol-specific type.
  410. TLinger* {.importc: "struct linger", pure, final,
  411. header: "<sys/socket.h>".} = object ## struct linger
  412. l_onoff*: cint ## Indicates whether linger option is enabled.
  413. l_linger*: cint ## Linger time, in seconds.
  414. # data follows...
  415. InPort* = uint16
  416. InAddrScalar* = uint32
  417. InAddrT* {.importc: "in_addr_t", pure, final,
  418. header: "<netinet/in.h>".} = uint32
  419. InAddr* {.importc: "struct in_addr", pure, final,
  420. header: "<netinet/in.h>".} = object ## struct in_addr
  421. s_addr*: InAddrScalar
  422. Sockaddr_in* {.importc: "struct sockaddr_in", pure, final,
  423. header: "<netinet/in.h>".} = object ## struct sockaddr_in
  424. sin_family*: TSa_Family ## AF_INET.
  425. sin_port*: InPort ## Port number.
  426. sin_addr*: InAddr ## IP address.
  427. sin_zero: array[16 - 2 - 2 - 4, uint8]
  428. In6Addr* {.importc: "struct in6_addr", pure, final,
  429. header: "<netinet/in.h>".} = object ## struct in6_addr
  430. s6_addr*: array[0..15, char]
  431. Sockaddr_in6* {.importc: "struct sockaddr_in6", pure, final,
  432. header: "<netinet/in.h>".} = object ## struct sockaddr_in6
  433. sin6_family*: TSa_Family ## AF_INET6.
  434. sin6_port*: InPort ## Port number.
  435. sin6_flowinfo*: uint32 ## IPv6 traffic class and flow information.
  436. sin6_addr*: In6Addr ## IPv6 address.
  437. sin6_scope_id*: uint32 ## Set of interfaces for a scope.
  438. Tipv6_mreq* {.importc: "struct ipv6_mreq", pure, final,
  439. header: "<netinet/in.h>".} = object ## struct ipv6_mreq
  440. ipv6mr_multiaddr*: In6Addr ## IPv6 multicast address.
  441. ipv6mr_interface*: cuint ## Interface index.
  442. Hostent* {.importc: "struct hostent", pure, final,
  443. header: "<netdb.h>".} = object ## struct hostent
  444. h_name*: cstring ## Official name of the host.
  445. h_aliases*: cstringArray ## A pointer to an array of pointers to
  446. ## alternative host names, terminated by a
  447. ## null pointer.
  448. h_addrtype*: cint ## Address type.
  449. h_length*: cint ## The length, in bytes, of the address.
  450. h_addr_list*: cstringArray ## A pointer to an array of pointers to network
  451. ## addresses (in network byte order) for the
  452. ## host, terminated by a null pointer.
  453. Tnetent* {.importc: "struct netent", pure, final,
  454. header: "<netdb.h>".} = object ## struct netent
  455. n_name*: cstring ## Official, fully-qualified (including the
  456. ## domain) name of the host.
  457. n_aliases*: cstringArray ## A pointer to an array of pointers to
  458. ## alternative network names, terminated by a
  459. ## null pointer.
  460. n_addrtype*: cint ## The address type of the network.
  461. n_net*: uint32 ## The network number, in host byte order.
  462. Protoent* {.importc: "struct protoent", pure, final,
  463. header: "<netdb.h>".} = object ## struct protoent
  464. p_name*: cstring ## Official name of the protocol.
  465. p_aliases*: cstringArray ## A pointer to an array of pointers to
  466. ## alternative protocol names, terminated by
  467. ## a null pointer.
  468. p_proto*: cint ## The protocol number.
  469. Servent* {.importc: "struct servent", pure, final,
  470. header: "<netdb.h>".} = object ## struct servent
  471. s_name*: cstring ## Official name of the service.
  472. s_aliases*: cstringArray ## A pointer to an array of pointers to
  473. ## alternative service names, terminated by
  474. ## a null pointer.
  475. s_port*: cint ## The port number at which the service
  476. ## resides, in network byte order.
  477. s_proto*: cstring ## The name of the protocol to use when
  478. ## contacting the service.
  479. AddrInfo* {.importc: "struct addrinfo", pure, final,
  480. header: "<netdb.h>".} = object ## struct addrinfo
  481. ai_flags*: cint ## Input flags.
  482. ai_family*: cint ## Address family of socket.
  483. ai_socktype*: cint ## Socket type.
  484. ai_protocol*: cint ## Protocol of socket.
  485. ai_addrlen*: SockLen ## Length of socket address.
  486. ai_addr*: ptr SockAddr ## Socket address of socket.
  487. ai_canonname*: cstring ## Canonical name of service location.
  488. ai_next*: ptr AddrInfo ## Pointer to next in list.
  489. TPollfd* {.importc: "struct pollfd", pure, final,
  490. header: "<poll.h>".} = object ## struct pollfd
  491. fd*: cint ## The following descriptor being polled.
  492. events*: cshort ## The input event flags (see below).
  493. revents*: cshort ## The output event flags (see below).
  494. Tnfds* {.importc: "nfds_t", header: "<poll.h>".} = culong
  495. var
  496. errno* {.importc, header: "<errno.h>".}: cint ## error variable
  497. h_errno* {.importc, header: "<netdb.h>".}: cint
  498. daylight* {.importc, header: "<time.h>".}: cint
  499. timezone* {.importc, header: "<time.h>".}: clong
  500. # Regenerate using detect.nim!
  501. include posix_linux_amd64_consts
  502. # <sys/wait.h>
  503. proc WEXITSTATUS*(s: cint): cint = (s and 0xff00) shr 8
  504. proc WTERMSIG*(s:cint): cint = s and 0x7f
  505. proc WSTOPSIG*(s:cint): cint = WEXITSTATUS(s)
  506. proc WIFEXITED*(s:cint) : bool = WTERMSIG(s) == 0
  507. proc WIFSIGNALED*(s:cint) : bool = (cast[int8]((s and 0x7f) + 1) shr 1) > 0
  508. proc WIFSTOPPED*(s:cint) : bool = (s and 0xff) == 0x7f
  509. proc WIFCONTINUED*(s:cint) : bool = s == WCONTINUED
  510. when defined(nimHasStyleChecks):
  511. {.pop.} # {.push styleChecks: off.}