source: ada-examples/gen-soconn/gen-soccon.c @ db9a1d1

ada-examples-4-10-branchada-examples-4-9-branch
Last change on this file since db9a1d1 was fd0047e, checked in by Joel Sherrill <joel.sherrill@…>, on 09/27/07 at 14:40:53

2007-09-27 Joel Sherrill <joel.sherrill@…>

  • ChangeLog?, Makefile, README, gen-soccon.c, gsocket.h, init.c: New files.
  • Property mode set to 100644
File size: 15.6 KB
Line 
1/****************************************************************************
2 *                                                                          *
3 *                          GNAT SYSTEM UTILITIES                           *
4 *                                                                          *
5 *                           G E N - S O C C O N                            *
6 *                                                                          *
7 *          Copyright (C) 2004-2005, Free Software Foundation, Inc.         *
8 *                                                                          *
9 * GNAT is free software;  you can  redistribute it  and/or modify it under *
10 * terms of the  GNU General Public License as published  by the Free Soft- *
11 * ware  Foundation;  either version 2,  or (at your option) any later ver- *
12 * sion.  GNAT is distributed in the hope that it will be useful, but WITH- *
13 * OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY *
14 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License *
15 * for  more details.  You should have  received  a copy of the GNU General *
16 * Public License  distributed with GNAT;  see file COPYING.  If not, write *
17 * to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, *
18 * Boston, MA 02110-1301, USA.                                              *
19 *                                                                          *
20 * GNAT was originally developed  by the GNAT team at  New York University. *
21 * Extensive contributions were provided by Ada Core Technologies Inc.      *
22 *                                                                          *
23 ****************************************************************************/
24
25/* This program generates g-soccon.ads */
26
27/* To build using DEC C:
28  CC/DEFINE="TARGET=""OpenVMS""" gen-soccon
29  LINK gen-soccon
30  RUN gen-soccon
31*/
32
33#ifndef TARGET
34# error Please define TARGET
35#endif
36
37#include <stdlib.h>
38#include <stdio.h>
39#include <string.h>
40#include <limits.h>
41
42#ifdef __MINGW32__
43#include <fcntl.h>
44#endif
45
46#include "gsocket.h"
47
48struct line {
49  char *text;
50  char *value;
51  char *comment;
52  struct line *next;
53};
54
55struct line *first = NULL, *last = NULL;
56
57#define TXT(_text) add_line(_text, NULL, NULL);
58/* Plain text */
59
60#define _NL TXT("")
61/* Empty line */
62
63#define itoad(n) f_itoa ("%d", (n))
64#define itoax(n) f_itoa ("16#%08x#", (n))
65
66#define CND(name,comment) add_line(#name, itoad (name), comment);
67/* Constant (decimal) */
68
69#define CNX(name,comment) add_line(#name, itoax (name), comment);
70/* Constant (hexadecimal) */
71
72#define CN_(name,comment) add_line(#name, name, comment);
73/* Constant (generic) */
74
75#define STR(p) STR1(p)
76#define STR1(p) #p
77
78void output (void);
79/* Generate output spec */
80
81char *f_itoa (char *, int);
82/* int to string */
83
84void add_line (char *, char*, char*);
85
86#ifdef __MINGW32__
87unsigned int _CRT_fmode = _O_BINARY;
88#endif
89
90int
91main (void) {
92
93TXT("------------------------------------------------------------------------------")
94TXT("--                                                                          --")
95TXT("--                         GNAT COMPILER COMPONENTS                         --")
96TXT("--                                                                          --")
97TXT("--               G N A T . S O C K E T S . C O N S T A N T S                --")
98TXT("--                                                                          --")
99TXT("--                                 S p e c                                  --")
100TXT("--                                                                          --")
101TXT("--          Copyright (C) 2000-2005, Free Software Foundation, Inc.         --")
102TXT("--                                                                          --")
103TXT("-- GNAT is free software;  you can  redistribute it  and/or modify it under --")
104TXT("-- terms of the  GNU General Public License as published  by the Free Soft- --")
105TXT("-- ware  Foundation;  either version 2,  or (at your option) any later ver- --")
106TXT("-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --")
107TXT("-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --")
108TXT("-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --")
109TXT("-- for  more details.  You should have  received  a copy of the GNU General --")
110TXT("-- Public License  distributed with GNAT;  see file COPYING.  If not, write --")
111TXT("-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --")
112TXT("-- Boston, MA 02110-1301, USA.                                              --")
113TXT("--                                                                          --")
114TXT("-- As a special exception,  if other files  instantiate  generics from this --")
115TXT("-- unit, or you link  this unit with other files  to produce an executable, --")
116TXT("-- this  unit  does not  by itself cause  the resulting  executable  to  be --")
117TXT("-- covered  by the  GNU  General  Public  License.  This exception does not --")
118TXT("-- however invalidate  any other reasons why  the executable file  might be --")
119TXT("-- covered by the  GNU Public License.                                      --")
120TXT("--                                                                          --")
121TXT("-- GNAT was originally developed  by the GNAT team at  New York University. --")
122TXT("-- Extensive contributions were provided by Ada Core Technologies Inc.      --")
123TXT("--                                                                          --")
124TXT("------------------------------------------------------------------------------")
125_NL
126TXT("--  This package provides target dependent definitions of constant for use")
127TXT("--  by the GNAT.Sockets package (g-socket.ads). This package should not be")
128TXT("--  directly with'ed by an applications program.")
129_NL
130TXT("--  This is the version for " TARGET)
131TXT("--  This file is generated automatically, do not modify it by hand! Instead,")
132TXT("--  make changes to gen-soccon.c and re-run it on each target.")
133_NL
134TXT("package GNAT.Sockets.Constants is")
135_NL
136TXT("   --------------")
137TXT("   -- Families --")
138TXT("   --------------")
139_NL
140
141#ifndef AF_INET
142#define AF_INET -1
143#endif
144CND(AF_INET, "IPv4 address family")
145
146#ifndef AF_INET6
147#define AF_INET6 -1
148#endif
149CND(AF_INET6, "IPv6 address family")
150_NL
151TXT("   -----------")
152TXT("   -- Modes --")
153TXT("   -----------")
154_NL
155
156#ifndef SOCK_STREAM
157#define SOCK_STREAM -1
158#endif
159CND(SOCK_STREAM, "Stream socket")
160
161#ifndef SOCK_DGRAM
162#define SOCK_DGRAM -1
163#endif
164CND(SOCK_DGRAM, "Datagram socket")
165_NL
166TXT("   -------------------")
167TXT("   -- Socket errors --")
168TXT("   -------------------")
169_NL
170
171#ifndef EACCES
172#define EACCES -1
173#endif
174CND(EACCES, "Permission denied")
175
176#ifndef EADDRINUSE
177#define EADDRINUSE -1
178#endif
179CND(EADDRINUSE, "Address already in use")
180
181#ifndef EADDRNOTAVAIL
182#define EADDRNOTAVAIL -1
183#endif
184CND(EADDRNOTAVAIL, "Cannot assign address")
185
186#ifndef EAFNOSUPPORT
187#define EAFNOSUPPORT -1
188#endif
189CND(EAFNOSUPPORT, "Addr family not supported")
190
191#ifndef EALREADY
192#define EALREADY -1
193#endif
194CND(EALREADY, "Operation in progress")
195
196#ifndef EBADF
197#define EBADF -1
198#endif
199CND(EBADF, "Bad file descriptor")
200
201#ifndef ECONNABORTED
202#define ECONNABORTED -1
203#endif
204CND(ECONNABORTED, "Connection aborted")
205
206#ifndef ECONNREFUSED
207#define ECONNREFUSED -1
208#endif
209CND(ECONNREFUSED, "Connection refused")
210
211#ifndef ECONNRESET
212#define ECONNRESET -1
213#endif
214CND(ECONNRESET, "Connection reset by peer")
215
216#ifndef EDESTADDRREQ
217#define EDESTADDRREQ -1
218#endif
219CND(EDESTADDRREQ, "Destination addr required")
220
221#ifndef EFAULT
222#define EFAULT -1
223#endif
224CND(EFAULT, "Bad address")
225
226#ifndef EHOSTDOWN
227#define EHOSTDOWN -1
228#endif
229CND(EHOSTDOWN, "Host is down")
230
231#ifndef EHOSTUNREACH
232#define EHOSTUNREACH -1
233#endif
234CND(EHOSTUNREACH, "No route to host")
235
236#ifndef EINPROGRESS
237#define EINPROGRESS -1
238#endif
239CND(EINPROGRESS, "Operation now in progress")
240
241#ifndef EINTR
242#define EINTR -1
243#endif
244CND(EINTR, "Interrupted system call")
245
246#ifndef EINVAL
247#define EINVAL -1
248#endif
249CND(EINVAL, "Invalid argument")
250
251#ifndef EIO
252#define EIO -1
253#endif
254CND(EIO, "Input output error")
255
256#ifndef EISCONN
257#define EISCONN -1
258#endif
259CND(EISCONN, "Socket already connected")
260
261#ifndef ELOOP
262#define ELOOP -1
263#endif
264CND(ELOOP, "Too many symbolic lynks")
265
266#ifndef EMFILE
267#define EMFILE -1
268#endif
269CND(EMFILE, "Too many open files")
270
271#ifndef EMSGSIZE
272#define EMSGSIZE -1
273#endif
274CND(EMSGSIZE, "Message too long")
275
276#ifndef ENAMETOOLONG
277#define ENAMETOOLONG -1
278#endif
279CND(ENAMETOOLONG, "Name too long")
280
281#ifndef ENETDOWN
282#define ENETDOWN -1
283#endif
284CND(ENETDOWN, "Network is down")
285
286#ifndef ENETRESET
287#define ENETRESET -1
288#endif
289CND(ENETRESET, "Disconn. on network reset")
290
291#ifndef ENETUNREACH
292#define ENETUNREACH -1
293#endif
294CND(ENETUNREACH, "Network is unreachable")
295
296#ifndef ENOBUFS
297#define ENOBUFS -1
298#endif
299CND(ENOBUFS, "No buffer space available")
300
301#ifndef ENOPROTOOPT
302#define ENOPROTOOPT -1
303#endif
304CND(ENOPROTOOPT, "Protocol not available")
305
306#ifndef ENOTCONN
307#define ENOTCONN -1
308#endif
309CND(ENOTCONN, "Socket not connected")
310
311#ifndef ENOTSOCK
312#define ENOTSOCK -1
313#endif
314CND(ENOTSOCK, "Operation on non socket")
315
316#ifndef EOPNOTSUPP
317#define EOPNOTSUPP -1
318#endif
319CND(EOPNOTSUPP, "Operation not supported")
320
321#ifndef EPFNOSUPPORT
322#define EPFNOSUPPORT -1
323#endif
324CND(EPFNOSUPPORT, "Unknown protocol family")
325
326#ifndef EPROTONOSUPPORT
327#define EPROTONOSUPPORT -1
328#endif
329CND(EPROTONOSUPPORT, "Unknown protocol")
330
331#ifndef EPROTOTYPE
332#define EPROTOTYPE -1
333#endif
334CND(EPROTOTYPE, "Unknown protocol type")
335
336#ifndef ESHUTDOWN
337#define ESHUTDOWN -1
338#endif
339CND(ESHUTDOWN, "Cannot send once shutdown")
340
341#ifndef ESOCKTNOSUPPORT
342#define ESOCKTNOSUPPORT -1
343#endif
344CND(ESOCKTNOSUPPORT, "Socket type not supported")
345
346#ifndef ETIMEDOUT
347#define ETIMEDOUT -1
348#endif
349CND(ETIMEDOUT, "Connection timed out")
350
351#ifndef ETOOMANYREFS
352#define ETOOMANYREFS -1
353#endif
354CND(ETOOMANYREFS, "Too many references")
355
356#ifndef EWOULDBLOCK
357#define EWOULDBLOCK -1
358#endif
359CND(EWOULDBLOCK, "Operation would block")
360_NL
361TXT("   -----------------")
362TXT("   -- Host errors --")
363TXT("   -----------------")
364_NL
365
366#ifndef HOST_NOT_FOUND
367#define HOST_NOT_FOUND -1
368#endif
369CND(HOST_NOT_FOUND, "Unknown host")
370
371#ifndef TRY_AGAIN
372#define TRY_AGAIN -1
373#endif
374CND(TRY_AGAIN, "Host name lookup failure")
375
376#ifndef NO_DATA
377#define NO_DATA -1
378#endif
379CND(NO_DATA, "No data record for name")
380
381#ifndef NO_RECOVERY
382#define NO_RECOVERY -1
383#endif
384CND(NO_RECOVERY, "Non recoverable errors")
385_NL
386TXT("   -------------------")
387TXT("   -- Control flags --")
388TXT("   -------------------")
389_NL
390
391#ifndef FIONBIO
392#define FIONBIO -1
393#endif
394CND(FIONBIO, "Set/clear non-blocking io")
395
396#ifndef FIONREAD
397#define FIONREAD -1
398#endif
399CND(FIONREAD, "How many bytes to read")
400_NL
401TXT("   --------------------")
402TXT("   -- Shutdown modes --")
403TXT("   --------------------")
404_NL
405
406#ifndef SHUT_RD
407#define SHUT_RD -1
408#endif
409CND(SHUT_RD, "No more recv")
410
411#ifndef SHUT_WR
412#define SHUT_WR -1
413#endif
414CND(SHUT_WR, "No more send")
415
416#ifndef SHUT_RDWR
417#define SHUT_RDWR -1
418#endif
419CND(SHUT_RDWR, "No more recv/send")
420_NL
421TXT("   ---------------------")
422TXT("   -- Protocol levels --")
423TXT("   ---------------------")
424_NL
425
426#ifndef SOL_SOCKET
427#define SOL_SOCKET -1
428#endif
429CND(SOL_SOCKET, "Options for socket level")
430
431#ifndef IPPROTO_IP
432#define IPPROTO_IP -1
433#endif
434CND(IPPROTO_IP, "Dummy protocol for IP")
435
436#ifndef IPPROTO_UDP
437#define IPPROTO_UDP -1
438#endif
439CND(IPPROTO_UDP, "UDP")
440
441#ifndef IPPROTO_TCP
442#define IPPROTO_TCP -1
443#endif
444CND(IPPROTO_TCP, "TCP")
445_NL
446TXT("   -------------------")
447TXT("   -- Request flags --")
448TXT("   -------------------")
449_NL
450
451#ifndef MSG_OOB
452#define MSG_OOB -1
453#endif
454CND(MSG_OOB, "Process out-of-band data")
455
456#ifndef MSG_PEEK
457#define MSG_PEEK -1
458#endif
459CND(MSG_PEEK, "Peek at incoming data")
460
461#ifndef MSG_EOR
462#define MSG_EOR -1
463#endif
464CND(MSG_EOR, "Send end of record")
465
466#ifndef MSG_WAITALL
467#define MSG_WAITALL -1
468#endif
469CND(MSG_WAITALL, "Wait for full reception")
470
471#ifndef MSG_NOSIGNAL
472#define MSG_NOSIGNAL -1
473#endif
474CND(MSG_NOSIGNAL, "No SIGPIPE on send")
475
476#ifdef __linux__
477# define MSG_Forced_Flags "MSG_NOSIGNAL"
478#else
479# define MSG_Forced_Flags "0"
480#endif
481CN_(MSG_Forced_Flags, "")
482TXT("   --  Flags set on all send(2) calls")
483
484_NL
485TXT("   --------------------")
486TXT("   -- Socket options --")
487TXT("   --------------------")
488_NL
489
490#ifndef TCP_NODELAY
491#define TCP_NODELAY -1
492#endif
493CND(TCP_NODELAY, "Do not coalesce packets")
494
495#ifndef SO_REUSEADDR
496#define SO_REUSEADDR -1
497#endif
498CND(SO_REUSEADDR, "Bind reuse local address")
499
500#ifndef SO_KEEPALIVE
501#define SO_KEEPALIVE -1
502#endif
503CND(SO_KEEPALIVE, "Enable keep-alive msgs")
504
505#ifndef SO_LINGER
506#define SO_LINGER -1
507#endif
508CND(SO_LINGER, "Defer close to flush data")
509
510#ifndef SO_BROADCAST
511#define SO_BROADCAST -1
512#endif
513CND(SO_BROADCAST, "Can send broadcast msgs")
514
515#ifndef SO_SNDBUF
516#define SO_SNDBUF -1
517#endif
518CND(SO_SNDBUF, "Set/get send buffer size")
519
520#ifndef SO_RCVBUF
521#define SO_RCVBUF -1
522#endif
523CND(SO_RCVBUF, "Set/get recv buffer size")
524
525#ifndef SO_SNDTIMEO
526#define SO_SNDTIMEO -1
527#endif
528CND(SO_SNDTIMEO, "Emission timeout")
529
530#ifndef SO_RCVTIMEO
531#define SO_RCVTIMEO -1
532#endif
533CND(SO_RCVTIMEO, "Reception timeout")
534
535#ifndef SO_ERROR
536#define SO_ERROR -1
537#endif
538CND(SO_ERROR, "Get/clear error status")
539
540#ifndef IP_MULTICAST_IF
541#define IP_MULTICAST_IF -1
542#endif
543CND(IP_MULTICAST_IF, "Set/get mcast interface")
544
545#ifndef IP_MULTICAST_TTL
546#define IP_MULTICAST_TTL -1
547#endif
548CND(IP_MULTICAST_TTL, "Set/get multicast TTL")
549
550#ifndef IP_MULTICAST_LOOP
551#define IP_MULTICAST_LOOP -1
552#endif
553CND(IP_MULTICAST_LOOP, "Set/get mcast loopback")
554
555#ifndef IP_ADD_MEMBERSHIP
556#define IP_ADD_MEMBERSHIP -1
557#endif
558CND(IP_ADD_MEMBERSHIP, "Join a multicast group")
559
560#ifndef IP_DROP_MEMBERSHIP
561#define IP_DROP_MEMBERSHIP -1
562#endif
563CND(IP_DROP_MEMBERSHIP, "Leave a multicast group")
564
565_NL
566TXT("   -------------------")
567TXT("   -- System limits --")
568TXT("   -------------------")
569_NL
570
571#ifndef IOV_MAX
572#define IOV_MAX INT_MAX
573#endif
574CND(IOV_MAX, "Maximum writev iovcnt")
575
576_NL
577TXT("   ----------------------")
578TXT("   -- Type definitions --")
579TXT("   ----------------------")
580_NL
581
582{
583  struct timeval tv;
584TXT("   --  Sizes (in bytes) of the components of struct timeval")
585_NL
586#define SIZEOF_tv_sec (sizeof tv.tv_sec)
587CND(SIZEOF_tv_sec, "tv_sec")
588#define SIZEOF_tv_usec (sizeof tv.tv_usec)
589CND(SIZEOF_tv_usec, "tv_usec")
590}
591
592#ifdef __vxworks
593_NL
594TXT("   --------------------------------")
595TXT("   -- VxWorks-specific constants --")
596TXT("   --------------------------------")
597_NL
598TXT("   --  These constants may be used only within the VxWorks version of")
599TXT("   --  GNAT.Sockets.Thin.")
600_NL
601
602CND(OK,    "VxWorks generic success")
603CND(ERROR, "VxWorks generic error")
604#endif
605
606_NL
607TXT("end GNAT.Sockets.Constants;")
608
609  output ();
610  return 0;
611}
612
613void
614output (void) {
615  int text_max = 0, value_max = 0, l;
616  struct line *p;
617  char fmt[64];
618#define UPD_MAX(x) do { \
619  l = strlen (p->x); \
620  if (l > x ## _max) x ## _max = l; \
621} while (0)
622
623  for (p = first; p != NULL; p = p->next) {
624    if (p->value != NULL) {
625      UPD_MAX(text);
626      UPD_MAX(value);
627    }
628  }
629  sprintf (fmt, "   %%-%ds : constant := %%%ds;%%s%%s\n",
630    text_max, value_max);
631
632  for (p = first; p != NULL; p = p->next) {
633    if (p->value == NULL) {
634      printf ("%s\n", p->text);
635    } else {
636      char *comment_sep = (strlen (p->comment) > 0)
637                          ? " --  " : "";
638      printf (fmt, p->text, p->value, comment_sep, p->comment);
639    }
640  }
641}
642
643char *
644f_itoa (char *fmt, int n) {
645  char buf[32], *ret;
646  sprintf (buf, fmt, n);
647  ret = malloc (strlen (buf) + 1);
648  if (ret != NULL)
649    strcpy (ret, buf);
650  return ret;
651}
652
653void
654add_line (char *_text, char *_value, char *_comment) {
655  struct line *l = (struct line *) malloc (sizeof (struct line));
656
657  l->text = _text;
658  l->value = _value;
659  l->comment = _comment;
660  l->next = NULL;
661  if (last == NULL)
662    first = last = l;
663  else {
664    last->next = l;
665    last = l;
666  }
667}
Note: See TracBrowser for help on using the repository browser.