summaryrefslogtreecommitdiff
path: root/lib/examples/client.c
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2010-09-28 22:27:04 +0200
committerLinus Nordberg <linus@nordu.net>2010-09-28 22:27:04 +0200
commite981fbcf3909fbaba462c7b578f29fa67b3bc74b (patch)
treef67203b602b71600020e95ff6805d6aa71331237 /lib/examples/client.c
parent07fa3839c8bddd1ad91f86243dd582c0359ba3e1 (diff)
WIP.
Diffstat (limited to 'lib/examples/client.c')
-rw-r--r--lib/examples/client.c46
1 files changed, 32 insertions, 14 deletions
diff --git a/lib/examples/client.c b/lib/examples/client.c
index 37601b6..eab4390 100644
--- a/lib/examples/client.c
+++ b/lib/examples/client.c
@@ -3,6 +3,7 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <stdlib.h>
#include "../libradsec.h"
#include "../debug.h"
@@ -10,37 +11,54 @@
#define USER_NAME "bob"
#define USER_PW "hemligt"
-int
+struct rs_error *
rsx_client (const char *srvname, int srvport)
{
- struct rs_context *h;
- struct rs_connecion *conn;
- struct rs_packet *req, *resp;
+ struct rs_handle *h;
+ struct rs_connection *conn;
+ struct rs_peer *server;
+ struct rs_packet *req;
+ //struct rs_packet *resp;
if (rs_context_create (&h, "/usr/share/freeradius/dictionary"))
- return rs_err_code (rs_ctx_err_code (h));
+ return NULL;
- if (rs_conn_new (h, &conn))
- return rs_err_code (rs_conn_err_code (conn));
- if (rs_conn_add_server (conn, RS_CONN_TYPE_UDP, srvname, srvport, 10, 3, SECRET))
- return rs_err_code (rs_conn_err_code (conn));
+ if (rs_conn_create (h, &conn))
+ return rs_conn_err_pop (conn);
+ if (rs_conn_add_server (conn, &server, RS_CONN_TYPE_UDP, srvname, srvport))
+ return rs_conn_err_pop (conn);
+ rs_server_set_timeout (server, 10);
+ rs_server_set_tries (server, 3);
+ rs_server_set_secret (server, SECRET);
if (rs_packet_create_acc_request (conn, &req, USER_NAME, USER_PW))
- return rs_err_code (rs_conn_err_code (conn));
+ return rs_conn_err_pop (conn);
- if (rs_packet_send (req))
- return rs_err_code (rs_conn_err_code (conn));
+ if (rs_packet_send (conn, req, NULL))
+ return rs_conn_err_pop (conn);
req = NULL;
+#if 0
+ printf ("waiting for response\n");
if (rs_packet_recv (conn, &resp))
- return rs_err_code (rs_conn_err_code (conn));
+ return rs_conn_err_pop (conn);
+ printf ("got response\n");
+ rs_dump_packet (resp);
+#endif
rs_conn_destroy (conn);
rs_context_destroy (h);
+ return 0;
}
int
main (int argc, char *argv[])
{
- exit (rsx_client ());
+ struct rs_error *err;
+
+ err = rsx_client (strsep (argv + 1, ":"), atoi (argv[1]));
+ if (!err)
+ return -1;
+ fprintf (stderr, "%s\n", rs_err_msg (err, 0));
+ return rs_err_code (err, 1);
}