c74c5b37764b8e12a9aa002ee714aadf24deb17f
2 Copyright (C) by Ronnie Sahlberg <ronniesahlberg@gmail.com> 2011
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>.
18 /* Example program using the lowlevel raw broadcast interface.
27 #include <sys/socket.h>
30 #include "libnfs-raw.h"
31 #include "libnfs-raw-mount.h"
32 #include "libnfs-raw-portmap.h"
33 #include "libnfs-private.h"
35 void pm_cb(struct rpc_context
*rpc _U_
, int status
, void *data
, void *private_data _U_
)
37 pmap_call_result
*res
= (pmap_call_result
*)data
;
42 printf("callback for CALLIT failed\n");
46 sin
= rpc_get_recv_sockaddr(rpc
);
48 printf("failed to get sockaddr for received pdu\n");
52 if (getnameinfo(sin
, sizeof(struct sockaddr_in
), &hostdd
[0], sizeof(hostdd
), NULL
, 0, NI_NUMERICHOST
) < 0) {
53 printf("getnameinfo failed\n");
57 printf("NFS server at %s\n", hostdd
);
60 int main(int argc _U_
, char *argv
[] _U_
)
62 struct rpc_context
*rpc
;
65 rpc
= rpc_init_udp_context();
67 printf("failed to init context\n");
71 if (rpc_bind_udp(rpc
, "0.0.0.0", 0) < 0) {
72 printf("failed to bind to udp %s\n", rpc_get_error(rpc
));
76 if (rpc_set_udp_destination(rpc
, "10.1.1.255", 111, 1) < 0) {
77 printf("failed to set udp destination %s\n", rpc_get_error(rpc
));
81 if (rpc_pmap_callit_async(rpc
, 100005, 2, 0, NULL
, 0, pm_cb
, NULL
) < 0) {
82 printf("Failed to set up callit function\n");
85 if (rpc_set_udp_destination(rpc
, "10.9.2.255", 111, 1) < 0) {
86 printf("failed to set udp destination %s\n", rpc_get_error(rpc
));
90 if (rpc_pmap_callit_async(rpc
, 100005, 2, 0, NULL
, 0, pm_cb
, NULL
) < 0) {
91 printf("Failed to set up callit function\n");
98 pfd
.fd
= rpc_get_fd(rpc
);
99 pfd
.events
= rpc_which_events(rpc
);
101 if (poll(&pfd
, 1, -1) < 0) {
102 printf("Poll failed");
105 if (rpc_service(rpc
, pfd
.revents
) < 0) {
106 printf("rpc_service failed with %s\n", rpc_get_error(rpc
));
111 rpc_destroy_context(rpc
);
113 printf("nfsclient finished\n");