From: Ronnie Sahlberg Date: Fri, 1 Jul 2011 23:33:26 +0000 (+1000) Subject: update the bcast example to broadcast on all available ipv4 interfaces X-Git-Tag: upstream/1.9.6^2~365 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=92e787feacb4134aa0641b18ea95b014e7006684;p=deb_libnfs.git update the bcast example to broadcast on all available ipv4 interfaces to detect nfs servers on the locally attached networks --- diff --git a/examples/nfsclient-bcast.c b/examples/nfsclient-bcast.c index c74c5b3..47fd28c 100644 --- a/examples/nfsclient-bcast.c +++ b/examples/nfsclient-bcast.c @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include "libnfs.h" #include "libnfs-raw.h" @@ -61,6 +63,8 @@ int main(int argc _U_, char *argv[] _U_) { struct rpc_context *rpc; struct pollfd pfd; + struct ifconf ifc; + int i, size; rpc = rpc_init_udp_context(); if (rpc == NULL) { @@ -73,24 +77,63 @@ int main(int argc _U_, char *argv[] _U_) exit(10); } - if (rpc_set_udp_destination(rpc, "10.1.1.255", 111, 1) < 0) { - printf("failed to set udp destination %s\n", rpc_get_error(rpc)); - exit(10); - } - if (rpc_pmap_callit_async(rpc, 100005, 2, 0, NULL, 0, pm_cb, NULL) < 0) { - printf("Failed to set up callit function\n"); - exit(10); - } - if (rpc_set_udp_destination(rpc, "10.9.2.255", 111, 1) < 0) { - printf("failed to set udp destination %s\n", rpc_get_error(rpc)); - exit(10); - } + /* get list of all interfaces */ + size = sizeof(struct ifreq); + ifc.ifc_buf = NULL; + ifc.ifc_len = size; - if (rpc_pmap_callit_async(rpc, 100005, 2, 0, NULL, 0, pm_cb, NULL) < 0) { - printf("Failed to set up callit function\n"); - exit(10); + while (ifc.ifc_len == size) { + size *= 2; + + free(ifc.ifc_buf); + ifc.ifc_len = size; + ifc.ifc_buf = malloc(size); + if (ioctl(rpc_get_fd(rpc), SIOCGIFCONF, (caddr_t)&ifc) < 0) { + printf("ioctl SIOCGIFCONF failed\n"); + exit(10); + } + } + + for (i=0; i