WIP on libradsec: 94e3f46 Example client crafting simple packet using freeradius...
[radsecproxy.git] / lib / examples / client.c
1 /* RADIUS client doing blocking i/o.  */
2
3 #include <stdio.h>
4 #include <string.h>
5 #include <unistd.h>
6 #include "../libradsec.h"
7 #include "../debug.h"
8
9 #define SECRET "sikrit"
10 #define USER_NAME "bob"
11 #define USER_PW "hemligt"
12
13 int
14 rsx_client (const char *srvname, int srvport)
15 {
16   struct rs_context *h;
17   struct rs_connecion *conn;
18   struct rs_packet *req, *resp;
19
20   if (rs_context_create (&h, "/usr/share/freeradius/dictionary"))
21     return rs_err_code (rs_ctx_err_code (h));
22
23   if (rs_conn_new (h, &conn))
24     return rs_err_code (rs_conn_err_code (conn));
25   if (rs_conn_add_server (conn, RS_CONN_TYPE_UDP, srvname, srvport, 10, 3, SECRET))
26     return rs_err_code (rs_conn_err_code (conn));
27
28   if (rs_packet_create_acc_request (conn, &req, USER_NAME, USER_PW))
29     return rs_err_code (rs_conn_err_code (conn));
30
31   if (rs_packet_send (req))
32     return rs_err_code (rs_conn_err_code (conn));
33   req = NULL;
34
35   if (rs_packet_recv (conn, &resp))
36     return rs_err_code (rs_conn_err_code (conn));
37
38   rs_conn_destroy (conn);
39   rs_context_destroy (h);
40 }
41
42 int
43 main (int argc, char *argv[])
44 {
45   exit (rsx_client ());
46 }