+# The in_pktinfo struct.
+grep '^type _in_pktinfo ' gen-sysinfo.go | \
+ sed -e 's/_in_pktinfo/Inet4Pktinfo/' \
+ -e 's/ipi_ifindex/Ifindex/' \
+ -e 's/ipi_spec_dst/Spec_dst/' \
+ -e 's/ipi_addr/Addr/' \
+ -e 's/_in_addr/[4]byte/g' \
+ >> ${OUT}
+
+# The in6_pktinfo struct.
+grep '^type _in6_pktinfo ' gen-sysinfo.go | \
+ sed -e 's/_in6_pktinfo/Inet6Pktinfo/' \
+ -e 's/ipi6_addr/Addr/' \
+ -e 's/ipi6_ifindex/Ifindex/' \
+ -e 's/_in6_addr/[16]byte/' \
+ >> ${OUT}
+
+# The termios struct.
+grep '^type _termios ' gen-sysinfo.go | \
+ sed -e 's/_termios/Termios/' \
+ -e 's/c_iflag/Iflag/' \
+ -e 's/c_oflag/Oflag/' \
+ -e 's/c_cflag/Cflag/' \
+ -e 's/c_lflag/Lflag/' \
+ -e 's/c_line/Line/' \
+ -e 's/c_cc/Cc/' \
+ -e 's/c_ispeed/Ispeed/' \
+ -e 's/c_ospeed/Ospeed/' \
+ >> ${OUT}
+
+# The termios constants.
+for n in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \
+ IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \
+ OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 CS5 CS6 CS7 CS8 TABDLY \
+ BSDLY VTDLY FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL \
+ CLOCAL LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE ECHO ECHOE ECHOK \
+ ECHONL ECHOCTL ECHOPRT ECHOKE DEFECHO FLUSHO NOFLSH TOSTOP PENDIN IEXTEN \
+ VINTR VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 VSWTCH VSTART VSTOP \
+ VSUSP VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS TCSANOW TCSADRAIN \
+ TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON TCIOFF TCION B0 B50 \
+ B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 \
+ B38400 B57600 B115200 B230400 B460800 B500000 B576000 B921600 B1000000 \
+ B1152000 B1500000 B2000000 B2500000 B3000000 B3500000 B4000000; do
+
+ grep "^const _$n " gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+done
+
+# The mount flags
+grep '^const _MNT_' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(MNT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+grep '^const _MS_' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(MS_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The fallocate flags.
+grep '^const _FALLOC_' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(FALLOC_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The statfs struct.
+# Prefer largefile variant if available.
+statfs=`grep '^type _statfs64 ' gen-sysinfo.go || true`
+if test "$statfs" != ""; then
+ grep '^type _statfs64 ' gen-sysinfo.go
+else
+ grep '^type _statfs ' gen-sysinfo.go
+fi | sed -e 's/type _statfs64/type Statfs_t/' \
+ -e 's/type _statfs/type Statfs_t/' \
+ -e 's/f_type/Type/' \
+ -e 's/f_bsize/Bsize/' \
+ -e 's/f_blocks/Blocks/' \
+ -e 's/f_bfree/Bfree/' \
+ -e 's/f_bavail/Bavail/' \
+ -e 's/f_files/Files/' \
+ -e 's/f_ffree/Ffree/' \
+ -e 's/f_fsid/Fsid/' \
+ -e 's/f_namelen/Namelen/' \
+ -e 's/f_frsize/Frsize/' \
+ -e 's/f_flags/Flags/' \
+ -e 's/f_spare/Spare/' \
+ >> ${OUT}
+
+# The timex struct.
+timex=`grep '^type _timex ' gen-sysinfo.go || true`
+if test "$timex" = ""; then
+ timex=`grep '^// type _timex ' gen-sysinfo.go || true`
+ if test "$timex" != ""; then
+ timex=`echo $timex | sed -e 's|// ||' -e 's/INVALID-bit-field/int32/g'`
+ fi
+fi
+if test "$timex" != ""; then
+ echo "$timex" | \
+ sed -e 's/_timex/Timex/' \
+ -e 's/modes/Modes/' \
+ -e 's/offset/Offset/' \
+ -e 's/freq/Freq/' \
+ -e 's/maxerror/Maxerror/' \
+ -e 's/esterror/Esterror/' \
+ -e 's/status/Status/' \
+ -e 's/constant/Constant/' \
+ -e 's/precision/Precision/' \
+ -e 's/tolerance/Tolerance/' \
+ -e 's/ time / Time /' \
+ -e 's/tick/Tick/' \
+ -e 's/ppsfreq/Ppsfreq/' \
+ -e 's/jitter/Jitter/' \
+ -e 's/shift/Shift/' \
+ -e 's/stabil/Stabil/' \
+ -e 's/jitcnt/Jitcnt/' \
+ -e 's/calcnt/Calcnt/' \
+ -e 's/errcnt/Errcnt/' \
+ -e 's/stbcnt/Stbcnt/' \
+ -e 's/tai/Tai/' \
+ -e 's/_timeval/Timeval/' \
+ >> ${OUT}
+fi
+
+# The rlimit struct.
+grep '^type _rlimit ' gen-sysinfo.go | \
+ sed -e 's/_rlimit/Rlimit/' \
+ -e 's/rlim_cur/Cur/' \
+ -e 's/rlim_max/Max/' \
+ >> ${OUT}
+
+# The RLIMIT constants.
+grep '^const _RLIMIT_' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(RLIMIT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+grep '^const _RLIM_' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(RLIM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The sysinfo struct.
+grep '^type _sysinfo ' gen-sysinfo.go | \
+ sed -e 's/_sysinfo/Sysinfo_t/' \
+ -e 's/uptime/Uptime/' \
+ -e 's/loads/Loads/' \
+ -e 's/totalram/Totalram/' \
+ -e 's/freeram/Freeram/' \
+ -e 's/sharedram/Sharedram/' \
+ -e 's/bufferram/Bufferram/' \
+ -e 's/totalswap/Totalswap/' \
+ -e 's/freeswap/Freeswap/' \
+ -e 's/procs/Procs/' \
+ -e 's/totalhigh/Totalhigh/' \
+ -e 's/freehigh/Freehigh/' \
+ -e 's/mem_unit/Unit/' \
+ >> ${OUT}
+
+# The ustat struct.
+grep '^type _ustat ' gen-sysinfo.go | \
+ sed -e 's/_ustat/Ustat_t/' \
+ -e 's/f_tfree/Tfree/' \
+ -e 's/f_tinode/Tinoe/' \
+ -e 's/f_fname/Fname/' \
+ -e 's/f_fpack/Fpack/' \
+ >> ${OUT}
+# Force it to be defined, as on some older GNU/Linux systems the
+# header file fails when using with <linux/filter.h>.
+if ! grep 'type _ustat ' gen-sysinfo.go >/dev/null 2>&1; then
+ echo 'type Ustat_t struct { Tfree int32; Tinoe uint64; Fname [5+1]int8; Fpack [5+1]int8; }' >> ${OUT}
+fi
+
+# The utimbuf struct.
+grep '^type _utimbuf ' gen-sysinfo.go | \
+ sed -e 's/_utimbuf/Utimbuf/' \
+ -e 's/actime/Actime/' \
+ -e 's/modtime/Modtime/' \
+ >> ${OUT}
+
+# The LOCK flags for flock.
+grep '^const _LOCK_' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(LOCK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The PRIO constants.
+grep '^const _PRIO_' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(PRIO_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The GNU/Linux LINUX_REBOOT flags.
+grep '^const _LINUX_REBOOT_' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(LINUX_REBOOT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The GNU/Linux sock_filter struct.
+grep '^type _sock_filter ' gen-sysinfo.go | \
+ sed -e 's/_sock_filter/SockFilter/' \
+ -e 's/code/Code/' \
+ -e 's/jt/Jt/' \
+ -e 's/jf/Jf/' \
+ -e 's/k /K /' \
+ >> ${OUT}
+
+# The GNU/Linux sock_fprog struct.
+grep '^type _sock_fprog ' gen-sysinfo.go | \
+ sed -e 's/_sock_fprog/SockFprog/' \
+ -e 's/len/Len/' \
+ -e 's/filter/Filter/' \
+ -e 's/_sock_filter/SockFilter/' \
+ >> ${OUT}
+
+# The GNU/Linux filter flags.
+grep '^const _BPF_' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(BPF_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The GNU/Linux nlattr struct.
+grep '^type _nlattr ' gen-sysinfo.go | \
+ sed -e 's/_nlattr/NlAttr/' \
+ -e 's/nla_len/Len/' \
+ -e 's/nla_type/Type/' \
+ >> ${OUT}
+
+# The GNU/Linux nlmsgerr struct.
+grep '^type _nlmsgerr ' gen-sysinfo.go | \
+ sed -e 's/_nlmsgerr/NlMsgerr/' \
+ -e 's/error/Error/' \
+ -e 's/msg/Msg/' \
+ -e 's/_nlmsghdr/NlMsghdr/' \
+ >> ${OUT}
+
+# The GNU/Linux rtnexthop struct.
+grep '^type _rtnexthop ' gen-sysinfo.go | \
+ sed -e 's/_rtnexthop/RtNexthop/' \
+ -e 's/rtnh_len/Len/' \
+ -e 's/rtnh_flags/Flags/' \
+ -e 's/rtnh_hops/Hops/' \
+ -e 's/rtnh_ifindex/Ifindex/' \
+ >> ${OUT}
+
+# The GNU/Linux netlink flags.
+grep '^const _NETLINK_' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(NETLINK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+grep '^const _NLA_' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(NLA_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The GNU/Linux packet socket flags.
+grep '^const _PACKET_' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(PACKET_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The GNU/Linux inotify_event struct.
+grep '^type _inotify_event ' gen-sysinfo.go | \
+ sed -e 's/_inotify_event/InotifyEvent/' \
+ -e 's/wd/Wd/' \
+ -e 's/mask/Mask/' \
+ -e 's/cookie/Cookie/' \
+ -e 's/len/Len/' \
+ -e 's/name/Name/' \
+ -e 's/\[\]/[0]/' \
+ -e 's/\[0\]byte/[0]int8/' \
+ >> ${OUT}
+
+# The GNU/Linux CLONE flags.
+grep '^const _CLONE_' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(CLONE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# Struct sizes.
+set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \
+ ifaddrmsg IfAddrmsg ifinfomsg IfInfomsg in_pktinfo Inet4Pktinfo \
+ in6_pktinfo Inet6Pktinfo inotify_event InotifyEvent linger Linger \
+ msghdr Msghdr nlattr NlAttr nlmsgerr NlMsgerr nlmsghdr NlMsghdr \
+ rtattr RtAttr rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \
+ sock_filter SockFilter sock_fprog SockFprog ucred Ucred \
+ icmp6_filter ICMPv6Filter
+while test $# != 0; do
+ nc=$1
+ ngo=$2
+ shift
+ shift
+ if grep "^const _sizeof_$nc =" gen-sysinfo.go >/dev/null 2>&1; then
+ echo "const Sizeof$ngo = _sizeof_$nc" >> ${OUT}
+ fi
+done
+
+# In order to compile the net package, we need some sizes to exist
+# even if the types do not.
+if ! grep 'const SizeofIPMreq ' ${OUT} >/dev/null 2>&1; then
+ echo 'const SizeofIPMreq = 8' >> ${OUT}
+fi
+if ! grep 'const SizeofIPv6Mreq ' ${OUT} >/dev/null 2>&1; then
+ echo 'const SizeofIPv6Mreq = 20' >> ${OUT}
+fi
+if ! grep 'const SizeofIPMreqn ' ${OUT} >/dev/null 2>&1; then
+ echo 'const SizeofIPMreqn = 12' >> ${OUT}
+fi
+if ! grep 'const SizeofICMPv6Filter ' ${OUT} >/dev/null 2>&1; then
+ echo 'const SizeofICMPv6Filter = 32' >> ${OUT}