1 /* $NetBSD: wire-test.c,v 1.1.1.3 2015/01/17 16:34:19 christos Exp $ */
2
3 /*
4 * Copyright (c) 1997-2014 Erez Zadok
5 * Copyright (c) 1990 Jan-Simon Pendry
6 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
7 * Copyright (c) 1990 The Regents of the University of California.
8 * All rights reserved.
9 *
10 * This code is derived from software contributed to Berkeley by
11 * Jan-Simon Pendry at Imperial College, London.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 *
38 * File: am-utils/wire-test/wire-test.c
39 *
40 */
41
42 #ifdef HAVE_CONFIG_H
43 # include <config.h>
44 #endif /* HAVE_CONFIG_H */
45 #include <am_defs.h>
46
47 #define STRMAX 100
48
49 char hostname[MAXHOSTNAMELEN + 1];
50
51
52 int
main(int argc,char ** argv)53 main(int argc, char **argv)
54 {
55 char *networkName1, *networkNumber1;
56 struct in_addr myipaddr; /* (An) IP address of this host */
57 char *testhost, *proto, *tmp_buf;
58 int nv, ret;
59 struct sockaddr_in *ip;
60 struct hostent *hp = NULL;
61
62 am_set_progname(argv[0]);
63
64 if (gethostname(hostname, sizeof(hostname)) < 0) {
65 perror(argv[0]);
66 exit(1);
67 }
68 hostname[sizeof(hostname) - 1] = '\0';
69
70 /* get list of networks */
71 getwire(&networkName1, &networkNumber1);
72 tmp_buf = print_wires();
73 if (tmp_buf) {
74 fprintf(stderr, "%s", tmp_buf);
75 XFREE(tmp_buf);
76 }
77
78 /* also print my IP address */
79 amu_get_myaddress(&myipaddr, NULL);
80 fprintf(stderr, "My IP address is 0x%x.\n", (unsigned int) htonl(myipaddr.s_addr));
81
82 /*
83 * NFS VERSION/PROTOCOL TESTS:
84 * If argv[1] is specified perform nfs tests to that host, else use
85 * localhost.
86 */
87 if (argc > 1)
88 testhost = argv[1];
89 else
90 testhost = "localhost";
91 hp = gethostbyname(testhost);
92 if (!hp) {
93 fprintf(stderr, "NFS vers/proto failed: no such hostname \"%s\"\n", testhost);
94 exit(1);
95 }
96 ip = (struct sockaddr_in *) xmalloc(sizeof(struct sockaddr_in));
97 memset((voidp) ip, 0, sizeof(*ip));
98 /* as per POSIX, sin_len need not be set (used internally by kernel) */
99 ip->sin_family = AF_INET;
100 memmove((voidp) &ip->sin_addr, (voidp) hp->h_addr, sizeof(ip->sin_addr));
101 ip->sin_port = htons(NFS_PORT);
102
103 fprintf(stderr, "NFS Version and protocol tests to host \"%s\"...\n", testhost);
104 proto = "udp";
105 for (nv=2; nv<=3; ++nv) {
106 fprintf(stderr, "\ttesting vers=%d, proto=\"%s\" -> ", nv, proto);
107 ret = get_nfs_version(testhost, ip, nv, proto, 0);
108 if (ret == 0)
109 fprintf(stderr, "failed!\n");
110 else
111 fprintf(stderr, "found version %d.\n", ret);
112 }
113
114 proto = "tcp";
115 for (nv=2; nv<=3; ++nv) {
116 fprintf(stderr, "\ttesting vers=%d, proto=\"%s\" -> ", nv, proto);
117 ret = get_nfs_version(testhost, ip, nv, proto, 0);
118 if (ret == 0)
119 fprintf(stderr, "failed!\n");
120 else
121 fprintf(stderr, "found version %d.\n", ret);
122 }
123
124 exit(0);
125 return 0; /* should never reach here */
126 }
127