Follow API changes.
[radsecproxy.git] / lib / tests / test-blocking.c
1 #include <sys/types.h>
2 #include <sys/socket.h>
3 #include <netinet/in.h>
4 #include <netdb.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include "blocking.h"
8
9 int
10 f (const struct sockaddr *addr,
11    socklen_t addrlen,
12    int out_fd)
13 {
14   int fd = -1;
15   //struct rs_alloc_scheme as = { calloc, malloc, free, realloc };
16   struct rs_handle ctx = { RS_CONN_TYPE_TCP,
17                            { RS_CRED_NONE, NULL, NULL },
18                            { NULL, NULL, NULL, NULL } };
19   struct rs_packet *p = NULL;
20
21   fd = rs_connect (&ctx, addr, addrlen);
22   if (fd < 0)
23     {
24       perror ("rs_connect");
25       return -1;
26     }
27
28   p = next_packet (&ctx, fd);
29   if (p == NULL)
30     {
31       perror ("next_packet");
32       rs_disconnect (&ctx, fd);
33       return -1;
34     }
35   rs_disconnect (&ctx, fd);
36
37   if (send_packet (&ctx, out_fd, p))
38     {
39       rs_packet_free (&ctx, &p);
40       perror ("send_packet");
41       return -1;
42     }
43
44     return 0;
45 }
46
47 int
48 main (int argc, char *argv[])
49 {
50   struct addrinfo *ai;
51   int rc;
52
53   rc = getaddrinfo (argv[1], argv[2], NULL, &ai);
54   if (rc)
55     {
56       if (rc == EAI_SYSTEM)
57         perror ("getaddrinfo");
58       else
59         fprintf (stderr, "getaddrinfo: %s\n", gai_strerror (rc));
60       return -1;
61     }
62
63   return f (ai->ai_addr, ai->ai_addrlen, 1);
64 }