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

ada-examples-4-10-branch ada-examples-4-10-2
Last change on this file was 57716a5, checked in by Joel Sherrill <joel.sherrill@…>, on 09/17/09 at 18:13:35

2009-09-17 Joel Sherrill <joel.sherrill@…>

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