From: Ronnie Sahlberg Date: Sat, 2 Jul 2011 00:04:50 +0000 (+1000) Subject: collect nfs servers into a dedicated list and parse this list and print the results... X-Git-Tag: upstream/1.9.6^2~363 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=5e9910f0f0b2a1c71a08e910e7123efcadef46bf;p=deb_libnfs.git collect nfs servers into a dedicated list and parse this list and print the results once the response collection timeout has expired --- diff --git a/examples/nfsclient-bcast.c b/examples/nfsclient-bcast.c index 6f48618..2075f09 100644 --- a/examples/nfsclient-bcast.c +++ b/examples/nfsclient-bcast.c @@ -35,32 +35,74 @@ #include "libnfs-raw-portmap.h" #include "libnfs-private.h" -void pm_cb(struct rpc_context *rpc _U_, int status, void *data, void *private_data _U_) +struct nfs_server_list { + struct nfs_server_list *next; + char *addr; +}; + +struct nfs_list_data { + int status; + struct nfs_server_list *srvrs; +}; + +void free_nfs_srvr_list(struct nfs_server_list *srv) +{ + while (srv != NULL) { + struct nfs_server_list *next = srv->next; + + free(srv->addr); + free(srv); + srv = next; + } +} + +void pm_cb(struct rpc_context *rpc, int status, void *data, void *private_data _U_) { pmap_call_result *res = (pmap_call_result *)data; + struct nfs_list_data *srv_data = private_data; struct sockaddr *sin; char hostdd[16]; + struct nfs_server_list *srvr; if (status == RPC_STATUS_CANCEL) { return; } if (status != 0) { - printf("callback for CALLIT failed\n"); - exit(10); + srv_data->status = -1; + return; } sin = rpc_get_recv_sockaddr(rpc); if (sin == NULL) { - printf("failed to get sockaddr for received pdu\n"); - exit(10); + rpc_set_error(rpc, "failed to get sockaddr in CALLIT callback"); + srv_data->status = -1; + return; } if (getnameinfo(sin, sizeof(struct sockaddr_in), &hostdd[0], sizeof(hostdd), NULL, 0, NI_NUMERICHOST) < 0) { - printf("getnameinfo failed\n"); - exit(10); + rpc_set_error(rpc, "getnameinfo failed in CALLIT callback"); + srv_data->status = -1; + return; + } + + + srvr = malloc(sizeof(struct nfs_server_list)); + if (srvr == NULL) { + rpc_set_error(rpc, "Malloc failed when allocating server structure"); + srv_data->status = -1; + return; } - printf("NFS server at %s\n", hostdd); + srvr->addr = strdup(hostdd); + if (srvr->addr == NULL) { + rpc_set_error(rpc, "Strdup failed when allocating server structure"); + free(srvr); + srv_data->status = -1; + return; + } + + srvr->next = srv_data->srvrs; + srv_data->srvrs = srvr; } int main(int argc _U_, char *argv[] _U_) @@ -70,6 +112,8 @@ int main(int argc _U_, char *argv[] _U_) struct ifconf ifc; int i, size; struct timeval tv_start, tv_current; + struct nfs_list_data data = {0, NULL}; + struct nfs_server_list *srvr; rpc = rpc_init_udp_context(); if (rpc == NULL) { @@ -132,7 +176,7 @@ int main(int argc _U_, char *argv[] _U_) exit(10); } - if (rpc_pmap_callit_async(rpc, MOUNT_PROGRAM, 2, 0, NULL, 0, pm_cb, NULL) < 0) { + if (rpc_pmap_callit_async(rpc, MOUNT_PROGRAM, 2, 0, NULL, 0, pm_cb, &data) < 0) { printf("Failed to set up callit function\n"); exit(10); } @@ -165,6 +209,11 @@ int main(int argc _U_, char *argv[] _U_) } } + for (srvr=data.srvrs; srvr; srvr = srvr->next) { + printf("NFS SERVER @ %s\n", srvr->addr); + } + free_nfs_srvr_list(data.srvrs); + rpc_destroy_context(rpc); rpc=NULL; return 0;