xref: /minix3/crypto/external/bsd/heimdal/dist/lib/roken/test-mini_inetd.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: test-mini_inetd.c,v 1.1.1.2 2014/04/24 12:45:52 pettai Exp $	*/
2ebfedea0SLionel Sambuc 
3ebfedea0SLionel Sambuc /***********************************************************************
4ebfedea0SLionel Sambuc  * Copyright (c) 2009, Secure Endpoints Inc.
5ebfedea0SLionel Sambuc  * All rights reserved.
6ebfedea0SLionel Sambuc  *
7ebfedea0SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
8ebfedea0SLionel Sambuc  * modification, are permitted provided that the following conditions
9ebfedea0SLionel Sambuc  * are met:
10ebfedea0SLionel Sambuc  *
11ebfedea0SLionel Sambuc  * - Redistributions of source code must retain the above copyright
12ebfedea0SLionel Sambuc  *   notice, this list of conditions and the following disclaimer.
13ebfedea0SLionel Sambuc  *
14ebfedea0SLionel Sambuc  * - Redistributions in binary form must reproduce the above copyright
15ebfedea0SLionel Sambuc  *   notice, this list of conditions and the following disclaimer in
16ebfedea0SLionel Sambuc  *   the documentation and/or other materials provided with the
17ebfedea0SLionel Sambuc  *   distribution.
18ebfedea0SLionel Sambuc  *
19ebfedea0SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20ebfedea0SLionel Sambuc  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21ebfedea0SLionel Sambuc  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22ebfedea0SLionel Sambuc  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23ebfedea0SLionel Sambuc  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24ebfedea0SLionel Sambuc  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25ebfedea0SLionel Sambuc  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26ebfedea0SLionel Sambuc  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27ebfedea0SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28ebfedea0SLionel Sambuc  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29ebfedea0SLionel Sambuc  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30ebfedea0SLionel Sambuc  * OF THE POSSIBILITY OF SUCH DAMAGE.
31ebfedea0SLionel Sambuc  *
32ebfedea0SLionel Sambuc  **********************************************************************/
33ebfedea0SLionel Sambuc 
34ebfedea0SLionel Sambuc #include <config.h>
35ebfedea0SLionel Sambuc #include <krb5/roken.h>
36ebfedea0SLionel Sambuc #include <stdio.h>
37ebfedea0SLionel Sambuc #include <string.h>
38ebfedea0SLionel Sambuc #include <stdlib.h>
39ebfedea0SLionel Sambuc 
40ebfedea0SLionel Sambuc #define PORT 8013
41ebfedea0SLionel Sambuc #define PORT_S "8013"
42ebfedea0SLionel Sambuc 
43ebfedea0SLionel Sambuc char * prog = "Master";
44ebfedea0SLionel Sambuc int is_client = 0;
45ebfedea0SLionel Sambuc 
46ebfedea0SLionel Sambuc static int
get_address(int flags,struct addrinfo ** ret)47ebfedea0SLionel Sambuc get_address(int flags, struct addrinfo ** ret)
48ebfedea0SLionel Sambuc {
49ebfedea0SLionel Sambuc     struct addrinfo ai;
50ebfedea0SLionel Sambuc     int rv;
51ebfedea0SLionel Sambuc 
52ebfedea0SLionel Sambuc     memset(&ai, 0, sizeof(ai));
53ebfedea0SLionel Sambuc 
54ebfedea0SLionel Sambuc     ai.ai_flags = flags | AI_NUMERICHOST;
55ebfedea0SLionel Sambuc     ai.ai_family = AF_INET;
56ebfedea0SLionel Sambuc     ai.ai_socktype = SOCK_STREAM;
57ebfedea0SLionel Sambuc     ai.ai_protocol = PF_UNSPEC;
58ebfedea0SLionel Sambuc 
59ebfedea0SLionel Sambuc     rv = getaddrinfo("127.0.0.1", PORT_S, &ai, ret);
60ebfedea0SLionel Sambuc     if (rv)
61ebfedea0SLionel Sambuc 	warnx("getaddrinfo: %s", gai_strerror(rv));
62ebfedea0SLionel Sambuc     return rv;
63ebfedea0SLionel Sambuc }
64ebfedea0SLionel Sambuc 
65ebfedea0SLionel Sambuc static int
get_connected_socket(rk_socket_t * s_ret)66ebfedea0SLionel Sambuc get_connected_socket(rk_socket_t * s_ret)
67ebfedea0SLionel Sambuc {
68ebfedea0SLionel Sambuc     struct addrinfo * ai = NULL;
69ebfedea0SLionel Sambuc     int rv = 0;
70ebfedea0SLionel Sambuc     rk_socket_t s = rk_INVALID_SOCKET;
71ebfedea0SLionel Sambuc 
72ebfedea0SLionel Sambuc     rv = get_address(0, &ai);
73ebfedea0SLionel Sambuc     if (rv)
74ebfedea0SLionel Sambuc 	return rv;
75ebfedea0SLionel Sambuc 
76ebfedea0SLionel Sambuc     s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
77ebfedea0SLionel Sambuc     if (rk_IS_BAD_SOCKET(s)) {
78ebfedea0SLionel Sambuc 	rv = 1;
79ebfedea0SLionel Sambuc 	goto done;
80ebfedea0SLionel Sambuc     }
81ebfedea0SLionel Sambuc 
82ebfedea0SLionel Sambuc     rv = connect(s, ai->ai_addr, ai->ai_addrlen);
83ebfedea0SLionel Sambuc     if (rk_IS_SOCKET_ERROR(rv))
84ebfedea0SLionel Sambuc 	goto done;
85ebfedea0SLionel Sambuc 
86ebfedea0SLionel Sambuc     *s_ret = s;
87ebfedea0SLionel Sambuc     s = rk_INVALID_SOCKET;
88ebfedea0SLionel Sambuc     rv = 0;
89ebfedea0SLionel Sambuc 
90ebfedea0SLionel Sambuc  done:
91ebfedea0SLionel Sambuc     if (!rk_IS_BAD_SOCKET(s))
92ebfedea0SLionel Sambuc 	rk_closesocket(s);
93ebfedea0SLionel Sambuc 
94ebfedea0SLionel Sambuc     if (ai)
95ebfedea0SLionel Sambuc 	freeaddrinfo(ai);
96ebfedea0SLionel Sambuc 
97ebfedea0SLionel Sambuc     return (rv) ? rk_SOCK_ERRNO : 0;
98ebfedea0SLionel Sambuc }
99ebfedea0SLionel Sambuc 
100ebfedea0SLionel Sambuc const char * test_strings[] = {
101ebfedea0SLionel Sambuc     "Hello",
102ebfedea0SLionel Sambuc     "01234566789012345689012345678901234567890123456789",
103ebfedea0SLionel Sambuc     "Another test",
104ebfedea0SLionel Sambuc     "exit"
105ebfedea0SLionel Sambuc };
106ebfedea0SLionel Sambuc 
107ebfedea0SLionel Sambuc static int
test_simple_echo_client(void)108ebfedea0SLionel Sambuc test_simple_echo_client(void)
109ebfedea0SLionel Sambuc {
110ebfedea0SLionel Sambuc     rk_socket_t s = rk_INVALID_SOCKET;
111ebfedea0SLionel Sambuc     int rv;
112ebfedea0SLionel Sambuc     char buf[81];
113ebfedea0SLionel Sambuc     int i;
114ebfedea0SLionel Sambuc 
115ebfedea0SLionel Sambuc     fprintf(stderr, "[%s] Getting connected socket...", getprogname());
116ebfedea0SLionel Sambuc     rv = get_connected_socket(&s);
117ebfedea0SLionel Sambuc     if (rv) {
118ebfedea0SLionel Sambuc 	fprintf(stderr, "\n[%s] get_connected_socket() failed (%s)\n",
119ebfedea0SLionel Sambuc 		getprogname(), strerror(rk_SOCK_ERRNO));
120ebfedea0SLionel Sambuc 	return 1;
121ebfedea0SLionel Sambuc     }
122ebfedea0SLionel Sambuc 
123ebfedea0SLionel Sambuc     fprintf(stderr, "[%s] done\n", getprogname());
124ebfedea0SLionel Sambuc 
125ebfedea0SLionel Sambuc     for (i=0; i < sizeof(test_strings)/sizeof(test_strings[0]); i++) {
126ebfedea0SLionel Sambuc 	rv = send(s, test_strings[i], strlen(test_strings[i]), 0);
127ebfedea0SLionel Sambuc 	if (rk_IS_SOCKET_ERROR(rv)) {
128ebfedea0SLionel Sambuc 	    fprintf(stderr, "[%s] send() failure (%s)\n",
129ebfedea0SLionel Sambuc 		    getprogname(), strerror(rk_SOCK_ERRNO));
130ebfedea0SLionel Sambuc 	    rk_closesocket(s);
131ebfedea0SLionel Sambuc 	    return 1;
132ebfedea0SLionel Sambuc 	}
133ebfedea0SLionel Sambuc 
134ebfedea0SLionel Sambuc 	rv = recv(s, buf, sizeof(buf), 0);
135ebfedea0SLionel Sambuc 	if (rk_IS_SOCKET_ERROR(rv)) {
136ebfedea0SLionel Sambuc 	    fprintf (stderr, "[%s] recv() failure (%s)\n",
137ebfedea0SLionel Sambuc 		     getprogname(), strerror(rk_SOCK_ERRNO));
138ebfedea0SLionel Sambuc 	    rk_closesocket(s);
139ebfedea0SLionel Sambuc 	    return 1;
140ebfedea0SLionel Sambuc 	}
141ebfedea0SLionel Sambuc 
142ebfedea0SLionel Sambuc 	if (rv == 0) {
143ebfedea0SLionel Sambuc 	    fprintf (stderr, "[%s] No data received\n", prog);
144ebfedea0SLionel Sambuc 	    rk_closesocket(s);
145ebfedea0SLionel Sambuc 	    return 1;
146ebfedea0SLionel Sambuc 	}
147ebfedea0SLionel Sambuc 
148ebfedea0SLionel Sambuc 	if (rv != strlen(test_strings[i])) {
149ebfedea0SLionel Sambuc 	    fprintf (stderr, "[%s] Data length mismatch %d != %d\n", prog, rv, strlen(test_strings[i]));
150ebfedea0SLionel Sambuc 	    rk_closesocket(s);
151ebfedea0SLionel Sambuc 	    return 1;
152ebfedea0SLionel Sambuc 	}
153ebfedea0SLionel Sambuc     }
154ebfedea0SLionel Sambuc 
155ebfedea0SLionel Sambuc     fprintf (stderr, "[%s] Done\n", prog);
156ebfedea0SLionel Sambuc     rk_closesocket(s);
157ebfedea0SLionel Sambuc     return 0;
158ebfedea0SLionel Sambuc }
159ebfedea0SLionel Sambuc 
160ebfedea0SLionel Sambuc static int
test_simple_echo_socket(void)161ebfedea0SLionel Sambuc test_simple_echo_socket(void)
162ebfedea0SLionel Sambuc {
163ebfedea0SLionel Sambuc     fprintf (stderr, "[%s] Process ID %d\n", prog, GetCurrentProcessId());
164ebfedea0SLionel Sambuc     fprintf (stderr, "[%s] Starting echo test with sockets\n", prog);
165ebfedea0SLionel Sambuc 
166ebfedea0SLionel Sambuc     if (is_client) {
167ebfedea0SLionel Sambuc 	return test_simple_echo_client();
168ebfedea0SLionel Sambuc     } else {
169ebfedea0SLionel Sambuc 
170ebfedea0SLionel Sambuc 	rk_socket_t s = rk_INVALID_SOCKET;
171ebfedea0SLionel Sambuc 
172ebfedea0SLionel Sambuc 	fprintf (stderr, "[%s] Listening for connections...\n", prog);
173ebfedea0SLionel Sambuc 	mini_inetd(htons(PORT), &s);
174ebfedea0SLionel Sambuc 	if (rk_IS_BAD_SOCKET(s)) {
175ebfedea0SLionel Sambuc 	    fprintf (stderr, "[%s] Connect failed (%s)\n",
176ebfedea0SLionel Sambuc 		     getprogname(), strerror(rk_SOCK_ERRNO));
177ebfedea0SLionel Sambuc 	} else {
178ebfedea0SLionel Sambuc 	    fprintf (stderr, "[%s] Connected\n", prog);
179ebfedea0SLionel Sambuc 	}
180ebfedea0SLionel Sambuc 
181ebfedea0SLionel Sambuc 	{
182ebfedea0SLionel Sambuc 	    char buf[81];
183ebfedea0SLionel Sambuc 	    int rv, srv;
184ebfedea0SLionel Sambuc 
185ebfedea0SLionel Sambuc 	    while ((rv = recv(s, buf, sizeof(buf), 0)) != 0 && !rk_IS_SOCKET_ERROR(rv)) {
186ebfedea0SLionel Sambuc 		buf[rv] = 0;
187ebfedea0SLionel Sambuc 		fprintf(stderr, "[%s] Received [%s]\n", prog, buf);
188ebfedea0SLionel Sambuc 
189ebfedea0SLionel Sambuc 		/* simple echo */
190ebfedea0SLionel Sambuc 		srv = send(s, buf, rv, 0);
191ebfedea0SLionel Sambuc 		if (srv != rv) {
192ebfedea0SLionel Sambuc 		    if (rk_IS_SOCKET_ERROR(srv))
193ebfedea0SLionel Sambuc 			fprintf(stderr, "[%s] send() error [%s]\n",
194ebfedea0SLionel Sambuc 				getprogname(), strerror(rk_SOCK_ERRNO));
195ebfedea0SLionel Sambuc 		    else
196ebfedea0SLionel Sambuc 			fprintf(stderr, "[%s] send() size mismatch %d != %d",
197ebfedea0SLionel Sambuc 				getprogname(), srv, rv);
198ebfedea0SLionel Sambuc 		}
199ebfedea0SLionel Sambuc 
200ebfedea0SLionel Sambuc 		if (!strcmp(buf, "exit")) {
201ebfedea0SLionel Sambuc 		    fprintf(stderr, "[%s] Exiting...\n", prog);
202ebfedea0SLionel Sambuc 		    shutdown(s, SD_SEND);
203ebfedea0SLionel Sambuc 		    rk_closesocket(s);
204ebfedea0SLionel Sambuc 		    return 0;
205ebfedea0SLionel Sambuc 		}
206ebfedea0SLionel Sambuc 	    }
207ebfedea0SLionel Sambuc 
208ebfedea0SLionel Sambuc 	    fprintf(stderr, "[%s] recv() failed (%s)\n",
209ebfedea0SLionel Sambuc 		    getprogname(),
210ebfedea0SLionel Sambuc 		    strerror(rk_SOCK_ERRNO));
211ebfedea0SLionel Sambuc 	}
212ebfedea0SLionel Sambuc 
213ebfedea0SLionel Sambuc 	rk_closesocket(s);
214ebfedea0SLionel Sambuc     }
215ebfedea0SLionel Sambuc 
216ebfedea0SLionel Sambuc     return 1;
217ebfedea0SLionel Sambuc }
218ebfedea0SLionel Sambuc 
219ebfedea0SLionel Sambuc static int
test_simple_echo(void)220ebfedea0SLionel Sambuc test_simple_echo(void)
221ebfedea0SLionel Sambuc {
222ebfedea0SLionel Sambuc     fprintf (stderr, "[%s] Starting echo test\n", prog);
223ebfedea0SLionel Sambuc 
224ebfedea0SLionel Sambuc     if (is_client) {
225ebfedea0SLionel Sambuc 
226ebfedea0SLionel Sambuc 	return test_simple_echo_client();
227ebfedea0SLionel Sambuc 
228ebfedea0SLionel Sambuc     } else {
229ebfedea0SLionel Sambuc 
230ebfedea0SLionel Sambuc 	fprintf (stderr, "[%s] Listening for connections...\n", prog);
231ebfedea0SLionel Sambuc 	mini_inetd(htons(PORT), NULL);
232ebfedea0SLionel Sambuc 	fprintf (stderr, "[%s] Connected\n", prog);
233ebfedea0SLionel Sambuc 
234ebfedea0SLionel Sambuc 	{
235ebfedea0SLionel Sambuc 	    char buf[81];
236ebfedea0SLionel Sambuc 	    while (gets(buf)) {
237ebfedea0SLionel Sambuc 		fprintf(stderr, "[%s] Received [%s]\n", prog, buf);
238ebfedea0SLionel Sambuc 
239ebfedea0SLionel Sambuc 		if (!strcmp(buf, "exit"))
240ebfedea0SLionel Sambuc 		    return 0;
241ebfedea0SLionel Sambuc 
242ebfedea0SLionel Sambuc 		/* simple echo */
243ebfedea0SLionel Sambuc 		puts(buf);
244ebfedea0SLionel Sambuc 	    }
245ebfedea0SLionel Sambuc 
246ebfedea0SLionel Sambuc 	    fprintf(stderr, "[%s] gets() failed (%s)\n", prog, _strerror("gets"));
247ebfedea0SLionel Sambuc 	}
248ebfedea0SLionel Sambuc     }
249ebfedea0SLionel Sambuc 
250ebfedea0SLionel Sambuc     return 1;
251ebfedea0SLionel Sambuc }
252ebfedea0SLionel Sambuc 
253ebfedea0SLionel Sambuc static int
do_client(void)254ebfedea0SLionel Sambuc do_client(void)
255ebfedea0SLionel Sambuc {
256ebfedea0SLionel Sambuc     int rv = 0;
257ebfedea0SLionel Sambuc 
258ebfedea0SLionel Sambuc     rk_SOCK_INIT();
259ebfedea0SLionel Sambuc 
260ebfedea0SLionel Sambuc     prog = "Client";
261ebfedea0SLionel Sambuc     is_client = 1;
262ebfedea0SLionel Sambuc 
263ebfedea0SLionel Sambuc     fprintf(stderr, "Starting client...\n");
264ebfedea0SLionel Sambuc 
265ebfedea0SLionel Sambuc     rv = test_simple_echo_socket();
266ebfedea0SLionel Sambuc 
267ebfedea0SLionel Sambuc     rk_SOCK_EXIT();
268ebfedea0SLionel Sambuc 
269ebfedea0SLionel Sambuc     return rv;
270ebfedea0SLionel Sambuc }
271ebfedea0SLionel Sambuc 
272ebfedea0SLionel Sambuc static int
do_server(void)273ebfedea0SLionel Sambuc do_server(void)
274ebfedea0SLionel Sambuc {
275ebfedea0SLionel Sambuc     int rv = 0;
276ebfedea0SLionel Sambuc 
277ebfedea0SLionel Sambuc     rk_SOCK_INIT();
278ebfedea0SLionel Sambuc 
279ebfedea0SLionel Sambuc     prog = "Server";
280ebfedea0SLionel Sambuc 
281ebfedea0SLionel Sambuc     fprintf(stderr, "Starting server...\n");
282ebfedea0SLionel Sambuc 
283ebfedea0SLionel Sambuc     rv = test_simple_echo_socket();
284ebfedea0SLionel Sambuc 
285ebfedea0SLionel Sambuc     rk_SOCK_EXIT();
286ebfedea0SLionel Sambuc 
287ebfedea0SLionel Sambuc     return rv;
288ebfedea0SLionel Sambuc }
289ebfedea0SLionel Sambuc 
290ebfedea0SLionel Sambuc static time_t
wait_callback(void * p)291ebfedea0SLionel Sambuc wait_callback(void *p)
292ebfedea0SLionel Sambuc {
293ebfedea0SLionel Sambuc     return (time_t)-1;
294ebfedea0SLionel Sambuc }
295ebfedea0SLionel Sambuc 
296ebfedea0SLionel Sambuc static int
do_test(char * path)297ebfedea0SLionel Sambuc do_test(char * path)
298ebfedea0SLionel Sambuc {
299ebfedea0SLionel Sambuc     intptr_t p_server;
300ebfedea0SLionel Sambuc     intptr_t p_client;
301ebfedea0SLionel Sambuc     int client_rv;
302ebfedea0SLionel Sambuc     int server_rv;
303ebfedea0SLionel Sambuc 
304ebfedea0SLionel Sambuc     p_server = _spawnl(_P_NOWAIT, path, path, "--server", NULL);
305ebfedea0SLionel Sambuc     if (p_server <= 0) {
306ebfedea0SLionel Sambuc 	fprintf(stderr, "%s: %s", path, _strerror("Can't start server process"));
307ebfedea0SLionel Sambuc 	return 1;
308ebfedea0SLionel Sambuc     }
309ebfedea0SLionel Sambuc #ifdef _WIN32
310ebfedea0SLionel Sambuc     /* On Windows, the _spawn*() functions return a process handle on
311ebfedea0SLionel Sambuc        success.  We need a process ID for use with
312ebfedea0SLionel Sambuc        wait_for_process_timed(). */
313ebfedea0SLionel Sambuc 
314ebfedea0SLionel Sambuc     p_server = GetProcessId((HANDLE) p_server);
315ebfedea0SLionel Sambuc #endif
316ebfedea0SLionel Sambuc     fprintf(stderr, "Created server process ID %d\n", p_server);
317ebfedea0SLionel Sambuc 
318ebfedea0SLionel Sambuc     p_client = _spawnl(_P_NOWAIT, path, path, "--client", NULL);
319ebfedea0SLionel Sambuc     if (p_client <= 0) {
320ebfedea0SLionel Sambuc 	fprintf(stderr, "%s: %s", path, _strerror("Can't start client process"));
321ebfedea0SLionel Sambuc 	fprintf(stderr, "Waiting for server process to terminate ...");
322ebfedea0SLionel Sambuc 	wait_for_process_timed(p_server, wait_callback, NULL, 5);
323ebfedea0SLionel Sambuc 	fprintf(stderr, "DONE\n");
324ebfedea0SLionel Sambuc 	return 1;
325ebfedea0SLionel Sambuc     }
326ebfedea0SLionel Sambuc #ifdef _WIN32
327ebfedea0SLionel Sambuc     p_client = GetProcessId((HANDLE) p_client);
328ebfedea0SLionel Sambuc #endif
329ebfedea0SLionel Sambuc     fprintf(stderr, "Created client process ID %d\n", p_client);
330ebfedea0SLionel Sambuc 
331ebfedea0SLionel Sambuc     fprintf(stderr, "Waiting for client process to terminate ...");
332ebfedea0SLionel Sambuc     client_rv = wait_for_process_timed(p_client, wait_callback, NULL, 5);
333ebfedea0SLionel Sambuc     if (SE_IS_ERROR(client_rv)) {
334ebfedea0SLionel Sambuc 	fprintf(stderr, "\nwait_for_process_timed() failed for client. rv=%d\n", client_rv);
335ebfedea0SLionel Sambuc     } else {
336ebfedea0SLionel Sambuc 	fprintf(stderr, "DONE\n");
337ebfedea0SLionel Sambuc     }
338ebfedea0SLionel Sambuc 
339ebfedea0SLionel Sambuc     fprintf(stderr, "Waiting for server process to terminate ...");
340ebfedea0SLionel Sambuc     server_rv = wait_for_process_timed(p_server, wait_callback, NULL, 5);
341ebfedea0SLionel Sambuc     if (SE_IS_ERROR(server_rv)) {
342ebfedea0SLionel Sambuc 	fprintf(stderr, "\nwait_for_process_timed() failed for server. rv=%d\n", server_rv);
343ebfedea0SLionel Sambuc     } else {
344ebfedea0SLionel Sambuc 	fprintf(stderr, "DONE\n");
345ebfedea0SLionel Sambuc     }
346ebfedea0SLionel Sambuc 
347ebfedea0SLionel Sambuc     if (client_rv == 0 && server_rv == 0) {
348ebfedea0SLionel Sambuc 	fprintf(stderr, "PASS\n");
349ebfedea0SLionel Sambuc 	return 0;
350ebfedea0SLionel Sambuc     } else {
351ebfedea0SLionel Sambuc 	fprintf(stderr, "FAIL: Client rv=%d, Server rv=%d\n", client_rv, server_rv);
352ebfedea0SLionel Sambuc 	return 1;
353ebfedea0SLionel Sambuc     }
354ebfedea0SLionel Sambuc }
355ebfedea0SLionel Sambuc 
main(int argc,char ** argv)356ebfedea0SLionel Sambuc int main(int argc, char ** argv)
357ebfedea0SLionel Sambuc {
358ebfedea0SLionel Sambuc     setprogname(argv[0]);
359ebfedea0SLionel Sambuc 
360ebfedea0SLionel Sambuc     if (argc == 2 && strcmp(argv[1], "--client") == 0)
361ebfedea0SLionel Sambuc 	return do_client();
362ebfedea0SLionel Sambuc     else if (argc == 2 && strcmp(argv[1], "--server") == 0)
363ebfedea0SLionel Sambuc 	return do_server();
364ebfedea0SLionel Sambuc     else if (argc == 1)
365ebfedea0SLionel Sambuc 	return do_test(argv[0]);
366ebfedea0SLionel Sambuc     else {
367ebfedea0SLionel Sambuc 	printf ("%s: Test mini_inetd() function.  Run with no arguments to start test\n",
368ebfedea0SLionel Sambuc 		argv[0]);
369ebfedea0SLionel Sambuc 	return 1;
370ebfedea0SLionel Sambuc     }
371ebfedea0SLionel Sambuc }
372