move extra headers
[nestedvm.git] / upstream / misc / extraheaders.sh
1 #!/bin/sh -e
2
3 mkdir -p arpa netinet sys nestedvm
4
5 for f in arpa/inet.h netdb.h netinet/in.h sys/socket.h; do
6     test -e $f || echo "#include <nestedvm/socket.h>" > $f
7 done
8
9 for f in getopt.h; do
10     test -e $f || echo "#include <unistd.h>" > $f
11 done
12
13 cat <<__EOF__ > sys/ioctl.h
14
15 __EOF__
16
17 cat <<__EOF__ > sys/klog.h
18 #ifndef __SYS_KLOG_H
19 #define __SYS_KLOG_H
20
21 int klogctl(int cmd, char *buf, int buflen);
22
23 #endif
24 __EOF__
25
26 cat <<__EOF__ > sys/utsname.h
27 #ifndef __SYS_UTSNAME_H
28 #define __SYS_UTSNAME_H
29
30 #define SYS_NMLN 32
31
32 struct utsname {
33     char sysname[SYS_NMLN];
34     char nodename[SYS_NMLN];
35     char release[SYS_NMLN];
36     char version[SYS_NMLN];
37     char machine[SYS_NMLN];
38 };
39
40 int uname(struct utsname *);
41
42 #endif
43 __EOF__
44
45 cat <<__EOF__ > sys/sysctl.h
46 /*
47  * Copyright (c) 1989, 1993
48  *      The Regents of the University of California.  All rights reserved.
49  *
50  * This code is derived from software contributed to Berkeley by
51  * Mike Karels at Berkeley Software Design, Inc.
52  *
53  * Redistribution and use in source and binary forms, with or without
54  * modification, are permitted provided that the following conditions
55  * are met:
56  * 1. Redistributions of source code must retain the above copyright
57  *    notice, this list of conditions and the following disclaimer.
58  * 2. Redistributions in binary form must reproduce the above copyright
59  *    notice, this list of conditions and the following disclaimer in the
60  *    documentation and/or other materials provided with the distribution.
61  * 3. All advertising materials mentioning features or use of this software
62  *    must display the following acknowledgement:
63  *      This product includes software developed by the University of
64  *      California, Berkeley and its contributors.
65  * 4. Neither the name of the University nor the names of its contributors
66  *    may be used to endorse or promote products derived from this software
67  *    without specific prior written permission.
68  *
69  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
70  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
71  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
72  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
73  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
74  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
75             * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
76  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
77  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
78  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
79  * SUCH DAMAGE.
80  *
81  *      @(#)sysctl.h    8.1 (Berkeley) 6/2/93
82  * $FreeBSD: src/sys/sys/sysctl.h,v 1.81.2.10 2003/05/01 22:48:09 trhodes Exp $
83  */
84
85 #ifndef __SYS_SYSCTL_H
86 #define __SYS_SYSCTL_H
87
88 #define CTL_MAXNAME     12
89
90
91 /*
92  * Top-level identifiers
93  */
94 #define CTL_UNSPEC      0               /* unused */
95 #define CTL_KERN        1               /* "high kernel": proc, limits */
96 #define CTL_VM          2               /* virtual memory */
97 #define CTL_VFS         3               /* file system, mount type is next */
98 #define CTL_NET         4               /* network, see socket.h */
99 #define CTL_DEBUG       5               /* debugging parameters */
100 #define CTL_HW          6               /* generic cpu/io */
101 #define CTL_MACHDEP     7               /* machine dependent */
102 #define CTL_USER        8               /* user-level */
103 #define CTL_P1003_1B    9               /* POSIX 1003.1B */
104 #define CTL_MAXID       10              /* number of valid top-level ids */
105
106 #define CTL_NAMES { \
107         { 0, 0 }, \
108 { "kern", CTLTYPE_NODE }, \
109 { "vm", CTLTYPE_NODE }, \
110 { "vfs", CTLTYPE_NODE }, \
111 { "net", CTLTYPE_NODE }, \
112 { "debug", CTLTYPE_NODE }, \
113 { "hw", CTLTYPE_NODE }, \
114 { "machdep", CTLTYPE_NODE }, \
115 { "user", CTLTYPE_NODE }, \
116 { "p1003_1b", CTLTYPE_NODE }, \
117 }
118
119 /*
120  * CTL_KERN identifiers
121  */
122 #define KERN_OSTYPE              1      /* string: system version */
123 #define KERN_OSRELEASE           2      /* string: system release */
124 #define KERN_OSREV               3      /* int: system revision */
125 #define KERN_VERSION             4      /* string: compile time info */
126 #define KERN_MAXVNODES           5      /* int: max vnodes */
127 #define KERN_MAXPROC             6      /* int: max processes */
128 #define KERN_MAXFILES            7      /* int: max open files */
129 #define KERN_ARGMAX              8      /* int: max arguments to exec */
130 #define KERN_SECURELVL           9      /* int: system security level */
131 #define KERN_HOSTNAME           10      /* string: hostname */
132 #define KERN_HOSTID             11      /* int: host identifier */
133 #define KERN_CLOCKRATE          12      /* struct: struct clockrate */
134 #define KERN_VNODE              13      /* struct: vnode structures */
135 #define KERN_PROC               14      /* struct: process entries */
136 #define KERN_FILE               15      /* struct: file entries */
137 #define KERN_PROF               16      /* node: kernel profiling info */
138 #define KERN_POSIX1             17      /* int: POSIX.1 version */
139 #define KERN_NGROUPS            18      /* int: # of supplemental group ids */
140 #define KERN_JOB_CONTROL        19      /* int: is job control available */
141 #define KERN_SAVED_IDS          20      /* int: saved set-user/group-ID */
142 #define KERN_BOOTTIME           21      /* struct: time kernel was booted */
143 #define KERN_NISDOMAINNAME      22      /* string: YP domain name */
144 #define KERN_UPDATEINTERVAL     23      /* int: update process sleep time */
145 #define KERN_OSRELDATE          24      /* int: OS release date */
146 #define KERN_NTP_PLL            25      /* node: NTP PLL control */
147 #define KERN_BOOTFILE           26      /* string: name of booted kernel */
148 #define KERN_MAXFILESPERPROC    27      /* int: max open files per proc */
149 #define KERN_MAXPROCPERUID      28      /* int: max processes per uid */
150 #define KERN_DUMPDEV            29      /* dev_t: device to dump on */
151 #define KERN_IPC                30      /* node: anything related to IPC */
152 #define KERN_DUMMY              31      /* unused */
153 #define KERN_PS_STRINGS         32      /* int: address of PS_STRINGS */
154 #define KERN_USRSTACK           33      /* int: address of USRSTACK */
155 #define KERN_LOGSIGEXIT         34      /* int: do we log sigexit procs? */
156 #define KERN_MAXID              35      /* number of valid kern ids */
157
158 #define CTL_KERN_NAMES { \
159         { 0, 0 }, \
160         { "ostype", CTLTYPE_STRING }, \
161         { "osrelease", CTLTYPE_STRING }, \
162         { "osrevision", CTLTYPE_INT }, \
163         { "version", CTLTYPE_STRING }, \
164         { "maxvnodes", CTLTYPE_INT }, \
165         { "maxproc", CTLTYPE_INT }, \
166         { "maxfiles", CTLTYPE_INT }, \
167         { "argmax", CTLTYPE_INT }, \
168         { "securelevel", CTLTYPE_INT }, \
169         { "hostname", CTLTYPE_STRING }, \
170         { "hostid", CTLTYPE_UINT }, \
171         { "clockrate", CTLTYPE_STRUCT }, \
172         { "vnode", CTLTYPE_STRUCT }, \
173         { "proc", CTLTYPE_STRUCT }, \
174         { "file", CTLTYPE_STRUCT }, \
175         { "profiling", CTLTYPE_NODE }, \
176         { "posix1version", CTLTYPE_INT }, \
177         { "ngroups", CTLTYPE_INT }, \
178         { "job_control", CTLTYPE_INT }, \
179         { "saved_ids", CTLTYPE_INT }, \
180         { "boottime", CTLTYPE_STRUCT }, \
181         { "nisdomainname", CTLTYPE_STRING }, \
182         { "update", CTLTYPE_INT }, \
183         { "osreldate", CTLTYPE_INT }, \
184         { "ntp_pll", CTLTYPE_NODE }, \
185         { "bootfile", CTLTYPE_STRING }, \
186         { "maxfilesperproc", CTLTYPE_INT }, \
187         { "maxprocperuid", CTLTYPE_INT }, \
188         { "dumpdev", CTLTYPE_STRUCT }, /* we lie; don't print as int */ \
189         { "ipc", CTLTYPE_NODE }, \
190         { "dummy", CTLTYPE_INT }, \
191         { "ps_strings", CTLTYPE_INT }, \
192         { "usrstack", CTLTYPE_INT }, \
193         { "logsigexit", CTLTYPE_INT }, \
194 }
195
196 /*
197  * CTL_VFS identifiers
198  */
199 #define CTL_VFS_NAMES { \
200         { "vfsconf", CTLTYPE_STRUCT }, \
201 }
202
203 /*
204  * KERN_PROC subtypes
205  */
206 #define KERN_PROC_ALL           0       /* everything */
207 #define KERN_PROC_PID           1       /* by process id */
208 #define KERN_PROC_PGRP          2       /* by process group id */
209 #define KERN_PROC_SESSION       3       /* by session of pid */
210 #define KERN_PROC_TTY           4       /* by controlling tty */
211 #define KERN_PROC_UID           5       /* by effective uid */
212 #define KERN_PROC_RUID          6       /* by real uid */
213 #define KERN_PROC_ARGS          7       /* get/set arguments/proctitle */
214
215 /*
216  * KERN_IPC identifiers
217  */
218 #define KIPC_MAXSOCKBUF         1       /* int: max size of a socket buffer */
219 #define KIPC_SOCKBUF_WASTE      2       /* int: wastage factor in sockbuf */
220 #define KIPC_SOMAXCONN          3       /* int: max length of connection q */
221 #define KIPC_MAX_LINKHDR        4       /* int: max length of link header */
222 #define KIPC_MAX_PROTOHDR       5       /* int: max length of network header */
223 #define KIPC_MAX_HDR            6       /* int: max total length of headers */
224 #define KIPC_MAX_DATALEN        7       /* int: max length of data? */
225 #define KIPC_MBSTAT             8       /* struct: mbuf usage statistics */
226 #define KIPC_NMBCLUSTERS        9       /* int: maximum mbuf clusters */
227
228 /*
229  * CTL_HW identifiers
230  */
231 #define HW_MACHINE       1              /* string: machine class */
232 #define HW_MODEL         2              /* string: specific machine model */
233 #define HW_NCPU          3              /* int: number of cpus */
234 #define HW_BYTEORDER     4              /* int: machine byte order */
235 #define HW_PHYSMEM       5              /* int: total memory */
236 #define HW_USERMEM       6              /* int: non-kernel memory */
237 #define HW_PAGESIZE      7              /* int: software page size */
238 #define HW_DISKNAMES     8              /* strings: disk drive names */
239 #define HW_DISKSTATS     9              /* struct: diskstats[] */
240 #define HW_FLOATINGPT   10              /* int: has HW floating point? */
241 #define HW_MACHINE_ARCH 11              /* string: machine architecture */
242 #define HW_MAXID        12              /* number of valid hw ids */
243
244 #define CTL_HW_NAMES { \
245         { 0, 0 }, \
246         { "machine", CTLTYPE_STRING }, \
247         { "model", CTLTYPE_STRING }, \
248         { "ncpu", CTLTYPE_INT }, \
249         { "byteorder", CTLTYPE_INT }, \
250         { "physmem", CTLTYPE_UINT }, \
251         { "usermem", CTLTYPE_UINT }, \
252         { "pagesize", CTLTYPE_INT }, \
253         { "disknames", CTLTYPE_STRUCT }, \
254         { "diskstats", CTLTYPE_STRUCT }, \
255         { "floatingpoint", CTLTYPE_INT }, \
256 }
257
258 /*
259  * CTL_USER definitions
260  */
261 #define USER_CS_PATH             1      /* string: _CS_PATH */
262 #define USER_BC_BASE_MAX         2      /* int: BC_BASE_MAX */
263 #define USER_BC_DIM_MAX          3      /* int: BC_DIM_MAX */
264 #define USER_BC_SCALE_MAX        4      /* int: BC_SCALE_MAX */
265 #define USER_BC_STRING_MAX       5      /* int: BC_STRING_MAX */
266 #define USER_COLL_WEIGHTS_MAX    6      /* int: COLL_WEIGHTS_MAX */
267 #define USER_EXPR_NEST_MAX       7      /* int: EXPR_NEST_MAX */
268 #define USER_LINE_MAX            8      /* int: LINE_MAX */
269 #define USER_RE_DUP_MAX          9      /* int: RE_DUP_MAX */
270 #define USER_POSIX2_VERSION     10      /* int: POSIX2_VERSION */
271 #define USER_POSIX2_C_BIND      11      /* int: POSIX2_C_BIND */
272 #define USER_POSIX2_C_DEV       12      /* int: POSIX2_C_DEV */
273 #define USER_POSIX2_CHAR_TERM   13      /* int: POSIX2_CHAR_TERM */
274 #define USER_POSIX2_FORT_DEV    14      /* int: POSIX2_FORT_DEV */
275 #define USER_POSIX2_FORT_RUN    15      /* int: POSIX2_FORT_RUN */
276 #define USER_POSIX2_LOCALEDEF   16      /* int: POSIX2_LOCALEDEF */
277 #define USER_POSIX2_SW_DEV      17      /* int: POSIX2_SW_DEV */
278 #define USER_POSIX2_UPE         18      /* int: POSIX2_UPE */
279 #define USER_STREAM_MAX         19      /* int: POSIX2_STREAM_MAX */
280 #define USER_TZNAME_MAX         20      /* int: POSIX2_TZNAME_MAX */
281 #define USER_MAXID              21      /* number of valid user ids */
282
283 #define CTL_USER_NAMES { \
284         { 0, 0 }, \
285         { "cs_path", CTLTYPE_STRING }, \
286         { "bc_base_max", CTLTYPE_INT }, \
287         { "bc_dim_max", CTLTYPE_INT }, \
288         { "bc_scale_max", CTLTYPE_INT }, \
289         { "bc_string_max", CTLTYPE_INT }, \
290         { "coll_weights_max", CTLTYPE_INT }, \
291         { "expr_nest_max", CTLTYPE_INT }, \
292         { "line_max", CTLTYPE_INT }, \
293         { "re_dup_max", CTLTYPE_INT }, \
294         { "posix2_version", CTLTYPE_INT }, \
295         { "posix2_c_bind", CTLTYPE_INT }, \
296         { "posix2_c_dev", CTLTYPE_INT }, \
297         { "posix2_char_term", CTLTYPE_INT }, \
298         { "posix2_fort_dev", CTLTYPE_INT }, \
299         { "posix2_fort_run", CTLTYPE_INT }, \
300         { "posix2_localedef", CTLTYPE_INT }, \
301         { "posix2_sw_dev", CTLTYPE_INT }, \
302         { "posix2_upe", CTLTYPE_INT }, \
303         { "stream_max", CTLTYPE_INT }, \
304         { "tzname_max", CTLTYPE_INT }, \
305 }
306
307 #define CTL_P1003_1B_ASYNCHRONOUS_IO            1       /* boolean */
308 #define CTL_P1003_1B_MAPPED_FILES               2       /* boolean */
309 #define CTL_P1003_1B_MEMLOCK                    3       /* boolean */
310 #define CTL_P1003_1B_MEMLOCK_RANGE              4       /* boolean */
311 #define CTL_P1003_1B_MEMORY_PROTECTION          5       /* boolean */
312 #define CTL_P1003_1B_MESSAGE_PASSING            6       /* boolean */
313 #define CTL_P1003_1B_PRIORITIZED_IO             7       /* boolean */
314 #define CTL_P1003_1B_PRIORITY_SCHEDULING        8       /* boolean */
315 #define CTL_P1003_1B_REALTIME_SIGNALS           9       /* boolean */
316 #define CTL_P1003_1B_SEMAPHORES                 10      /* boolean */
317 #define CTL_P1003_1B_FSYNC                      11      /* boolean */
318 #define CTL_P1003_1B_SHARED_MEMORY_OBJECTS      12      /* boolean */
319 #define CTL_P1003_1B_SYNCHRONIZED_IO            13      /* boolean */
320 #define CTL_P1003_1B_TIMERS                     14      /* boolean */
321 #define CTL_P1003_1B_AIO_LISTIO_MAX             15      /* int */
322 #define CTL_P1003_1B_AIO_MAX                    16      /* int */
323 #define CTL_P1003_1B_AIO_PRIO_DELTA_MAX         17      /* int */
324 #define CTL_P1003_1B_DELAYTIMER_MAX             18      /* int */
325 #define CTL_P1003_1B_MQ_OPEN_MAX                19      /* int */
326 #define CTL_P1003_1B_PAGESIZE                   20      /* int */
327 #define CTL_P1003_1B_RTSIG_MAX                  21      /* int */
328 #define CTL_P1003_1B_SEM_NSEMS_MAX              22      /* int */
329 #define CTL_P1003_1B_SEM_VALUE_MAX              23      /* int */
330 #define CTL_P1003_1B_SIGQUEUE_MAX               24      /* int */
331 #define CTL_P1003_1B_TIMER_MAX                  25      /* int */
332
333 #define CTL_P1003_1B_MAXID              26
334
335 #define CTL_P1003_1B_NAMES { \
336         { 0, 0 }, \
337         { "asynchronous_io", CTLTYPE_INT }, \
338         { "mapped_files", CTLTYPE_INT }, \
339         { "memlock", CTLTYPE_INT }, \
340         { "memlock_range", CTLTYPE_INT }, \
341         { "memory_protection", CTLTYPE_INT }, \
342         { "message_passing", CTLTYPE_INT }, \
343         { "prioritized_io", CTLTYPE_INT }, \
344         { "priority_scheduling", CTLTYPE_INT }, \
345         { "realtime_signals", CTLTYPE_INT }, \
346         { "semaphores", CTLTYPE_INT }, \
347         { "fsync", CTLTYPE_INT }, \
348         { "shared_memory_objects", CTLTYPE_INT }, \
349         { "synchronized_io", CTLTYPE_INT }, \
350         { "timers", CTLTYPE_INT }, \
351         { "aio_listio_max", CTLTYPE_INT }, \
352         { "aio_max", CTLTYPE_INT }, \
353         { "aio_prio_delta_max", CTLTYPE_INT }, \
354         { "delaytimer_max", CTLTYPE_INT }, \
355         { "mq_open_max", CTLTYPE_INT }, \
356         { "pagesize", CTLTYPE_INT }, \
357         { "rtsig_max", CTLTYPE_INT }, \
358         { "nsems_max", CTLTYPE_INT }, \
359         { "sem_value_max", CTLTYPE_INT }, \
360         { "sigqueue_max", CTLTYPE_INT }, \
361         { "timer_max", CTLTYPE_INT }, \
362 }
363
364 #endif
365 __EOF__
366
367 cat <<__EOF__ > nestedvm/socket.h
368 #ifndef __NESTEDVM_SOCKETS_H
369 #define __NESTEDVM_SOCKETS_H
370
371 #include <sys/types.h>
372
373 static unsigned short htons(int x) { return x; }
374 static unsigned long htonl(int x) { return x; }
375 static unsigned short ntohs(int x) { return x; }
376 static unsigned long ntohl(int x) { return x; }
377
378 #define AF_INET 2
379 #define PF_INET AF_INET
380
381 #define SOCK_STREAM 1
382 #define SOCK_DGRAM 2
383
384 #define HOST_NOT_FOUND  1
385 #define TRY_AGAIN       2
386 #define NO_RECOVERY     3
387 #define NO_DATA         4
388
389 #define SOL_SOCKET 0xffff
390
391 #define SO_REUSEADDR 0x0004
392 #define SO_KEEPALIVE 0x0008 
393
394 #define SHUT_RD 0
395 #define SHUT_WR 1
396 #define SHUT_RDWR 2
397
398 #define INADDR_ANY 0
399
400 typedef unsigned long in_addr_t;
401 typedef int socklen_t;
402
403 struct in_addr {
404         in_addr_t s_addr;
405 };
406
407 struct sockaddr {
408     u_char sa_len;
409     u_char sa_family;
410     char sa_data[6];
411 };
412
413 struct sockaddr_in {
414         u_char  sin_len;
415         u_char  sin_family;
416         u_short sin_port;
417         struct  in_addr sin_addr;
418 };
419
420 struct  servent {
421     char    *s_name;        /* official name of service */
422     char    **s_aliases;    /* alias list */
423     int     s_port;         /* port service resides at */
424     char    *s_proto;       /* protocol to use */
425 };
426
427 struct servent *getservbyname(const char *name, const char *proto);
428
429 struct  hostent {
430     char    *h_name;        /* official name of host */
431     char    **h_aliases;    /* alias list */
432     int     h_addrtype;     /* host address type */
433     int     h_length;       /* length of address */
434     char    **h_addr_list;  /* list of addresses from name server */
435 };
436 #define h_addr  h_addr_list[0]  /* address, for backward compatibility */
437
438 struct hostent *gethostbyname(const char *name);
439
440 int socket(int domain, int type, int proto);
441 int bind(int s, const struct sockaddr *addr, socklen_t addrlen);
442 int listen(int s, int backlog);
443 int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
444 int shutdown(int s, int how);
445 int connect(int s, const struct sockaddr *name, socklen_t namelen);
446 char *inet_ntoa(struct in_addr in);
447
448 int getsockopt(int s, int level, int name, void *val, socklen_t *len);
449 int setsockopt(int s, int level, int name, const void *val, socklen_t len);
450
451 extern int h_errno;
452
453 void herror(const char *);
454
455 #endif
456 __EOF__