Add help to the trmon utility
[trust_router.git] / tid / example / tidc_main.c
index 8697ece..f1dfce5 100644 (file)
@@ -41,6 +41,8 @@
 #include <tr_debug.h>
 #include <tid_internal.h>
 #include <trust_router/tr_dh.h>
+#include <trust_router/tid.h>
+#include <tr_inet_util.h>
 
 static void tidc_resp_handler (TIDC_INSTANCE * tidc, 
                        TID_REQ *req,
@@ -50,6 +52,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 +66,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))) {
@@ -139,7 +147,19 @@ static error_t parse_option(int key, char *arg, struct argp_state *state)
       break;
 
     case 4:
-      arguments->port=strtol(arg, NULL, 10); /* optional */
+      arguments->port=tr_parse_port(arg); /* optional */
+      if (arguments->port < 0) {
+        switch(-(arguments->port)) {
+          case ERANGE:
+            printf("\nError parsing port (%s): port must be an integer in the range 1 - 65535\n\n", arg);
+            break;
+
+          default:
+            printf("\nError parsing port (%s): %s\n\n", arg, strerror(-arguments->port));
+            break;
+        }
+        argp_usage(state);
+      }
       break;
 
     default:
@@ -203,7 +223,8 @@ int main (int argc,
  
   /* Create a TID client instance & the client DH */
   tidc = tidc_create();
-  if (NULL == (tidc->client_dh = tr_create_dh_params(NULL, 0))) {
+  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;
   }