Check which getprotobynumber_r() variant to use
[socat.git] / xiohelp.c
blobf4431ffbcb4aa3d9449a57f30a766a093968b62a
1 /* source: xiohelp.c */
2 /* Copyright Gerhard Rieger and contributors (see file CHANGES) */
3 /* Published under the GNU General Public License V.2, see file COPYING */
5 /* this file contains the source for the help function */
7 #include "xiosysincludes.h"
8 #include "xioopen.h"
10 #include "xiohelp.h"
12 #if WITH_HELP
14 /* keep consistent with xioopts.h:enum e_types ! */
15 static const char *optiontypenames[] = {
16 "CONST", "BIN", "BOOL", "BYTE",
17 "INT", "LONG", "STRING", "PTRDIFF",
18 "SHORT", "SIZE_T", "SOCKADDR", "UNSIGNED-INT",
19 "UNSIGNED-LONG","UNSIGNED-SHORT","MODE_T", "GID_T",
20 "UID_T", "INT[3]", "STRUCT-TIMEVAL", "STRUCT-TIMESPEC",
21 "DOUBLE", "STRING-NULL", "LONG-LONG", "OFF_T",
22 "OFF64_T", "INT:INT", "INT:INTP", "INT:BIN",
23 "INT:STRING", "INT:INT:INT", "INT:INT:BIN", "INT:INT:STRING",
24 "INT:INT:GENERIC",
25 "IP4NAME",
27 #if HAVE_STRUCT_LINGER
28 "STRUCT-LINGER",
29 #endif
30 #if HAVE_STRUCT_IP_MREQN
31 "STRUCT-IP_MREQN",
32 #elif HAVE_STRUCT_IP_MREQ
33 "STRUCT-IP_MREQ",
34 #endif
35 #if HAVE_STRUCT_IP_MREQ_SOURCE
36 "IP-MREQ-SOURCE",
37 #endif
38 "GENERIC",
39 } ;
42 /* keep consistent with xioopts.h:#define GROUP_* ! */
43 static const char *addressgroupnames[] = {
44 "FD", "FIFO", "CHR", "BLK",
45 "REG", "SOCKET", "READLINE", "undef",
46 "NAMED", "OPEN", "EXEC", "FORK",
47 "LISTEN", "DEVICE", "CHILD", "RETRY",
48 "TERMIOS", "RANGE", "PTY", "PARENT",
49 "UNIX", "IP4", "IP6", "INTERFACE",
50 "UDP", "TCP", "SOCKS4", "OPENSSL",
51 "PROCESS", "APPL", "HTTP", "SCTP"
52 } ;
55 /* keep consistent with xioopts.h:enum ephase ! */
56 static char *optionphasenames[] = {
57 "ALL", "INIT", "EARLY",
58 "PREOPEN", "OPEN", "PASTOPEN",
59 "PRESOCKET", "SOCKET", "PASTSOCKET",
60 "PREBIGEN", "BIGEN", "PASTBIGEN",
61 "FD",
62 "PREBIND", "BIND", "PASTBIND",
63 "PRELISTEN", "LISTEN", "PASTLISTEN",
64 "PRECONNECT", "CONNECT", "PASTCONNECT",
65 "PREACCEPT", "ACCEPT", "PASTACCEPT",
66 "CONNECTED",
67 "PREFORK", "FORK", "PASTFORK",
68 "LATE", "LATE2",
69 "PREEXEC", "EXEC", "SPECIFIC",
70 NULL
71 } ;
74 /* print a line about a single option */
75 static int xiohelp_option(FILE *of, const struct optname *on, const char *name) {
76 int j;
77 unsigned int groups;
78 bool occurred;
80 fprintf(of, " %s\tgroups=", name);
81 groups = on->desc->group; occurred = false;
82 for (j = 0; j < 32; ++j) {
83 if (groups & 1) {
84 if (occurred) { fputc(',', of); }
85 fprintf(of, "%s", addressgroupnames[j]);
86 occurred = true;
88 groups >>= 1;
90 fprintf(of, "\tphase=%s", optionphasenames[on->desc->phase]);
91 fprintf(of, "\ttype=%s", optiontypenames[on->desc->type]);
92 fputc('\n', of);
93 return 0;
96 int xioopenhelp(FILE *of,
97 int level /* 0..only addresses, 1..and options */
98 ) {
99 const struct addrname *an;
100 const struct optname *on;
101 int i, j;
102 unsigned int groups;
103 bool occurred;
105 fputs(" bi-address:\n", of);
106 fputs(" pipe[,<opts>]\tgroups=FD,FIFO\n", of);
107 if (level == 2) {
108 fputs(" echo is an alias for pipe\n", of);
109 fputs(" fifo is an alias for pipe\n", of);
111 fputs(" <single-address>!!<single-address>\n", of);
112 fputs(" <single-address>\n", of);
113 fputs(" single-address:\n", of);
114 fputs(" <address-head>[,<opts>]\n", of);
115 fputs(" address-head:\n", of);
116 an = &addressnames[0];
117 i = 0;
118 while (addressnames[i].name) {
119 if (!strcmp(an->name, an->desc->defname)) {
120 /* it is a canonical address name */
121 fprintf(of, " %s", an->name);
122 if (an->desc->syntax) {
123 fputs(an->desc->syntax, of); }
124 fputs("\tgroups=", of);
125 groups = an->desc->groups; occurred = false;
126 for (j = 0; j < 32; ++j) {
127 if (groups & 1) {
128 if (occurred) { fputc(',', of); }
129 fprintf(of, "%s", addressgroupnames[j]);
130 occurred = true;
132 groups >>= 1;
134 fputc('\n', of);
135 } else if (level == 2) {
136 fprintf(of, " %s is an alias name for %s\n", an->name, an->desc->defname);
138 ++an; ++i;
140 if (level == 2) {
141 fputs(" <num> is a short form for fd:<num>\n", of);
142 fputs(" <filename> is a short form for gopen:<filename>\n", of);
145 if (level <= 0) return 0;
147 fputs(" opts:\n", of);
148 fputs(" <opt>{,<opts>}:\n", of);
149 fputs(" opt:\n", of);
150 on = optionnames;
151 while (on->name != NULL) {
152 if (on->desc->nickname!= NULL
153 && !strcmp(on->name, on->desc->nickname)) {
154 if (level == 2) {
155 fprintf(of, " %s is an alias for %s\n", on->name, on->desc->defname);
156 } else {
157 xiohelp_option(of, on, on->name);
159 } else if (on->desc->nickname == NULL &&
160 !strcmp(on->name, on->desc->defname)) {
161 xiohelp_option(of, on, on->name);
162 } else if (level == 2) {
163 if (!strcmp(on->name, on->desc->defname)) {
164 xiohelp_option(of, on, on->name);
165 } else {
166 fprintf(of, " %s is an alias for %s\n", on->name, on->desc->defname);
169 ++on;
171 fflush(of);
172 return 0;
175 #endif /* WITH_HELP */