2b5acd6051f1be80f1f4c95353c8b053b7b4cc0f
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.
29 #define _LARGEFILE_SOURCE
30 #define _FILE_OFFSET_BITS 64
32 #include <sys/types.h>
36 #include <netinet/in.h>
37 /* <netinet/tcp.h> needs u_char/u_short, but <sys/bsd_types> is only
38 included by <netinet/in.h> if _SGIAPI (i.e. _SGI_SOURCE
41 #include <sys/bsd_types.h>
43 #include <netinet/tcp.h>
45 #include <sys/ioctl.h>
47 #if defined(HAVE_SYSCALL_H)
50 #if defined(HAVE_SYS_SYSCALL_H)
51 #include <sys/syscall.h>
53 #if defined(HAVE_SYS_EPOLL_H)
54 #include <sys/epoll.h>
56 #if defined(HAVE_SYS_MMAN_H)
59 #if defined(HAVE_SYS_PTRACE_H)
60 #include <sys/ptrace.h>
62 #include <sys/resource.h>
64 #include <sys/socket.h>
69 #if defined(HAVE_SYS_USER_H)
72 #if defined(HAVE_SYS_UTSNAME_H)
73 #include <sys/utsname.h>
75 #if defined(HAVE_SYS_SELECT_H)
76 #include <sys/select.h>
81 #if defined(HAVE_LINUX_FILTER_H)
82 #include <linux/filter.h>
84 #if defined(HAVE_LINUX_NETLINK_H)
85 #include <linux/netlink.h>
87 #if defined(HAVE_LINUX_RTNETLINK_H)
88 #include <linux/rtnetlink.h>
90 #if defined(HAVE_NET_IF_H)
95 ${CC} -fdump-go-spec=gen-sysinfo.go
-std=gnu99
-S -o sysinfo.s sysinfo.c
97 echo 'package syscall' > ${OUT}
98 echo 'import "unsafe"' >> ${OUT}
99 echo 'type _ unsafe.Pointer' >> ${OUT}
101 # Get all the consts and types, skipping ones which could not be
102 # represented in Go and ones which we need to rewrite. We also skip
103 # function declarations, as we don't need them here. All the symbols
104 # will all have a leading underscore.
105 grep -v '^// ' gen-sysinfo.go | \
107 grep -v '^type _timeval ' | \
108 grep -v '^type _timespec_t ' | \
109 grep -v '^type _timespec ' | \
110 grep -v '^type _timestruc_t ' | \
111 grep -v '^type _epoll_' | \
112 grep -v 'in6_addr' | \
113 grep -v 'sockaddr_in6' | \
114 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
115 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
116 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
117 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
120 # The errno constants.
121 grep '^const _E' gen-sysinfo.go | \
122 sed -e 's/^\(const \)_\(E[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
125 egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
126 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
127 if ! grep '^const O_ASYNC' ${OUT} >/dev
/null
2>&1; then
128 echo "const O_ASYNC = 0" >> ${OUT}
130 if ! grep '^const O_CLOEXEC' ${OUT} >/dev
/null
2>&1; then
131 echo "const O_CLOEXEC = 0" >> ${OUT}
134 # The signal numbers.
135 grep '^const _SIG[^_]' gen-sysinfo.go | \
136 grep -v '^const _SIGEV_' | \
137 sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
139 # The syscall numbers. We force the names to upper case.
140 grep '^const _SYS_' gen-sysinfo.go | \
141 sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \
143 sup
=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
144 echo "const $sup = _$sys" >> ${OUT}
148 grep '^const _S_' gen-sysinfo.go | \
149 sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
152 grep '^const _PROT_' gen-sysinfo.go | \
153 sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
154 grep '^const _MAP_' gen-sysinfo.go | \
155 sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
157 # Process status constants.
158 grep '^const _W' gen-sysinfo.go |
159 sed -e 's/^\(const \)_\(W[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
160 # WSTOPPED was introduced in glibc 2.3.4.
161 if ! grep '^const _WSTOPPED = ' gen-sysinfo.go
>/dev
/null
2>&1; then
162 if grep '^const _WUNTRACED = ' gen-sysinfo.go
> /dev
/null
2>&1; then
163 echo 'const WSTOPPED = _WUNTRACED' >> ${OUT}
165 echo 'const WSTOPPED = 2' >> ${OUT}
168 if grep '^const ___WALL = ' gen-sysinfo.go
>/dev
/null
2>&1 \
169 && ! grep '^const _WALL = ' gen-sysinfo.go
>/dev
/null
2>&1; then
170 echo 'const WALL = ___WALL' >> ${OUT}
173 # Networking constants.
174 egrep '^const _(AF|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
175 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
176 grep '^const _SOMAXCONN' gen-sysinfo.go |
177 sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
179 grep '^const _SHUT_' gen-sysinfo.go |
180 sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
182 # The net package requires a definition for IPV6ONLY.
183 if ! grep '^const IPV6_V6ONLY ' ${OUT} >/dev
/null
2>&1; then
184 echo "const IPV6_V6ONLY = 0" >> ${OUT}
187 # pathconf constants.
188 grep '^const __PC' gen-sysinfo.go |
189 sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
191 # The epoll constants were picked up by the errno constants, but we
192 # need to be sure the EPOLLRDHUP is defined.
193 if ! grep '^const EPOLLRDHUP' ${OUT} >/dev
/null
2>&1; then
194 echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
197 # Ptrace constants. We don't expose all the PTRACE flags, just the
198 # PTRACE_O_xxx and PTRACE_EVENT_xxx ones.
199 grep '^const _PTRACE_O' gen-sysinfo.go |
200 sed -e 's/^\(const \)_\(PTRACE_O[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
201 grep '^const _PTRACE_EVENT' gen-sysinfo.go |
202 sed -e 's/^\(const \)_\(PTRACE_EVENT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
203 # We need PTRACE_SETOPTIONS and PTRACE_GETEVENTMSG, but they are not
204 # defined in older versions of glibc.
205 if ! grep '^const _PTRACE_SETOPTIONS' ${OUT} > /dev
/null
2>&1; then
206 echo "const _PTRACE_SETOPTIONS = 0x4200" >> ${OUT}
208 if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev
/null
2>&1; then
209 echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
211 if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev
/null
2>&1; then
212 echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
214 if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev
/null
2>&1; then
215 echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
217 if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev
/null
2>&1; then
218 echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
220 if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev
/null
2>&1; then
221 echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
223 if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev
/null
2>&1; then
224 echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
226 if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev
/null
2>&1; then
227 echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
229 if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev
/null
2>&1; then
230 echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
232 if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev
/null
2>&1; then
233 echo "const _PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
235 if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev
/null
2>&1; then
236 echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
238 if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev
/null
2>&1; then
239 echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
241 if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev
/null
2>&1; then
242 echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
244 if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev
/null
2>&1; then
245 echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
247 if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev
/null
2>&1; then
248 echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
250 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev
/null
2>&1; then
251 echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
253 if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev
/null
2>&1; then
254 echo "const _PTRACE_TRACEME = 0" >> ${OUT}
257 # The registers returned by PTRACE_GETREGS. This is probably
258 # GNU/Linux specific; it should do no harm if there is no
260 regs
=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
261 if test "$regs" != ""; then
262 regs
=`echo $regs | sed -e 's/type _user_regs_struct struct //' -e 's/[{}]//g'`
263 regs
=`echo $regs | sed -e s'/^ *//'`
265 while test -n "$regs"; do
266 field
=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
267 regs
=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
268 # Capitalize the first character of the field.
269 f
=`echo $field | sed -e 's/^\(.\).*$/\1/'`
270 r
=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
271 f
=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
273 nregs
="$nregs $field;"
275 echo "type PtraceRegs struct {$nregs }" >> ${OUT}
279 echo 'type Size_t _size_t' >> ${OUT}
280 echo "type Ssize_t _ssize_t" >> ${OUT}
281 if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go
> /dev
/null
2>&1; then
282 echo "type Offset_t _off64_t" >> ${OUT}
284 echo "type Offset_t _off_t" >> ${OUT}
286 echo "type Mode_t _mode_t" >> ${OUT}
287 echo "type Pid_t _pid_t" >> ${OUT}
288 echo "type Uid_t _uid_t" >> ${OUT}
289 echo "type Gid_t _gid_t" >> ${OUT}
290 echo "type Socklen_t _socklen_t" >> ${OUT}
292 # The long type, needed because that is the type that ptrace returns.
293 sizeof_long
=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
294 if test "$sizeof_long" = "4"; then
295 echo "type _C_long int32" >> ${OUT}
296 elif test "$sizeof_long" = "8"; then
297 echo "type _C_long int64" >> ${OUT}
299 echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
303 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
304 # double is commented by -fdump-go-spec.
305 if grep "^// type _pad128_t" gen-sysinfo.go
> /dev
/null
2>&1; then
306 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
308 if grep "^// type _upad128_t" gen-sysinfo.go
> /dev
/null
2>&1; then
309 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
312 # The time structures need special handling: we need to name the
313 # types, so that we can cast integers to the right types when
314 # assigning to the structures.
315 timeval
=`grep '^type _timeval ' gen-sysinfo.go`
316 timeval_sec
=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
317 timeval_usec
=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
318 echo "type Timeval_sec_t $timeval_sec" >> ${OUT}
319 echo "type Timeval_usec_t $timeval_usec" >> ${OUT}
321 sed -e 's/type _timeval /type Timeval /' \
322 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
323 -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
324 timespec
=`grep '^type _timespec ' gen-sysinfo.go || true`
325 if test "$timespec" = ""; then
326 # IRIX 6.5 has __timespec instead.
327 timespec
=`grep '^type ___timespec ' gen-sysinfo.go || true`
329 timespec_sec
=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
330 timespec_nsec
=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
331 echo "type Timespec_sec_t $timespec_sec" >> ${OUT}
332 echo "type Timespec_nsec_t $timespec_nsec" >> ${OUT}
334 sed -e 's/^type ___timespec /type Timespec /' \
335 -e 's/^type _timespec /type Timespec /' \
336 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
337 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
339 timestruc
=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
340 if test "$timestruc" != ""; then
341 timestruc_sec
=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
342 timestruc_nsec
=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
343 echo "type Timestruc_sec_t $timestruc_sec" >> ${OUT}
344 echo "type Timestruc_nsec_t $timestruc_nsec" >> ${OUT}
346 sed -e 's/^type _timestruc_t /type Timestruc /' \
347 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
348 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
352 # Prefer largefile variant if available.
353 stat
=`grep '^type _stat64 ' gen-sysinfo.go || true`
354 if test "$stat" != ""; then
355 grep '^type _stat64 ' gen-sysinfo.go
357 grep '^type _stat ' gen-sysinfo.go
358 fi |
sed -e 's/type _stat64/type Stat_t/' \
359 -e 's/type _stat/type Stat_t/' \
361 -e 's/st_ino/Ino/g' \
362 -e 's/st_nlink/Nlink/' \
363 -e 's/st_mode/Mode/' \
366 -e 's/st_rdev/Rdev/' \
367 -e 's/st_size/Size/' \
368 -e 's/st_blksize/Blksize/' \
369 -e 's/st_blocks/Blocks/' \
370 -e 's/st_atim/Atime/' \
371 -e 's/st_mtim/Mtime/' \
372 -e 's/st_ctim/Ctime/' \
373 -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
374 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
375 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
376 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
377 -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
380 # The directory searching types.
381 # Prefer largefile variant if available.
382 dirent
=`grep '^type _dirent64 ' gen-sysinfo.go || true`
383 if test "$dirent" != ""; then
384 grep '^type _dirent64 ' gen-sysinfo.go
386 grep '^type _dirent ' gen-sysinfo.go
387 fi |
sed -e 's/type _dirent64/type Dirent/' \
388 -e 's/type _dirent/type Dirent/' \
389 -e 's/d_name \[0+1\]/d_name [0+256]/' \
390 -e 's/d_name/Name/' \
391 -e 's/]int8/]byte/' \
394 -e 's/d_reclen/Reclen/' \
395 -e 's/d_type/Type/' \
397 echo "type DIR _DIR" >> ${OUT}
400 rusage
=`grep '^type _rusage struct' gen-sysinfo.go`
401 if test "$rusage" != ""; then
402 rusage
=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
403 rusage
=`echo $rusage | sed -e 's/^ *//'`
405 while test -n "$rusage"; do
406 field
=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
407 rusage
=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
408 # Drop the leading ru_, capitalize the next character.
409 field
=`echo $field | sed -e 's/^ru_//'`
410 f
=`echo $field | sed -e 's/^\(.\).*$/\1/'`
411 r
=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
412 f
=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
413 # Fix _timeval _timespec, and _timestruc_t.
414 r
=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
415 r
=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
416 r
=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
418 nrusage
="$nrusage $field;"
420 echo "type Rusage struct {$nrusage }" >> ${OUT}
422 echo "type Rusage struct {}" >> ${OUT}
425 # The RUSAGE constants.
426 grep '^const _RUSAGE_' gen-sysinfo.go | \
427 sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
429 # The utsname struct.
430 grep '^type _utsname ' gen-sysinfo.go | \
431 sed -e 's/_utsname/Utsname/' \
432 -e 's/sysname/Sysname/' \
433 -e 's/nodename/Nodename/' \
434 -e 's/release/Release/' \
435 -e 's/version/Version/' \
436 -e 's/machine/Machine/' \
437 -e 's/domainname/Domainname/' \
441 iovec
=`grep '^type _iovec ' gen-sysinfo.go`
442 iovec_len
=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
443 echo "type Iovec_len_t $iovec_len" >> ${OUT}
445 sed -e 's/_iovec/Iovec/' \
446 -e 's/iov_base/Base/' \
447 -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
451 msghdr
=`grep '^type _msghdr ' gen-sysinfo.go`
452 msghdr_controllen
=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
453 echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
455 sed -e 's/_msghdr/Msghdr/' \
456 -e 's/msg_name/Name/' \
457 -e 's/msg_namelen/Namelen/' \
458 -e 's/msg_iov/Iov/' \
459 -e 's/msg_iovlen/Iovlen/' \
460 -e 's/_iovec/Iovec/' \
461 -e 's/msg_control/Control/' \
462 -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
463 -e 's/msg_flags/Flags/' \
467 grep '^type _ip_mreq ' gen-sysinfo.go | \
468 sed -e 's/_ip_mreq/IPMreq/' \
469 -e 's/imr_multiaddr/Multiaddr/' \
470 -e 's/imr_interface/Interface/' \
471 -e 's/_in_addr/[4]byte/g' \
474 # Try to guess the type to use for fd_set.
475 fd_set
=`grep '^type _fd_set ' gen-sysinfo.go || true`
476 fds_bits_type
="_C_long"
477 if test "$fd_set" != ""; then
478 fds_bits_type
=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
480 echo "type fds_bits_type $fds_bits_type" >> ${OUT}
482 # The addrinfo struct.
483 grep '^type _addrinfo ' gen-sysinfo.go | \
484 sed -e 's/_addrinfo/Addrinfo/g' \
488 # The addrinfo flags.
489 grep '^const _AI_' gen-sysinfo.go | \
490 sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
493 grep '^type _passwd ' gen-sysinfo.go | \
494 sed -e 's/_passwd/Passwd/' \
498 # The ioctl flags for the controlling TTY.
499 grep '^const _TIOC' gen-sysinfo.go | \
500 sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
502 # The nlmsghdr struct.
503 grep '^type _nlmsghdr ' gen-sysinfo.go | \
504 sed -e 's/_nlmsghdr/NlMsghdr/' \
505 -e 's/nlmsg_len/Len/' \
506 -e 's/nlmsg_type/Type/' \
507 -e 's/nlmsg_flags/Flags/' \
508 -e 's/nlmsg_seq/Seq/' \
509 -e 's/nlmsg_pid/Pid/' \
512 # The nlmsg flags and operators.
513 grep '^const _NLM' gen-sysinfo.go | \
514 sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
516 # NLMSG_HDRLEN is defined as an expression using sizeof.
517 if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev
/null
2>&1; then
518 if grep '^type NlMsghdr ' ${OUT} > /dev
/null
2>&1; then
519 echo 'var NLMSG_HDRLEN = int((unsafe.Sizeof(NlMsghdr{}) + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1))' >> ${OUT}
523 # The rtgenmsg struct.
524 grep '^type _rtgenmsg ' gen-sysinfo.go | \
525 sed -e 's/_rtgenmsg/RtGenmsg/' \
526 -e 's/rtgen_family/Family/' \
529 # The routing message flags.
530 grep '^const _RTA' gen-sysinfo.go | \
531 sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
532 grep '^const _RTM' gen-sysinfo.go | \
533 sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
535 # The size of the rtgenmsg struct.
536 if grep 'type RtGenmsg ' ${OUT} > /dev
/null
2>&1; then
537 echo 'var SizeofRtGenmsg = int(unsafe.Sizeof(RtGenmsg{}))' >> ${OUT}
540 # The ifinfomsg struct.
541 grep '^type _ifinfomsg ' gen-sysinfo.go | \
542 sed -e 's/_ifinfomsg/IfInfomsg/' \
543 -e 's/ifi_family/Family/' \
544 -e 's/ifi_type/Type/' \
545 -e 's/ifi_index/Index/' \
546 -e 's/ifi_flags/Flags/' \
547 -e 's/ifi_change/Change/' \
550 # The interface information types and flags.
551 grep '^const _IFA' gen-sysinfo.go | \
552 sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
553 grep '^const _IFLA' gen-sysinfo.go | \
554 sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
555 grep '^const _IFF' gen-sysinfo.go | \
556 sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
558 # The size of the ifinfomsg struct.
559 if grep 'type IfInfomsg ' ${OUT} > /dev
/null
2>&1; then
560 echo 'var SizeofIfInfomsg = int(unsafe.Sizeof(IfInfomsg{}))' >> ${OUT}
563 # The ifaddrmsg struct.
564 grep '^type _ifaddrmsg ' gen-sysinfo.go | \
565 sed -e 's/_ifaddrmsg/IfAddrmsg/' \
566 -e 's/ifa_family/Family/' \
567 -e 's/ifa_prefixlen/Prefixlen/' \
568 -e 's/ifa_flags/Flags/' \
569 -e 's/ifa_scope/Scope/' \
570 -e 's/ifa_index/Index/' \
573 # The size of the ifaddrmsg struct.
574 if grep 'type IfAddrmsg ' ${OUT} > /dev
/null
2>&1; then
575 echo 'var SizeofIfAddrmsg = int(unsafe.Sizeof(IfAddrmsg{}))' >> ${OUT}
579 grep '^type _rtattr ' gen-sysinfo.go | \
580 sed -e 's/_rtattr/RtAttr/' \
581 -e 's/rta_len/Len/' \
582 -e 's/rta_type/Type/' \
585 # The size of the rtattr struct.
586 if grep 'type RtAttr ' ${OUT} > /dev
/null
2>&1; then
587 echo 'var SizeofRtAttr = int(unsafe.Sizeof(RtAttr{}))' >> ${OUT}