diff options
author | Linus Nordberg <linus@nordu.net> | 2010-09-28 22:27:04 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2010-09-28 22:27:04 +0200 |
commit | e981fbcf3909fbaba462c7b578f29fa67b3bc74b (patch) | |
tree | f67203b602b71600020e95ff6805d6aa71331237 /lib/examples | |
parent | 07fa3839c8bddd1ad91f86243dd582c0359ba3e1 (diff) |
WIP.
Diffstat (limited to 'lib/examples')
-rw-r--r-- | lib/examples/Makefile | 4 | ||||
-rw-r--r-- | lib/examples/client.c | 46 |
2 files changed, 34 insertions, 16 deletions
diff --git a/lib/examples/Makefile b/lib/examples/Makefile index e07a32b..ceb97f1 100644 --- a/lib/examples/Makefile +++ b/lib/examples/Makefile @@ -1,12 +1,12 @@ CFLAGS = -Wall -g -all: blocking.o +all: client blocking.o: blocking.c blocking.h ../libradsec-base.h ../libradsec.h $(CC) $(CFLAGS) -c -I .. $^ client: client.c ../libradsec.a ../libradsec.h ../libradsec-impl.h - $(CC) $(CFLAGS) -o $@ -L /usr/lib/freeradius -lfreeradius-radius $^ + $(CC) $(CFLAGS) -o $@ $< -L /usr/lib/freeradius -lfreeradius-radius -L .. -lradsec clean: -rm *.o 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); } |