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