X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=tid%2Fexample%2Ftidc_main.c;h=02cd1db58faf5fbb08c2fbbbd3834b785cbb702e;hb=3c5fb17459ff56d5e23cea059503f46a42150a1e;hp=92056c299fa315d9170ba188905ce8d99f7dff08;hpb=a1b1b820c2abe67aff1ac4e517360ee969adaed2;p=trust_router.git diff --git a/tid/example/tidc_main.c b/tid/example/tidc_main.c index 92056c2..02cd1db 100644 --- a/tid/example/tidc_main.c +++ b/tid/example/tidc_main.c @@ -41,6 +41,7 @@ #include #include #include +#include static void tidc_resp_handler (TIDC_INSTANCE * tidc, TID_REQ *req, @@ -50,6 +51,7 @@ static void tidc_resp_handler (TIDC_INSTANCE * tidc, int c_keylen = 0; unsigned char *c_keybuf = NULL; int i; + struct timeval tv; printf ("Response received! Realm = %s, Community = %s.\n", resp->realm->buf, resp->comm->buf); @@ -63,7 +65,12 @@ static void tidc_resp_handler (TIDC_INSTANCE * tidc, fprintf(stderr, "tidc_resp_handler: Response does not contain server info.\n"); return; } - + if (tid_srvr_get_key_expiration(tid_resp_get_server(resp, 0), &tv)) + printf("Error reading key expiration\n"); + else + printf("Key expiration: %s", ctime(&tv.tv_sec)); + + if (0 > (c_keylen = tr_compute_dh_key(&c_keybuf, resp->servers->aaa_server_dh->pub_key, req->tidc_dh))) { @@ -83,19 +90,25 @@ static void tidc_resp_handler (TIDC_INSTANCE * tidc, } +static void print_version_info(void) +{ + printf("Moonshot TID Client %s\n\n", PACKAGE_VERSION); +} + /* command-line option setup */ /* argp global parameters */ const char *argp_program_bug_address=PACKAGE_BUGREPORT; /* bug reporting address */ /* doc strings */ -static const char doc[]=PACKAGE_NAME " - TID Client"; +static const char doc[]=PACKAGE_NAME " - Moonshot TID Client " PACKAGE_VERSION; static const char arg_doc[]=" []"; /* string describing arguments, if any */ /* define the options here. Fields are: * { long-name, short-name, variable name, options, help description } */ static const struct argp_option cmdline_options[] = { - { NULL } + { "version", 'v', NULL, 0, "Print version information and exit"}, + { NULL } }; /* structure for communicating with option parser */ @@ -149,6 +162,10 @@ static error_t parse_option(int key, char *arg, struct argp_state *state) } break; + case 'v': + print_version_info(); + exit(0); + default: return ARGP_ERR_UNKNOWN; } @@ -179,6 +196,8 @@ int main (int argc, argp_parse(&argp, argc, argv, 0, 0, &opts); /* TBD -- validity checking, dealing with quotes, etc. */ + print_version_info(); + /* Use standalone logging */ tr_log_open(); @@ -190,8 +209,9 @@ int main (int argc, printf("TIDC Client:\nServer = %s, rp_realm = %s, target_realm = %s, community = %s, port = %i\n", opts.server, opts.rp_realm, opts.target_realm, opts.community, opts.port); /* Create a TID client instance & the client DH */ - tidc = tidc_create(NULL); - if (NULL == (tidc->client_dh = tr_create_dh_params(NULL, 0))) { + tidc = tidc_create(); + tidc_set_dh(tidc, tr_create_dh_params(NULL, 0)); + if (tidc_get_dh(tidc) == NULL) { printf("Error creating client DH params.\n"); return 1; } @@ -212,7 +232,7 @@ int main (int argc, } /* Clean-up the TID client instance, and exit */ - tidc_free(tidc); + tidc_destroy(tidc); return 0; }