Sync usage with man page.
[netbsd-mini2440.git] / sys / rump / librump / test / sysproxy / serv / sysproxy_serv.c
blob0e7860661746be2059df68466a5eeca6bcc33906
1 #include <sys/types.h>
2 #include <sys/socket.h>
3 #include <sys/un.h>
5 #include <netinet/in.h>
7 #include <rump/rump.h>
9 #include <signal.h>
10 #include <string.h>
11 #include <unistd.h>
12 #include <stdlib.h>
14 #define SERVPATH "/tmp/rump_sysproxy_test"
15 #define USE_UN
17 static void
18 cleanup()
21 unlink(SERVPATH);
24 static void
25 sigint(int sig)
28 cleanup();
29 _exit(0);
32 static void
33 sigabrt(int sig)
36 cleanup();
37 abort();
40 int
41 main()
43 socklen_t slen;
44 int s, s2;
46 #ifdef USE_UN
47 struct sockaddr_un sun;
49 s = socket(AF_LOCAL, SOCK_STREAM, 0);
50 if (s == -1)
51 err(1, "socket");
53 memset(&sun, 0, sizeof(sun));
54 sun.sun_family = AF_LOCAL;
55 strcpy(sun.sun_path, SERVPATH);
56 if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) == -1)
57 err(1, "bind");
58 atexit(cleanup);
59 signal(SIGINT, sigint);
60 signal(SIGSEGV, sigabrt);
61 if (listen(s, 1) == -1)
62 err(1, "listen");
63 slen = sizeof(sun);
64 s2 = accept(s, (struct sockaddr *)&sun, &slen);
65 if (s2 == -1)
66 err(1, "accept");
67 #else
68 struct sockaddr_in sin;
70 s = socket(AF_INET, SOCK_STREAM, 0);
71 if (s == -1)
72 err(1, "socket");
74 memset(&sin, 0, sizeof(sin));
75 sin.sin_family = AF_INET;
76 sin.sin_port = htons(12345);
77 sin.sin_addr.s_addr = INADDR_ANY;
79 if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) == -1)
80 err(1, "bind");
81 if (listen(s, 1) == -1)
82 err(1, "listen");
83 slen = sizeof(sin);
84 s2 = accept(s, (struct sockaddr *)&sin, &slen);
85 if (s2 == -1)
86 err(1, "accept");
87 #endif
89 rump_init();
90 rump_sysproxy_socket_setup_server(s2);
92 pause();
94 return 0;