wire-test.c revision 174313
1123682Sache/* 2123682Sache * Copyright (c) 1997-2006 Erez Zadok 3123682Sache * Copyright (c) 1990 Jan-Simon Pendry 4123682Sache * Copyright (c) 1990 Imperial College of Science, Technology & Medicine 5174990Sache * Copyright (c) 1990 The Regents of the University of California. 6123682Sache * All rights reserved. 7123682Sache * 8123682Sache * This code is derived from software contributed to Berkeley by 9123682Sache * Jan-Simon Pendry at Imperial College, London. 10123682Sache * 11123682Sache * Redistribution and use in source and binary forms, with or without 12123682Sache * modification, are permitted provided that the following conditions 13123682Sache * are met: 14123682Sache * 1. Redistributions of source code must retain the above copyright 15123682Sache * notice, this list of conditions and the following disclaimer. 16123682Sache * 2. Redistributions in binary form must reproduce the above copyright 17123682Sache * notice, this list of conditions and the following disclaimer in the 18123682Sache * documentation and/or other materials provided with the distribution. 19123682Sache * 3. All advertising materials mentioning features or use of this software 20174990Sache * must display the following acknowledgment: 21123682Sache * This product includes software developed by the University of 22123682Sache * California, Berkeley and its contributors. 23123682Sache * 4. Neither the name of the University nor the names of its contributors 24123682Sache * may be used to endorse or promote products derived from this software 25123682Sache * without specific prior written permission. 26123682Sache * 27123682Sache * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28123682Sache * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29123682Sache * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30123682Sache * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31123682Sache * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32123682Sache * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33123682Sache * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34123682Sache * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35174990Sache * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36123682Sache * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37123682Sache * SUCH DAMAGE. 38123682Sache * 39123682Sache * 40123682Sache * File: am-utils/wire-test/wire-test.c 41123682Sache * 42123682Sache */ 43123682Sache 44123682Sache#ifdef HAVE_CONFIG_H 45174990Sache# include <config.h> 46123682Sache#endif /* HAVE_CONFIG_H */ 47123682Sache#include <am_defs.h> 48123682Sache 49123682Sache#define STRMAX 100 50123682Sache 51123682Sachechar hostname[MAXHOSTNAMELEN + 1]; 52123682Sache 53123682Sache 54123682Sacheint 55123682Sachemain(int argc, char **argv) 56123682Sache{ 57123682Sache char *networkName1, *networkNumber1; 58123682Sache struct in_addr myipaddr; /* (An) IP address of this host */ 59123682Sache char *testhost, *proto, *tmp_buf; 60123682Sache int nv, ret; 61123682Sache struct sockaddr_in *ip; 62123682Sache struct hostent *hp = 0; 63123682Sache 64123682Sache am_set_progname(argv[0]); 65123682Sache 66123682Sache if (gethostname(hostname, sizeof(hostname)) < 0) { 67123682Sache perror(argv[0]); 68123682Sache exit(1); 69123682Sache } 70123682Sache hostname[sizeof(hostname) - 1] = '\0'; 71123682Sache 72123682Sache /* get list of networks */ 73123682Sache getwire(&networkName1, &networkNumber1); 74123682Sache tmp_buf = print_wires(); 75123682Sache if (tmp_buf) { 76123682Sache fprintf(stderr, "%s", tmp_buf); 77123682Sache XFREE(tmp_buf); 78123682Sache } 79174990Sache 80123682Sache /* also print my IP address */ 81123682Sache amu_get_myaddress(&myipaddr, NULL); 82123682Sache fprintf(stderr, "My IP address is 0x%x.\n", (unsigned int) htonl(myipaddr.s_addr)); 83123682Sache 84123682Sache /* 85123682Sache * NFS VERSION/PROTOCOL TESTS: 86123682Sache * If argv[1] is specified perform nfs tests to that host, else use 87123682Sache * localhost. 88123682Sache */ 89123682Sache if (argc > 1) 90123682Sache testhost = argv[1]; 91123682Sache else 92123682Sache testhost = "localhost"; 93123682Sache hp = gethostbyname(testhost); 94123682Sache if (!hp) { 95123682Sache fprintf(stderr, "NFS vers/proto failed: no such hostname \"%s\"\n", testhost); 96123682Sache exit(1); 97123682Sache } 98123682Sache ip = (struct sockaddr_in *) xmalloc(sizeof(struct sockaddr_in)); 99123682Sache memset((voidp) ip, 0, sizeof(*ip)); 100123682Sache /* as per POSIX, sin_len need not be set (used internally by kernel) */ 101 ip->sin_family = AF_INET; 102 memmove((voidp) &ip->sin_addr, (voidp) hp->h_addr, sizeof(ip->sin_addr)); 103 ip->sin_port = htons(NFS_PORT); 104 105 xlog_level = 0; /* turn off debugging */ 106 fprintf(stderr, "NFS Version and protocol tests to host \"%s\"...\n", testhost); 107 proto = "udp"; 108 for (nv=2; nv<=3; ++nv) { 109 fprintf(stderr, "\ttesting vers=%d, proto=\"%s\" -> ", nv, proto); 110 ret = get_nfs_version(testhost, ip, nv, proto); 111 if (ret == 0) 112 fprintf(stderr, "failed!\n"); 113 else 114 fprintf(stderr, "found version %d.\n", ret); 115 } 116 117 proto = "tcp"; 118 for (nv=2; nv<=3; ++nv) { 119 fprintf(stderr, "\ttesting vers=%d, proto=\"%s\" -> ", nv, proto); 120 ret = get_nfs_version(testhost, ip, nv, proto); 121 if (ret == 0) 122 fprintf(stderr, "failed!\n"); 123 else 124 fprintf(stderr, "found version %d.\n", ret); 125 } 126 127 exit(0); 128 return 0; /* should never reach here */ 129} 130