3 # Copyright 2009 The Go Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style
5 # license that can be found in the LICENSE file.
9 # This shell script creates the sysinfo.go file which holds types and
10 # constants extracted from the system header files. This relies on a
11 # hook in gcc: the -fdump-go-spec option will generate debugging
12 # information in Go syntax.
14 # We currently #include all the files at once, which works, but leads
15 # to exposing some names which ideally should not be exposed, as they
16 # match grep patterns. E.g., WCHAR_MIN gets exposed because it starts
17 # with W, like the wait flags.
28 #include <sys/types.h>
32 #include <netinet/in.h>
33 /* <netinet/tcp.h> needs u_char/u_short, but <sys/bsd_types> is only
34 included by <netinet/in.h> if _SGIAPI (i.e. _SGI_SOURCE
36 <sys/termios.h> only defines TIOCNOTTY if !_XOPEN_SOURCE, while
37 <sys/ttold.h> does so unconditionally. */
39 #include <sys/bsd_types.h>
40 #include <sys/ttold.h>
42 #include <netinet/tcp.h>
43 #if defined(HAVE_NETINET_IN_SYSTM_H)
44 #include <netinet/in_systm.h>
46 #if defined(HAVE_NETINET_IP_H)
47 #include <netinet/ip.h>
49 #if defined(HAVE_NETINET_IP_MROUTE_H)
50 #include <netinet/ip_mroute.h>
52 #if defined(HAVE_NETINET_IF_ETHER_H)
53 #include <netinet/if_ether.h>
56 #include <sys/ioctl.h>
58 #if defined(HAVE_SYSCALL_H)
61 #if defined(HAVE_SYS_SYSCALL_H)
62 #include <sys/syscall.h>
64 #if defined(HAVE_SYS_EPOLL_H)
65 #include <sys/epoll.h>
67 #if defined(HAVE_SYS_FILE_H)
70 #if defined(HAVE_SYS_MMAN_H)
73 #if defined(HAVE_SYS_PRCTL_H)
74 #include <sys/prctl.h>
76 #if defined(HAVE_SYS_PTRACE_H)
77 #include <sys/ptrace.h>
79 #include <sys/resource.h>
81 #include <sys/socket.h>
84 #include <sys/times.h>
87 #if defined(HAVE_SYS_USER_H)
90 #if defined(HAVE_SYS_UTSNAME_H)
91 #include <sys/utsname.h>
93 #if defined(HAVE_SYS_SELECT_H)
94 #include <sys/select.h>
100 #if defined(HAVE_LINUX_FILTER_H)
101 #include <linux/filter.h>
103 #if defined(HAVE_LINUX_IF_ADDR_H)
104 #include <linux/if_addr.h>
106 #if defined(HAVE_LINUX_IF_ETHER_H)
107 #include <linux/if_ether.h>
109 #if defined(HAVE_LINUX_IF_TUN_H)
110 #include <linux/if_tun.h>
112 #if defined(HAVE_LINUX_NETLINK_H)
113 #include <linux/netlink.h>
115 #if defined(HAVE_LINUX_RTNETLINK_H)
116 #include <linux/rtnetlink.h>
118 #if defined(HAVE_NET_IF_H)
121 #if defined(HAVE_NET_IF_ARP_H)
122 #include <net/if_arp.h>
124 #if defined(HAVE_NET_ROUTE_H)
125 #include <net/route.h>
127 #if defined (HAVE_NETPACKET_PACKET_H)
128 #include <netpacket/packet.h>
130 #if defined(HAVE_SYS_MOUNT_H)
131 #include <sys/mount.h>
133 #if defined(HAVE_SYS_VFS_H)
136 #if defined(HAVE_STATFS_H)
137 #include <sys/statfs.h>
139 #if defined(HAVE_SYS_TIMEX_H)
140 #include <sys/timex.h>
142 #if defined(HAVE_SYS_SYSINFO_H)
143 #include <sys/sysinfo.h>
145 #if defined(HAVE_USTAT_H)
148 #if defined(HAVE_UTIME_H)
151 #if defined(HAVE_LINUX_ETHER_H)
152 #include <linux/ether.h>
154 #if defined(HAVE_LINUX_FS_H)
155 #include <linux/fs.h>
157 #if defined(HAVE_LINUX_REBOOT_H)
158 #include <linux/reboot.h>
160 #if defined(HAVE_SYS_INOTIFY_H)
161 #include <sys/inotify.h>
164 /* Constants that may only be defined as expressions on some systems,
165 expressions too complex for -fdump-go-spec to handle. These are
166 handled specially below. */
169 TIOCGWINSZ_val = TIOCGWINSZ,
174 ${CC} -fdump-go-spec=gen-sysinfo.go -std=gnu99 -S -o sysinfo.s sysinfo.c
176 echo 'package syscall' > ${OUT}
177 echo 'import "unsafe"' >> ${OUT}
178 echo 'type _ unsafe.Pointer' >> ${OUT}
180 # Get all the consts and types, skipping ones which could not be
181 # represented in Go and ones which we need to rewrite. We also skip
182 # function declarations, as we don't need them here. All the symbols
183 # will all have a leading underscore.
184 grep -v '^// ' gen-sysinfo.go | \
186 grep -v '^type _timeval ' | \
187 grep -v '^type _timespec_t ' | \
188 grep -v '^type _timespec ' | \
189 grep -v '^type _timestruc_t ' | \
190 grep -v '^type _epoll_' | \
191 grep -v 'in6_addr' | \
192 grep -v 'sockaddr_in6' | \
193 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
194 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
195 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
196 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
199 # The errno constants. These get type Errno.
200 echo '#include <errno.h>' | ${CC} -x c - -E -dM | \
201 egrep '#define E[A-Z0-9_]+ ' | \
202 sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(_\1)/' >> ${OUT}
205 egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
206 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
207 if ! grep '^const O_ASYNC' ${OUT} >/dev/null 2>&1; then
208 echo "const O_ASYNC = 0" >> ${OUT}
210 if ! grep '^const O_CLOEXEC' ${OUT} >/dev/null 2>&1; then
211 echo "const O_CLOEXEC = 0" >> ${OUT}
214 # The signal numbers.
215 grep '^const _SIG[^_]' gen-sysinfo.go | \
216 grep -v '^const _SIGEV_' | \
217 sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = Signal(_\2)/' >> ${OUT}
219 # The syscall numbers. We force the names to upper case.
220 grep '^const _SYS_' gen-sysinfo.go | \
221 sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \
223 sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
224 echo "const $sup = _$sys" >> ${OUT}
228 grep '^const _S_' gen-sysinfo.go | \
229 sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
232 grep '^const _PROT_' gen-sysinfo.go | \
233 sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
234 grep '^const _MAP_' gen-sysinfo.go | \
235 sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
236 grep '^const _MADV_' gen-sysinfo.go | \
237 sed -e 's/^\(const \)_\(MADV_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
238 grep '^const _MCL_' gen-sysinfo.go | \
239 sed -e 's/^\(const \)_\(MCL_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
241 # Process status constants.
242 grep '^const _W' gen-sysinfo.go |
243 sed -e 's/^\(const \)_\(W[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
244 # WSTOPPED was introduced in glibc 2.3.4.
245 if ! grep '^const _WSTOPPED = ' gen-sysinfo.go >/dev/null 2>&1; then
246 if grep '^const _WUNTRACED = ' gen-sysinfo.go > /dev/null 2>&1; then
247 echo 'const WSTOPPED = _WUNTRACED' >> ${OUT}
249 echo 'const WSTOPPED = 2' >> ${OUT}
252 if grep '^const ___WALL = ' gen-sysinfo.go >/dev/null 2>&1 \
253 && ! grep '^const _WALL = ' gen-sysinfo.go >/dev/null 2>&1; then
254 echo 'const WALL = ___WALL' >> ${OUT}
257 # Networking constants.
258 egrep '^const _(AF|ARPHRD|ETH|IN|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
259 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
260 grep '^const _SOMAXCONN' gen-sysinfo.go |
261 sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
263 grep '^const _SHUT_' gen-sysinfo.go |
264 sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
266 # The net package requires some const definitions.
267 for m in IP_PKTINFO IPV6_V6ONLY IPPROTO_IPV6 IPV6_JOIN_GROUP IPV6_LEAVE_GROUP IPV6_TCLASS; do
268 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
269 echo "const $m = 0" >> ${OUT}
273 # pathconf constants.
274 grep '^const __PC' gen-sysinfo.go |
275 sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
277 # The PATH_MAX constant.
278 if grep '^const _PATH_MAX ' gen-sysinfo.go >/dev/null 2>&1; then
279 echo 'const PathMax = _PATH_MAX' >> ${OUT}
283 grep '^const _EPOLL' gen-sysinfo.go |
284 sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
285 # Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
286 if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
287 echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
289 if ! grep '^const EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
290 echo "const EPOLL_CLOEXEC = 02000000" >> ${OUT}
294 grep '^const _PR_' gen-sysinfo.go |
295 sed -e 's/^\(const \)_\(PR_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
298 grep '^const _PTRACE' gen-sysinfo.go |
299 sed -e 's/^\(const \)_\(PTRACE[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
300 # We need some ptrace options that are not defined in older versions
302 if ! grep '^const PTRACE_SETOPTIONS' ${OUT} > /dev/null 2>&1; then
303 echo "const PTRACE_SETOPTIONS = 0x4200" >> ${OUT}
305 if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then
306 echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
308 if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then
309 echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
311 if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then
312 echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
314 if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then
315 echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
317 if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then
318 echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
320 if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then
321 echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
323 if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then
324 echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
326 if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then
327 echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
329 if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
330 echo "const PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
332 if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
333 echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
335 if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then
336 echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
338 if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then
339 echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
341 if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then
342 echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
344 if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then
345 echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
347 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
348 echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
350 if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
351 echo "const _PTRACE_TRACEME = 0" >> ${OUT}
354 # The registers returned by PTRACE_GETREGS. This is probably
355 # GNU/Linux specific; it should do no harm if there is no
357 regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
358 if test "$regs" != ""; then
359 regs=`echo $regs | sed -e 's/type _user_regs_struct struct //' -e 's/[{}]//g'`
360 regs=`echo $regs | sed -e s'/^ *//'`
362 while test -n "$regs"; do
363 field=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
364 regs=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
365 # Capitalize the first character of the field.
366 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
367 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
368 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
370 nregs="$nregs $field;"
372 echo "type PtraceRegs struct {$nregs }" >> ${OUT}
376 echo 'type Size_t _size_t' >> ${OUT}
377 echo "type Ssize_t _ssize_t" >> ${OUT}
378 if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then
379 echo "type Offset_t _off64_t" >> ${OUT}
381 echo "type Offset_t _off_t" >> ${OUT}
383 echo "type Mode_t _mode_t" >> ${OUT}
384 echo "type Pid_t _pid_t" >> ${OUT}
385 echo "type Uid_t _uid_t" >> ${OUT}
386 echo "type Gid_t _gid_t" >> ${OUT}
387 echo "type Socklen_t _socklen_t" >> ${OUT}
389 # The long type, needed because that is the type that ptrace returns.
390 sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
391 if test "$sizeof_long" = "4"; then
392 echo "type _C_long int32" >> ${OUT}
393 elif test "$sizeof_long" = "8"; then
394 echo "type _C_long int64" >> ${OUT}
396 echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
400 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
401 # double is commented by -fdump-go-spec.
402 if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
403 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
405 if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
406 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
410 if grep '^type _time_t ' gen-sysinfo.go > /dev/null 2>&1; then
411 echo 'type Time_t _time_t' >> ${OUT}
414 # The time structures need special handling: we need to name the
415 # types, so that we can cast integers to the right types when
416 # assigning to the structures.
417 timeval=`grep '^type _timeval ' gen-sysinfo.go`
418 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
419 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
420 echo "type Timeval_sec_t $timeval_sec" >> ${OUT}
421 echo "type Timeval_usec_t $timeval_usec" >> ${OUT}
423 sed -e 's/type _timeval /type Timeval /' \
424 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
425 -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
426 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
427 if test "$timespec" = ""; then
428 # IRIX 6.5 has __timespec instead.
429 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
431 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
432 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
433 echo "type Timespec_sec_t $timespec_sec" >> ${OUT}
434 echo "type Timespec_nsec_t $timespec_nsec" >> ${OUT}
436 sed -e 's/^type ___timespec /type Timespec /' \
437 -e 's/^type _timespec /type Timespec /' \
438 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
439 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
441 timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
442 if test "$timestruc" != ""; then
443 timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
444 timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
445 echo "type Timestruc_sec_t $timestruc_sec" >> ${OUT}
446 echo "type Timestruc_nsec_t $timestruc_nsec" >> ${OUT}
448 sed -e 's/^type _timestruc_t /type Timestruc /' \
449 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
450 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
454 grep '^type _tms ' gen-sysinfo.go | \
455 sed -e 's/type _tms/type Tms/' \
456 -e 's/tms_utime/Utime/' \
457 -e 's/tms_stime/Stime/' \
458 -e 's/tms_cutime/Cutime/' \
459 -e 's/tms_cstime/Cstime/' \
463 # Prefer largefile variant if available.
464 stat=`grep '^type _stat64 ' gen-sysinfo.go || true`
465 if test "$stat" != ""; then
466 grep '^type _stat64 ' gen-sysinfo.go
468 grep '^type _stat ' gen-sysinfo.go
469 fi | sed -e 's/type _stat64/type Stat_t/' \
470 -e 's/type _stat/type Stat_t/' \
472 -e 's/st_ino/Ino/g' \
473 -e 's/st_nlink/Nlink/' \
474 -e 's/st_mode/Mode/' \
477 -e 's/st_rdev/Rdev/' \
478 -e 's/st_size/Size/' \
479 -e 's/st_blksize/Blksize/' \
480 -e 's/st_blocks/Blocks/' \
481 -e 's/st_atim/Atim/' \
482 -e 's/st_mtim/Mtim/' \
483 -e 's/st_ctim/Ctim/' \
484 -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
485 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
486 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
487 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
488 -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
491 # The directory searching types.
492 # Prefer largefile variant if available.
493 dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true`
494 if test "$dirent" != ""; then
495 grep '^type _dirent64 ' gen-sysinfo.go
497 grep '^type _dirent ' gen-sysinfo.go
498 fi | sed -e 's/type _dirent64/type Dirent/' \
499 -e 's/type _dirent/type Dirent/' \
500 -e 's/d_name \[0+1\]/d_name [0+256]/' \
501 -e 's/d_name/Name/' \
502 -e 's/]int8/]byte/' \
505 -e 's/d_reclen/Reclen/' \
506 -e 's/d_type/Type/' \
508 echo "type DIR _DIR" >> ${OUT}
510 # Values for d_type field in dirent.
511 grep '^const _DT_' gen-sysinfo.go |
512 sed -e 's/^\(const \)_\(DT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
515 rusage=`grep '^type _rusage struct' gen-sysinfo.go`
516 if test "$rusage" != ""; then
517 rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
518 rusage=`echo $rusage | sed -e 's/^ *//'`
520 while test -n "$rusage"; do
521 field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
522 rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
523 # Drop the leading ru_, capitalize the next character.
524 field=`echo $field | sed -e 's/^ru_//'`
525 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
526 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
527 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
528 # Fix _timeval _timespec, and _timestruc_t.
529 r=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
530 r=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
531 r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
533 nrusage="$nrusage $field;"
535 echo "type Rusage struct {$nrusage }" >> ${OUT}
537 echo "type Rusage struct {}" >> ${OUT}
540 # The RUSAGE constants.
541 grep '^const _RUSAGE_' gen-sysinfo.go | \
542 sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
544 # The utsname struct.
545 grep '^type _utsname ' gen-sysinfo.go | \
546 sed -e 's/_utsname/Utsname/' \
547 -e 's/sysname/Sysname/' \
548 -e 's/nodename/Nodename/' \
549 -e 's/release/Release/' \
550 -e 's/version/Version/' \
551 -e 's/machine/Machine/' \
552 -e 's/domainname/Domainname/' \
556 iovec=`grep '^type _iovec ' gen-sysinfo.go`
557 iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
558 echo "type Iovec_len_t $iovec_len" >> ${OUT}
560 sed -e 's/_iovec/Iovec/' \
561 -e 's/iov_base/Base/' \
562 -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
566 msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
567 msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
568 echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
570 sed -e 's/_msghdr/Msghdr/' \
571 -e 's/msg_name/Name/' \
572 -e 's/msg_namelen/Namelen/' \
573 -e 's/msg_iov/Iov/' \
574 -e 's/msg_iovlen/Iovlen/' \
575 -e 's/_iovec/Iovec/' \
576 -e 's/msg_control/Control/' \
577 -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
578 -e 's/msg_flags/Flags/' \
581 # The MSG_ flags for Msghdr.
582 grep '^const _MSG_' gen-sysinfo.go | \
583 sed -e 's/^\(const \)_\(MSG_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
585 # The cmsghdr struct.
586 cmsghdr=`grep '^type _cmsghdr ' gen-sysinfo.go`
587 if test -n "$cmsghdr"; then
588 cmsghdr_len=`echo $cmsghdr | sed -n -e 's/^.*cmsg_len \([^ ]*\);.*$/\1/p'`
589 echo "type Cmsghdr_len_t $cmsghdr_len" >> ${OUT}
591 sed -e 's/_cmsghdr/Cmsghdr/' \
592 -e 's/cmsg_len *[a-zA-Z0-9_]*/Len Cmsghdr_len_t/' \
593 -e 's/cmsg_level/Level/' \
594 -e 's/cmsg_type/Type/' \
599 # The SCM_ flags for Cmsghdr.
600 grep '^const _SCM_' gen-sysinfo.go | \
601 sed -e 's/^\(const \)_\(SCM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
604 grep '^type _ucred ' gen-sysinfo.go | \
605 sed -e 's/_ucred/Ucred/' \
611 # The ip_mreq struct.
612 grep '^type _ip_mreq ' gen-sysinfo.go | \
613 sed -e 's/_ip_mreq/IPMreq/' \
614 -e 's/imr_multiaddr/Multiaddr/' \
615 -e 's/imr_interface/Interface/' \
616 -e 's/_in_addr/[4]byte/g' \
619 # We need IPMreq to compile the net package.
620 if ! grep 'type IPMreq ' ${OUT} >/dev/null 2>&1; then
621 echo 'type IPMreq struct { Multiaddr [4]byte; Interface [4]byte; }' >> ${OUT}
624 # The ipv6_mreq struct.
625 grep '^type _ipv6_mreq ' gen-sysinfo.go | \
626 sed -e 's/_ipv6_mreq/IPv6Mreq/' \
627 -e 's/ipv6mr_multiaddr/Multiaddr/' \
628 -e 's/ipv6mr_interface/Interface/' \
629 -e 's/_in6_addr/[16]byte/' \
632 # We need IPv6Mreq to compile the net package.
633 if ! grep 'type IPv6Mreq ' ${OUT} >/dev/null 2>&1; then
634 echo 'type IPv6Mreq struct { Multiaddr [16]byte; Interface uint32; }' >> ${OUT}
637 # The ip_mreqn struct.
638 grep '^type _ip_mreqn ' gen-sysinfo.go | \
639 sed -e 's/_ip_mreqn/IPMreqn/' \
640 -e 's/imr_multiaddr/Multiaddr/' \
641 -e 's/imr_address/Address/' \
642 -e 's/imr_ifindex/Ifindex/' \
643 -e 's/_in_addr/[4]byte/g' \
646 # We need IPMreq to compile the net package.
647 if ! grep 'type IPMreqn ' ${OUT} >/dev/null 2>&1; then
648 echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT}
651 # Try to guess the type to use for fd_set.
652 fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
653 fds_bits_type="_C_long"
654 if test "$fd_set" != ""; then
655 fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
657 echo "type fds_bits_type $fds_bits_type" >> ${OUT}
659 # The addrinfo struct.
660 grep '^type _addrinfo ' gen-sysinfo.go | \
661 sed -e 's/_addrinfo/Addrinfo/g' \
665 # The addrinfo flags and errors.
666 grep '^const _AI_' gen-sysinfo.go | \
667 sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
668 grep '^const _EAI_' gen-sysinfo.go | \
669 sed -e 's/^\(const \)_\(EAI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
672 grep '^type _passwd ' gen-sysinfo.go | \
673 sed -e 's/_passwd/Passwd/' \
677 # The ioctl flags for the controlling TTY.
678 grep '^const _TIOC' gen-sysinfo.go | \
680 sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
681 # We need TIOCGWINSZ.
682 if ! grep '^const TIOCGWINSZ' ${OUT} >/dev/null 2>&1; then
683 if grep '^const _TIOCGWINSZ_val' ${OUT} >/dev/null 2>&1; then
684 echo 'const TIOCGWINSZ = _TIOCGWINSZ_val' >> ${OUT}
688 # The ioctl flags for terminal control
689 grep '^const _TC[GS]ET' gen-sysinfo.go | \
690 sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
692 # ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but
693 # needs handling in syscalls.exec.go.
694 if ! grep '^const _TIOCSCTTY ' gen-sysinfo.go >/dev/null 2>&1; then
695 if grep '^const _TIOCNXCL ' gen-sysinfo.go >/dev/null 2>&1; then
696 echo "const TIOCSCTTY = TIOCNXCL" >> ${OUT}
700 # The nlmsghdr struct.
701 grep '^type _nlmsghdr ' gen-sysinfo.go | \
702 sed -e 's/_nlmsghdr/NlMsghdr/' \
703 -e 's/nlmsg_len/Len/' \
704 -e 's/nlmsg_type/Type/' \
705 -e 's/nlmsg_flags/Flags/' \
706 -e 's/nlmsg_seq/Seq/' \
707 -e 's/nlmsg_pid/Pid/' \
710 # The nlmsg flags and operators.
711 grep '^const _NLM' gen-sysinfo.go | \
712 sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
714 # NLMSG_HDRLEN is defined as an expression using sizeof.
715 if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev/null 2>&1; then
716 if grep '^const _sizeof_nlmsghdr ' ${OUT} > /dev/null 2>&1; then
717 echo 'const NLMSG_HDRLEN = (_sizeof_nlmsghdr + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1)' >> ${OUT}
722 grep '^type _rtmsg ' gen-sysinfo.go | \
723 sed -e 's/_rtmsg/RtMsg/' \
724 -e 's/rtm_family/Family/' \
725 -e 's/rtm_dst_len/Dst_len/' \
726 -e 's/rtm_src_len/Src_len/' \
727 -e 's/rtm_tos/Tos/' \
728 -e 's/rtm_table/Table/' \
729 -e 's/rtm_protocol/Protocol/' \
730 -e 's/rtm_scope/Scope/' \
731 -e 's/rtm_type/Type/' \
732 -e 's/rtm_flags/Flags/' \
735 # The rtgenmsg struct.
736 grep '^type _rtgenmsg ' gen-sysinfo.go | \
737 sed -e 's/_rtgenmsg/RtGenmsg/' \
738 -e 's/rtgen_family/Family/' \
741 # The routing message flags.
742 grep '^const _RT_' gen-sysinfo.go | \
743 sed -e 's/^\(const \)_\(RT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
744 grep '^const _RTA' gen-sysinfo.go | \
745 sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
746 grep '^const _RTF' gen-sysinfo.go | \
747 sed -e 's/^\(const \)_\(RTF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
748 grep '^const _RTCF' gen-sysinfo.go | \
749 sed -e 's/^\(const \)_\(RTCF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
750 grep '^const _RTM' gen-sysinfo.go | \
751 sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
752 grep '^const _RTN' gen-sysinfo.go | \
753 sed -e 's/^\(const \)_\(RTN[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
754 grep '^const _RTPROT' gen-sysinfo.go | \
755 sed -e 's/^\(const \)_\(RTPROT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
757 # The ifinfomsg struct.
758 grep '^type _ifinfomsg ' gen-sysinfo.go | \
759 sed -e 's/_ifinfomsg/IfInfomsg/' \
760 -e 's/ifi_family/Family/' \
761 -e 's/ifi_type/Type/' \
762 -e 's/ifi_index/Index/' \
763 -e 's/ifi_flags/Flags/' \
764 -e 's/ifi_change/Change/' \
767 # The interface information types and flags.
768 grep '^const _IFA' gen-sysinfo.go | \
769 sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
770 grep '^const _IFLA' gen-sysinfo.go | \
771 sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
772 grep '^const _IFF' gen-sysinfo.go | \
773 sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
774 grep '^const _IFNAMSIZ' gen-sysinfo.go | \
775 sed -e 's/^\(const \)_\(IFNAMSIZ[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
776 grep '^const _SIOC' gen-sysinfo.go |
777 sed -e 's/^\(const \)_\(SIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
779 # The ifaddrmsg struct.
780 grep '^type _ifaddrmsg ' gen-sysinfo.go | \
781 sed -e 's/_ifaddrmsg/IfAddrmsg/' \
782 -e 's/ifa_family/Family/' \
783 -e 's/ifa_prefixlen/Prefixlen/' \
784 -e 's/ifa_flags/Flags/' \
785 -e 's/ifa_scope/Scope/' \
786 -e 's/ifa_index/Index/' \
790 grep '^type _rtattr ' gen-sysinfo.go | \
791 sed -e 's/_rtattr/RtAttr/' \
792 -e 's/rta_len/Len/' \
793 -e 's/rta_type/Type/' \
796 # The in_pktinfo struct.
797 grep '^type _in_pktinfo ' gen-sysinfo.go | \
798 sed -e 's/_in_pktinfo/Inet4Pktinfo/' \
799 -e 's/ipi_ifindex/Ifindex/' \
800 -e 's/ipi_spec_dst/Spec_dst/' \
801 -e 's/ipi_addr/Addr/' \
802 -e 's/_in_addr/[4]byte/g' \
805 # The in6_pktinfo struct.
806 grep '^type _in6_pktinfo ' gen-sysinfo.go | \
807 sed -e 's/_in6_pktinfo/Inet6Pktinfo/' \
808 -e 's/ipi6_addr/Addr/' \
809 -e 's/ipi6_ifindex/Ifindex/' \
810 -e 's/_in6_addr/[16]byte/' \
813 # The termios struct.
814 grep '^type _termios ' gen-sysinfo.go | \
815 sed -e 's/_termios/Termios/' \
816 -e 's/c_iflag/Iflag/' \
817 -e 's/c_oflag/Oflag/' \
818 -e 's/c_cflag/Cflag/' \
819 -e 's/c_lflag/Lflag/' \
820 -e 's/c_line/Line/' \
822 -e 's/c_ispeed/Ispeed/' \
823 -e 's/c_ospeed/Ospeed/' \
826 # The termios constants.
827 for n in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \
828 IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \
829 OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 CS5 CS6 CS7 CS8 TABDLY \
830 BSDLY VTDLY FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL \
831 CLOCAL LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE ECHO ECHOE ECHOK \
832 ECHONL ECHOCTL ECHOPRT ECHOKE DEFECHO FLUSHO NOFLSH TOSTOP PENDIN IEXTEN \
833 VINTR VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 VSWTCH VSTART VSTOP \
834 VSUSP VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS TCSANOW TCSADRAIN \
835 TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON TCIOFF TCION B0 B50 \
836 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 \
837 B38400 B57600 B115200 B230400 B460800 B500000 B576000 B921600 B1000000 \
838 B1152000 B1500000 B2000000 B2500000 B3000000 B3500000 B4000000; do
840 grep "^const _$n " gen-sysinfo.go | \
841 sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
845 grep '^const _MNT_' gen-sysinfo.go |
846 sed -e 's/^\(const \)_\(MNT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
847 grep '^const _MS_' gen-sysinfo.go |
848 sed -e 's/^\(const \)_\(MS_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
850 # The fallocate flags.
851 grep '^const _FALLOC_' gen-sysinfo.go |
852 sed -e 's/^\(const \)_\(FALLOC_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
855 # Prefer largefile variant if available.
856 statfs=`grep '^type _statfs64 ' gen-sysinfo.go || true`
857 if test "$statfs" != ""; then
858 grep '^type _statfs64 ' gen-sysinfo.go
860 grep '^type _statfs ' gen-sysinfo.go
861 fi | sed -e 's/type _statfs64/type Statfs_t/' \
862 -e 's/type _statfs/type Statfs_t/' \
863 -e 's/f_type/Type/' \
864 -e 's/f_bsize/Bsize/' \
865 -e 's/f_blocks/Blocks/' \
866 -e 's/f_bfree/Bfree/' \
867 -e 's/f_bavail/Bavail/' \
868 -e 's/f_files/Files/' \
869 -e 's/f_ffree/Ffree/' \
870 -e 's/f_fsid/Fsid/' \
871 -e 's/f_namelen/Namelen/' \
872 -e 's/f_frsize/Frsize/' \
873 -e 's/f_flags/Flags/' \
874 -e 's/f_spare/Spare/' \
878 timex=`grep '^type _timex ' gen-sysinfo.go || true`
879 if test "$timex" = ""; then
880 timex=`grep '^// type _timex ' gen-sysinfo.go || true`
881 if test "$timex" != ""; then
882 timex=`echo $timex | sed -e 's|// ||' -e 's/INVALID-bit-field/int32/g'`
885 if test "$timex" != ""; then
887 sed -e 's/_timex/Timex/' \
888 -e 's/modes/Modes/' \
889 -e 's/offset/Offset/' \
891 -e 's/maxerror/Maxerror/' \
892 -e 's/esterror/Esterror/' \
893 -e 's/status/Status/' \
894 -e 's/constant/Constant/' \
895 -e 's/precision/Precision/' \
896 -e 's/tolerance/Tolerance/' \
897 -e 's/ time / Time /' \
899 -e 's/ppsfreq/Ppsfreq/' \
900 -e 's/jitter/Jitter/' \
901 -e 's/shift/Shift/' \
902 -e 's/stabil/Stabil/' \
903 -e 's/jitcnt/Jitcnt/' \
904 -e 's/calcnt/Calcnt/' \
905 -e 's/errcnt/Errcnt/' \
906 -e 's/stbcnt/Stbcnt/' \
908 -e 's/_timeval/Timeval/' \
913 grep '^type _rlimit ' gen-sysinfo.go | \
914 sed -e 's/_rlimit/Rlimit/' \
915 -e 's/rlim_cur/Cur/' \
916 -e 's/rlim_max/Max/' \
919 # The RLIMIT constants.
920 grep '^const _RLIMIT_' gen-sysinfo.go |
921 sed -e 's/^\(const \)_\(RLIMIT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
922 grep '^const _RLIM_' gen-sysinfo.go |
923 sed -e 's/^\(const \)_\(RLIM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
925 # The sysinfo struct.
926 grep '^type _sysinfo ' gen-sysinfo.go | \
927 sed -e 's/_sysinfo/Sysinfo_t/' \
928 -e 's/uptime/Uptime/' \
929 -e 's/loads/Loads/' \
930 -e 's/totalram/Totalram/' \
931 -e 's/freeram/Freeram/' \
932 -e 's/sharedram/Sharedram/' \
933 -e 's/bufferram/Bufferram/' \
934 -e 's/totalswap/Totalswap/' \
935 -e 's/freeswap/Freeswap/' \
936 -e 's/procs/Procs/' \
937 -e 's/totalhigh/Totalhigh/' \
938 -e 's/freehigh/Freehigh/' \
939 -e 's/mem_unit/Unit/' \
943 grep '^type _ustat ' gen-sysinfo.go | \
944 sed -e 's/_ustat/Ustat_t/' \
945 -e 's/f_tfree/Tfree/' \
946 -e 's/f_tinode/Tinoe/' \
947 -e 's/f_fname/Fname/' \
948 -e 's/f_fpack/Fpack/' \
950 # Force it to be defined, as on some older GNU/Linux systems the
951 # header file fails when using with <linux/filter.h>.
952 if ! grep 'type _ustat ' gen-sysinfo.go >/dev/null 2>&1; then
953 echo 'type Ustat_t struct { Tfree int32; Tinoe uint64; Fname [5+1]int8; Fpack [5+1]int8; }' >> ${OUT}
956 # The utimbuf struct.
957 grep '^type _utimbuf ' gen-sysinfo.go | \
958 sed -e 's/_utimbuf/Utimbuf/' \
959 -e 's/actime/Actime/' \
960 -e 's/modtime/Modtime/' \
963 # The LOCK flags for flock.
964 grep '^const _LOCK_' gen-sysinfo.go |
965 sed -e 's/^\(const \)_\(LOCK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
967 # The GNU/Linux LINUX_REBOOT flags.
968 grep '^const _LINUX_REBOOT_' gen-sysinfo.go |
969 sed -e 's/^\(const \)_\(LINUX_REBOOT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
971 # The GNU/Linux sock_filter struct.
972 grep '^type _sock_filter ' gen-sysinfo.go | \
973 sed -e 's/_sock_filter/SockFilter/' \
980 # The GNU/Linux sock_fprog struct.
981 grep '^type _sock_fprog ' gen-sysinfo.go | \
982 sed -e 's/_sock_fprog/SockFprog/' \
984 -e 's/filter/Filter/' \
985 -e 's/_sock_filter/SockFilter/' \
988 # The GNU/Linux filter flags.
989 grep '^const _BPF_' gen-sysinfo.go | \
990 sed -e 's/^\(const \)_\(BPF_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
992 # The GNU/Linux nlattr struct.
993 grep '^type _nlattr ' gen-sysinfo.go | \
994 sed -e 's/_nlattr/NlAttr/' \
995 -e 's/nla_len/Len/' \
996 -e 's/nla_type/Type/' \
999 # The GNU/Linux nlmsgerr struct.
1000 grep '^type _nlmsgerr ' gen-sysinfo.go | \
1001 sed -e 's/_nlmsgerr/NlMsgerr/' \
1002 -e 's/error/Error/' \
1004 -e 's/_nlmsghdr/NlMsghdr/' \
1007 # The GNU/Linux rtnexthop struct.
1008 grep '^type _rtnexthop ' gen-sysinfo.go | \
1009 sed -e 's/_rtnexthop/RtNexthop/' \
1010 -e 's/rtnh_len/Len/' \
1011 -e 's/rtnh_flags/Flags/' \
1012 -e 's/rtnh_hops/Hops/' \
1013 -e 's/rtnh_ifindex/Ifindex/' \
1016 # The GNU/Linux netlink flags.
1017 grep '^const _NETLINK_' gen-sysinfo.go | \
1018 sed -e 's/^\(const \)_\(NETLINK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1019 grep '^const _NLA_' gen-sysinfo.go | \
1020 sed -e 's/^\(const \)_\(NLA_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1022 # The GNU/Linux packet socket flags.
1023 grep '^const _PACKET_' gen-sysinfo.go | \
1024 sed -e 's/^\(const \)_\(PACKET_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1026 # The GNU/Linux inotify_event struct.
1027 grep '^type _inotify_event ' gen-sysinfo.go | \
1028 sed -e 's/_inotify_event/InotifyEvent/' \
1031 -e 's/cookie/Cookie/' \
1035 -e 's/\[0\]byte/[0]int8/' \
1038 # The Solaris 11 Update 1 _zone_net_addr_t struct.
1039 grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
1040 sed -e 's/_in6_addr/[16]byte/' \
1044 set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \
1045 ifaddrmsg IfAddrmsg ifinfomsg IfInfomsg in_pktinfo Inet4Pktinfo \
1046 in6_pktinfo Inet6Pktinfo inotify_event InotifyEvent linger Linger \
1047 msghdr Msghdr nlattr NlAttr nlmsgerr NlMsgerr nlmsghdr NlMsghdr \
1048 rtattr RtAttr rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \
1049 sock_filter SockFilter sock_fprog SockFprog ucred Ucred
1050 while test $# != 0; do
1055 if grep "^const _sizeof_$nc =" gen-sysinfo.go >/dev/null 2>&1; then
1056 echo "const Sizeof$ngo = _sizeof_$nc" >> ${OUT}
1060 # In order to compile the net package, we need some sizes to exist
1061 # even if the types do not.
1062 if ! grep 'const SizeofIPMreq ' ${OUT} >/dev/null 2>&1; then
1063 echo 'const SizeofIPMreq = 8' >> ${OUT}
1065 if ! grep 'const SizeofIPv6Mreq ' ${OUT} >/dev/null 2>&1; then
1066 echo 'const SizeofIPv6Mreq = 20' >> ${OUT}
1068 if ! grep 'const SizeofIPMreqn ' ${OUT} >/dev/null 2>&1; then
1069 echo 'const SizeofIPMreqn = 12' >> ${OUT}