PORTMAP: Rename pmap3_getaddr_result to pmap3_string_result
[deb_libnfs.git] / examples / portmap-client.c
index d3866e665ed67a009d55c6044b8b6ae9363987c0..487cbed043cbc13f452bfa4e43d76b0bc3f533f1 100644 (file)
@@ -37,6 +37,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include "libnfs-zdr.h"
 #include "libnfs.h"
 #include "libnfs-raw.h"
@@ -104,6 +105,74 @@ void pmap3_dump_cb(struct rpc_context *rpc, int status, void *data, void *privat
        client->is_finished = 1;
 }
 
+void pmap3_getaddr_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
+{
+       struct client *client = private_data;
+       struct pmap3_string_result *gar = data;
+
+       if (status == RPC_STATUS_ERROR) {
+               printf("PORTMAP3/GETADDR call failed with \"%s\"\n", (char *)data);
+               exit(10);
+       }
+       if (status != RPC_STATUS_SUCCESS) {
+               printf("PORTMAP3/GETADDR call failed, status:%d\n", status);
+               exit(10);
+       }
+
+       printf("PORTMAP3/GETADDR:\n");
+       printf("        Addr:%s\n", gar->addr);
+
+       client->is_finished = 1;
+}
+
+void pmap3_gettime_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
+{
+       struct client *client = private_data;
+       time_t t = *(uint32_t *)data;
+
+       if (status == RPC_STATUS_ERROR) {
+               printf("PORTMAP3/GETTIME call failed with \"%s\"\n", (char *)data);
+               exit(10);
+       }
+       if (status != RPC_STATUS_SUCCESS) {
+               printf("PORTMAP3/GETTIME call failed, status:%d\n", status);
+               exit(10);
+       }
+
+       printf("PORTMAP3/GETTIME:\n");
+       printf("        Time:%d %s\n", (int)t, ctime(&t));
+
+       client->is_finished = 1;
+}
+
+void pmap3_uaddr2taddr_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
+{
+       struct client *client = private_data;
+       struct pmap3_netbuf *nb = data;
+       int i;
+
+       if (status == RPC_STATUS_ERROR) {
+               printf("PORTMAP3/UADDR2TADDR call failed with \"%s\"\n", (char *)data);
+               exit(10);
+       }
+       if (status != RPC_STATUS_SUCCESS) {
+               printf("PORTMAP3/UADDR2TADDR call failed, status:%d\n", status);
+               exit(10);
+       }
+
+       printf("PORTMAP3/UADDR2TADDR:\n");
+       printf("        MaxLen:%d\n", nb->maxlen);
+       printf("        ");
+       for (i = 0; i < nb->maxlen; i++) {
+               printf("%02x ", nb->buf.buf_val[i]);
+               if (i %16 == 15) {
+                       printf("\n        ");
+               }
+       }
+       printf("\n");
+       client->is_finished = 1;
+}
+
 void pmap2_null_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
 {
        struct client *client = private_data;
@@ -202,9 +271,16 @@ int main(int argc _U_, char *argv[] _U_)
        int null2 = 0;
        int dump2 = 0;
        int null3 = 0;
+       int getaddr3 = 0;
        int dump3 = 0;
+       int gettime3 = 0;
+       int u2t3 = 0;
        int command_found = 0;
 
+       int getaddr3prog, getaddr3vers;
+       char *getaddr3netid;
+       char *u2t3string;
+
        rpc = rpc_init_context();
        if (rpc == NULL) {
                printf("failed to init context\n");
@@ -221,6 +297,19 @@ int main(int argc _U_, char *argv[] _U_)
                } else if (!strcmp(argv[i], "dump3")) {
                        dump3 = 1;
                        command_found++;
+               } else if (!strcmp(argv[i], "gettime3")) {
+                       gettime3 = 1;
+                       command_found++;
+               } else if (!strcmp(argv[i], "u2t3")) {
+                       u2t3 = 1;
+                       u2t3string = argv[++i];
+                       command_found++;
+               } else if (!strcmp(argv[i], "getaddr3")) {
+                       getaddr3 = 1;
+                       getaddr3prog = atoi(argv[++i]);
+                       getaddr3vers = atoi(argv[++i]);
+                       getaddr3netid = argv[++i];
+                       command_found++;
                } else if (!strcmp(argv[i], "null3")) {
                        null3 = 1;
                        command_found++;
@@ -267,6 +356,34 @@ int main(int argc _U_, char *argv[] _U_)
                }
                wait_until_finished(rpc, &client);
        }
+       if (gettime3) {
+               if (rpc_pmap3_gettime_async(rpc, pmap3_gettime_cb, &client) != 0) {
+                       printf("Failed to send GETTIME3 request\n");
+                       exit(10);
+               }
+               wait_until_finished(rpc, &client);
+       }
+       if (u2t3) {
+               if (rpc_pmap3_uaddr2taddr_async(rpc, u2t3string, pmap3_uaddr2taddr_cb, &client) != 0) {
+                       printf("Failed to send UADDR2TADDR3 request\n");
+                       exit(10);
+               }
+               wait_until_finished(rpc, &client);
+       }
+       if (getaddr3) {
+               struct pmap3_mapping map;
+
+               map.prog=getaddr3prog;
+               map.vers=getaddr3vers;
+               map.netid=getaddr3netid;
+               map.addr="";
+               map.owner="";
+               if (rpc_pmap3_getaddr_async(rpc, &map, pmap3_getaddr_cb, &client) != 0) {
+                       printf("Failed to send GETADDR3 request\n");
+                       exit(10);
+               }
+               wait_until_finished(rpc, &client);
+       }
 
        
        rpc_destroy_context(rpc);