Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

403 Zeilen
8.5 KiB

  1. // Copyright 2009 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build ignore
  5. /*
  6. Input to cgo -godefs. See README.md
  7. */
  8. // +godefs map struct_in_addr [4]byte /* in_addr */
  9. // +godefs map struct_in6_addr [16]byte /* in6_addr */
  10. package unix
  11. /*
  12. #define KERNEL
  13. #include <dirent.h>
  14. #include <fcntl.h>
  15. #include <poll.h>
  16. #include <signal.h>
  17. #include <termios.h>
  18. #include <stdio.h>
  19. #include <unistd.h>
  20. #include <sys/capability.h>
  21. #include <sys/event.h>
  22. #include <sys/mman.h>
  23. #include <sys/mount.h>
  24. #include <sys/param.h>
  25. #include <sys/ptrace.h>
  26. #include <sys/resource.h>
  27. #include <sys/select.h>
  28. #include <sys/signal.h>
  29. #include <sys/socket.h>
  30. #include <sys/stat.h>
  31. #include <sys/time.h>
  32. #include <sys/types.h>
  33. #include <sys/un.h>
  34. #include <sys/utsname.h>
  35. #include <sys/wait.h>
  36. #include <net/bpf.h>
  37. #include <net/if.h>
  38. #include <net/if_dl.h>
  39. #include <net/route.h>
  40. #include <netinet/in.h>
  41. #include <netinet/icmp6.h>
  42. #include <netinet/tcp.h>
  43. enum {
  44. sizeofPtr = sizeof(void*),
  45. };
  46. union sockaddr_all {
  47. struct sockaddr s1; // this one gets used for fields
  48. struct sockaddr_in s2; // these pad it out
  49. struct sockaddr_in6 s3;
  50. struct sockaddr_un s4;
  51. struct sockaddr_dl s5;
  52. };
  53. struct sockaddr_any {
  54. struct sockaddr addr;
  55. char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)];
  56. };
  57. // This structure is a duplicate of stat on FreeBSD 8-STABLE.
  58. // See /usr/include/sys/stat.h.
  59. struct stat8 {
  60. #undef st_atimespec st_atim
  61. #undef st_mtimespec st_mtim
  62. #undef st_ctimespec st_ctim
  63. #undef st_birthtimespec st_birthtim
  64. __dev_t st_dev;
  65. ino_t st_ino;
  66. mode_t st_mode;
  67. nlink_t st_nlink;
  68. uid_t st_uid;
  69. gid_t st_gid;
  70. __dev_t st_rdev;
  71. #if __BSD_VISIBLE
  72. struct timespec st_atimespec;
  73. struct timespec st_mtimespec;
  74. struct timespec st_ctimespec;
  75. #else
  76. time_t st_atime;
  77. long __st_atimensec;
  78. time_t st_mtime;
  79. long __st_mtimensec;
  80. time_t st_ctime;
  81. long __st_ctimensec;
  82. #endif
  83. off_t st_size;
  84. blkcnt_t st_blocks;
  85. blksize_t st_blksize;
  86. fflags_t st_flags;
  87. __uint32_t st_gen;
  88. __int32_t st_lspare;
  89. #if __BSD_VISIBLE
  90. struct timespec st_birthtimespec;
  91. unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
  92. unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
  93. #else
  94. time_t st_birthtime;
  95. long st_birthtimensec;
  96. unsigned int :(8 / 2) * (16 - (int)sizeof(struct __timespec));
  97. unsigned int :(8 / 2) * (16 - (int)sizeof(struct __timespec));
  98. #endif
  99. };
  100. // This structure is a duplicate of if_data on FreeBSD 8-STABLE.
  101. // See /usr/include/net/if.h.
  102. struct if_data8 {
  103. u_char ifi_type;
  104. u_char ifi_physical;
  105. u_char ifi_addrlen;
  106. u_char ifi_hdrlen;
  107. u_char ifi_link_state;
  108. u_char ifi_spare_char1;
  109. u_char ifi_spare_char2;
  110. u_char ifi_datalen;
  111. u_long ifi_mtu;
  112. u_long ifi_metric;
  113. u_long ifi_baudrate;
  114. u_long ifi_ipackets;
  115. u_long ifi_ierrors;
  116. u_long ifi_opackets;
  117. u_long ifi_oerrors;
  118. u_long ifi_collisions;
  119. u_long ifi_ibytes;
  120. u_long ifi_obytes;
  121. u_long ifi_imcasts;
  122. u_long ifi_omcasts;
  123. u_long ifi_iqdrops;
  124. u_long ifi_noproto;
  125. u_long ifi_hwassist;
  126. // FIXME: these are now unions, so maybe need to change definitions?
  127. #undef ifi_epoch
  128. time_t ifi_epoch;
  129. #undef ifi_lastchange
  130. struct timeval ifi_lastchange;
  131. };
  132. // This structure is a duplicate of if_msghdr on FreeBSD 8-STABLE.
  133. // See /usr/include/net/if.h.
  134. struct if_msghdr8 {
  135. u_short ifm_msglen;
  136. u_char ifm_version;
  137. u_char ifm_type;
  138. int ifm_addrs;
  139. int ifm_flags;
  140. u_short ifm_index;
  141. struct if_data8 ifm_data;
  142. };
  143. */
  144. import "C"
  145. // Machine characteristics; for internal use.
  146. const (
  147. sizeofPtr = C.sizeofPtr
  148. sizeofShort = C.sizeof_short
  149. sizeofInt = C.sizeof_int
  150. sizeofLong = C.sizeof_long
  151. sizeofLongLong = C.sizeof_longlong
  152. )
  153. // Basic types
  154. type (
  155. _C_short C.short
  156. _C_int C.int
  157. _C_long C.long
  158. _C_long_long C.longlong
  159. )
  160. // Time
  161. type Timespec C.struct_timespec
  162. type Timeval C.struct_timeval
  163. // Processes
  164. type Rusage C.struct_rusage
  165. type Rlimit C.struct_rlimit
  166. type _Gid_t C.gid_t
  167. // Files
  168. const ( // Directory mode bits
  169. S_IFMT = C.S_IFMT
  170. S_IFIFO = C.S_IFIFO
  171. S_IFCHR = C.S_IFCHR
  172. S_IFDIR = C.S_IFDIR
  173. S_IFBLK = C.S_IFBLK
  174. S_IFREG = C.S_IFREG
  175. S_IFLNK = C.S_IFLNK
  176. S_IFSOCK = C.S_IFSOCK
  177. S_ISUID = C.S_ISUID
  178. S_ISGID = C.S_ISGID
  179. S_ISVTX = C.S_ISVTX
  180. S_IRUSR = C.S_IRUSR
  181. S_IWUSR = C.S_IWUSR
  182. S_IXUSR = C.S_IXUSR
  183. )
  184. type Stat_t C.struct_stat8
  185. type Statfs_t C.struct_statfs
  186. type Flock_t C.struct_flock
  187. type Dirent C.struct_dirent
  188. type Fsid C.struct_fsid
  189. // File system limits
  190. const (
  191. PathMax = C.PATH_MAX
  192. )
  193. // Advice to Fadvise
  194. const (
  195. FADV_NORMAL = C.POSIX_FADV_NORMAL
  196. FADV_RANDOM = C.POSIX_FADV_RANDOM
  197. FADV_SEQUENTIAL = C.POSIX_FADV_SEQUENTIAL
  198. FADV_WILLNEED = C.POSIX_FADV_WILLNEED
  199. FADV_DONTNEED = C.POSIX_FADV_DONTNEED
  200. FADV_NOREUSE = C.POSIX_FADV_NOREUSE
  201. )
  202. // Sockets
  203. type RawSockaddrInet4 C.struct_sockaddr_in
  204. type RawSockaddrInet6 C.struct_sockaddr_in6
  205. type RawSockaddrUnix C.struct_sockaddr_un
  206. type RawSockaddrDatalink C.struct_sockaddr_dl
  207. type RawSockaddr C.struct_sockaddr
  208. type RawSockaddrAny C.struct_sockaddr_any
  209. type _Socklen C.socklen_t
  210. type Linger C.struct_linger
  211. type Iovec C.struct_iovec
  212. type IPMreq C.struct_ip_mreq
  213. type IPMreqn C.struct_ip_mreqn
  214. type IPv6Mreq C.struct_ipv6_mreq
  215. type Msghdr C.struct_msghdr
  216. type Cmsghdr C.struct_cmsghdr
  217. type Inet6Pktinfo C.struct_in6_pktinfo
  218. type IPv6MTUInfo C.struct_ip6_mtuinfo
  219. type ICMPv6Filter C.struct_icmp6_filter
  220. const (
  221. SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in
  222. SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
  223. SizeofSockaddrAny = C.sizeof_struct_sockaddr_any
  224. SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un
  225. SizeofSockaddrDatalink = C.sizeof_struct_sockaddr_dl
  226. SizeofLinger = C.sizeof_struct_linger
  227. SizeofIPMreq = C.sizeof_struct_ip_mreq
  228. SizeofIPMreqn = C.sizeof_struct_ip_mreqn
  229. SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq
  230. SizeofMsghdr = C.sizeof_struct_msghdr
  231. SizeofCmsghdr = C.sizeof_struct_cmsghdr
  232. SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo
  233. SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo
  234. SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
  235. )
  236. // Ptrace requests
  237. const (
  238. PTRACE_TRACEME = C.PT_TRACE_ME
  239. PTRACE_CONT = C.PT_CONTINUE
  240. PTRACE_KILL = C.PT_KILL
  241. )
  242. // Events (kqueue, kevent)
  243. type Kevent_t C.struct_kevent
  244. // Select
  245. type FdSet C.fd_set
  246. // Routing and interface messages
  247. const (
  248. sizeofIfMsghdr = C.sizeof_struct_if_msghdr
  249. SizeofIfMsghdr = C.sizeof_struct_if_msghdr8
  250. sizeofIfData = C.sizeof_struct_if_data
  251. SizeofIfData = C.sizeof_struct_if_data8
  252. SizeofIfaMsghdr = C.sizeof_struct_ifa_msghdr
  253. SizeofIfmaMsghdr = C.sizeof_struct_ifma_msghdr
  254. SizeofIfAnnounceMsghdr = C.sizeof_struct_if_announcemsghdr
  255. SizeofRtMsghdr = C.sizeof_struct_rt_msghdr
  256. SizeofRtMetrics = C.sizeof_struct_rt_metrics
  257. )
  258. type ifMsghdr C.struct_if_msghdr
  259. type IfMsghdr C.struct_if_msghdr8
  260. type ifData C.struct_if_data
  261. type IfData C.struct_if_data8
  262. type IfaMsghdr C.struct_ifa_msghdr
  263. type IfmaMsghdr C.struct_ifma_msghdr
  264. type IfAnnounceMsghdr C.struct_if_announcemsghdr
  265. type RtMsghdr C.struct_rt_msghdr
  266. type RtMetrics C.struct_rt_metrics
  267. // Berkeley packet filter
  268. const (
  269. SizeofBpfVersion = C.sizeof_struct_bpf_version
  270. SizeofBpfStat = C.sizeof_struct_bpf_stat
  271. SizeofBpfZbuf = C.sizeof_struct_bpf_zbuf
  272. SizeofBpfProgram = C.sizeof_struct_bpf_program
  273. SizeofBpfInsn = C.sizeof_struct_bpf_insn
  274. SizeofBpfHdr = C.sizeof_struct_bpf_hdr
  275. SizeofBpfZbufHeader = C.sizeof_struct_bpf_zbuf_header
  276. )
  277. type BpfVersion C.struct_bpf_version
  278. type BpfStat C.struct_bpf_stat
  279. type BpfZbuf C.struct_bpf_zbuf
  280. type BpfProgram C.struct_bpf_program
  281. type BpfInsn C.struct_bpf_insn
  282. type BpfHdr C.struct_bpf_hdr
  283. type BpfZbufHeader C.struct_bpf_zbuf_header
  284. // Terminal handling
  285. type Termios C.struct_termios
  286. type Winsize C.struct_winsize
  287. // fchmodat-like syscalls.
  288. const (
  289. AT_FDCWD = C.AT_FDCWD
  290. AT_REMOVEDIR = C.AT_REMOVEDIR
  291. AT_SYMLINK_FOLLOW = C.AT_SYMLINK_FOLLOW
  292. AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW
  293. )
  294. // poll
  295. type PollFd C.struct_pollfd
  296. const (
  297. POLLERR = C.POLLERR
  298. POLLHUP = C.POLLHUP
  299. POLLIN = C.POLLIN
  300. POLLINIGNEOF = C.POLLINIGNEOF
  301. POLLNVAL = C.POLLNVAL
  302. POLLOUT = C.POLLOUT
  303. POLLPRI = C.POLLPRI
  304. POLLRDBAND = C.POLLRDBAND
  305. POLLRDNORM = C.POLLRDNORM
  306. POLLWRBAND = C.POLLWRBAND
  307. POLLWRNORM = C.POLLWRNORM
  308. )
  309. // Capabilities
  310. type CapRights C.struct_cap_rights
  311. // Uname
  312. type Utsname C.struct_utsname