user dispatch WIP 0
[radsecproxy.git] / lib / examples / client-oyo.c
1 /* RADIUS/RadSec client using libradsec in on-your-own mode. */
2
3 #include <sys/select.h>
4 #include <errno.h>
5 #include <stdio.h>
6
7 int
8 loop ()
9 {
10   int n;
11   fd_set rfds, wfds, xfds;
12   //struct timeval timeout = {1,0}; /* 1 second. */
13
14   fd = FIXME;
15
16   FD_ZERO(&rfds);
17   FD_SET(fd, &rfds);
18   FD_ZERO(&wfds);
19   FD_SET(fd, &wfds);
20   FD_ZERO(&xfds);
21   FD_SET(fd, &xfds);
22
23   while (1)
24     {
25       n = select (fd + 1, &rfds, &wfds, &xfds, NULL);
26       if (n == 0)
27         {
28           /* Timeout. */
29           fprintf (stderr, "timeout on fd %d after %d seconds\n", fd,
30                    timeout.tv_sec);
31           return -1;
32         }
33       else if (n == -1)
34         {
35           /* Error. */
36           perror ("select");
37           return -errno;
38         }
39       else
40         {
41           /* Ready to read/write/<had error>. */
42           if (FD_ISSET(fd, &rfds))
43             {
44               printf ("reading msg\n");
45               radsec_recv_blocking(fd, &msg_in);
46               if (!verify_packet(&msg_in))
47             }
48           if (FD_ISSET(fd, &wfds))
49             {
50               radsec_send(fd, &msg_out);
51               printf ("msg sent\n");
52             }
53           if (FD_ISSET(fd, &xfds))
54             {
55               fprintf (stderr, "error on fd %d\n", fd);
56               return -1;
57             }
58         }
59     }
60 }
61
62 int
63 main (int argc, char *argv[])
64 {
65   return loop ();
66 }