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