X-Git-Url: https://git.piment-noir.org/?p=deb_libnfs.git;a=blobdiff_plain;f=examples%2Fportmap-client.c;h=cae90d7a72f5b4fab5904926e3b3edf08be5a085;hp=b479888523deec55abbc119e165f3465bc26d819;hb=2db42ce2fc89bc88050564037688888bbb8876e9;hpb=7fbedfdefd1df0bb6f67d7ee769918c0a09ed3be diff --git a/examples/portmap-client.c b/examples/portmap-client.c index b479888..cae90d7 100644 --- a/examples/portmap-client.c +++ b/examples/portmap-client.c @@ -34,10 +34,12 @@ #include #endif +#include #include #include #include -#include "libnfs-zdr.h" +#include +#include #include "libnfs.h" #include "libnfs-raw.h" #include "libnfs-raw-mount.h" @@ -107,7 +109,7 @@ void pmap3_dump_cb(struct rpc_context *rpc, int status, void *data, void *privat void pmap3_getaddr_cb(struct rpc_context *rpc, int status, void *data, void *private_data) { struct client *client = private_data; - struct pmap3_getaddr_result *gar = data; + struct pmap3_string_result *gar = data; if (status == RPC_STATUS_ERROR) { printf("PORTMAP3/GETADDR call failed with \"%s\"\n", (char *)data); @@ -124,6 +126,109 @@ void pmap3_getaddr_cb(struct rpc_context *rpc, int status, void *data, void *pri client->is_finished = 1; } +void pmap3_set_cb(struct rpc_context *rpc, int status, void *data, void *private_data) +{ + struct client *client = private_data; + uint32_t res = *(uint32_t *)data; + + if (status == RPC_STATUS_ERROR) { + printf("PORTMAP3/SET call failed with \"%s\"\n", (char *)data); + exit(10); + } + if (status != RPC_STATUS_SUCCESS) { + printf("PORTMAP3/SET call failed, status:%d\n", status); + exit(10); + } + + printf("PORTMAP3/SET:\n"); + printf(" Res:%d\n", res); + + client->is_finished = 1; +} + +void pmap3_unset_cb(struct rpc_context *rpc, int status, void *data, void *private_data) +{ + struct client *client = private_data; + uint32_t res = *(uint32_t *)data; + + if (status == RPC_STATUS_ERROR) { + printf("PORTMAP3/UNSET call failed with \"%s\"\n", (char *)data); + exit(10); + } + if (status != RPC_STATUS_SUCCESS) { + printf("PORTMAP3/UNSET call failed, status:%d\n", status); + exit(10); + } + + printf("PORTMAP3/UNSET:\n"); + printf(" Res:%d\n", res); + + 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; + struct sockaddr_storage *ss; + char host[256], port[6]; + 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"); + printf(" ---\n"); + ss = (struct sockaddr_storage *)&nb->buf.buf_val[0]; + getnameinfo((struct sockaddr *)ss, sizeof(struct sockaddr_storage), + &host[0], sizeof(host), &port[0], sizeof(port), + NI_NUMERICHOST|NI_NUMERICSERV); + switch (ss->ss_family) { + case AF_INET: + printf(" IPv4: %s:%s\n", &host[0], &port[0]); + break; + case AF_INET6: + printf(" IPv6: %s:%s\n", &host[0], &port[0]); + break; + } + client->is_finished = 1; +} + void pmap2_null_cb(struct rpc_context *rpc, int status, void *data, void *private_data) { struct client *client = private_data; @@ -222,12 +327,21 @@ int main(int argc _U_, char *argv[] _U_) int null2 = 0; int dump2 = 0; int null3 = 0; + int set3 = 0; + int unset3 = 0; int getaddr3 = 0; int dump3 = 0; + int gettime3 = 0; + int u2t3 = 0; int command_found = 0; + int set3prog, set3vers; + char *set3netid, *set3addr, *set3owner; + int unset3prog, unset3vers; + char *unset3netid, *unset3addr, *unset3owner; int getaddr3prog, getaddr3vers; - char *getaddr3netid; + char *getaddr3netid, *getaddr3addr, *getaddr3owner; + char *u2t3string; rpc = rpc_init_context(); if (rpc == NULL) { @@ -245,11 +359,28 @@ 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]; + getaddr3addr = argv[++i]; + getaddr3owner = argv[++i]; + command_found++; + } else if (!strcmp(argv[i], "set3")) { + set3 = 1; + set3prog = atoi(argv[++i]); + set3vers = atoi(argv[++i]); + set3netid = argv[++i]; + set3addr = argv[++i]; + set3owner = argv[++i]; command_found++; } else if (!strcmp(argv[i], "null3")) { null3 = 1; @@ -297,20 +428,62 @@ 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=""; + map.prog = getaddr3prog; + map.vers = getaddr3vers; + map.netid = getaddr3netid; + map.addr = getaddr3addr; + map.owner = getaddr3owner; 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); } + if (set3) { + struct pmap3_mapping map; + + map.prog = set3prog; + map.vers = set3vers; + map.netid = set3netid; + map.addr = set3addr; + map.owner = set3owner; + if (rpc_pmap3_set_async(rpc, &map, pmap3_set_cb, &client) != 0) { + printf("Failed to send SET3 request\n"); + exit(10); + } + wait_until_finished(rpc, &client); + } + if (unset3) { + struct pmap3_mapping map; + + map.prog = unset3prog; + map.vers = unset3vers; + map.netid = unset3netid; + map.addr = unset3addr; + map.owner = unset3owner; + if (rpc_pmap3_unset_async(rpc, &map, pmap3_unset_cb, &client) != 0) { + printf("Failed to send UNSET3 request\n"); + exit(10); + } + wait_until_finished(rpc, &client); + } rpc_destroy_context(rpc);