wire-test.c revision 42633
138494Sobrien/*
238494Sobrien * Copyright (c) 1997-1998 Erez Zadok
338494Sobrien * Copyright (c) 1990 Jan-Simon Pendry
438494Sobrien * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
538494Sobrien * Copyright (c) 1990 The Regents of the University of California.
638494Sobrien * All rights reserved.
738494Sobrien *
838494Sobrien * This code is derived from software contributed to Berkeley by
938494Sobrien * Jan-Simon Pendry at Imperial College, London.
1038494Sobrien *
1138494Sobrien * Redistribution and use in source and binary forms, with or without
1238494Sobrien * modification, are permitted provided that the following conditions
1338494Sobrien * are met:
1438494Sobrien * 1. Redistributions of source code must retain the above copyright
1538494Sobrien *    notice, this list of conditions and the following disclaimer.
1638494Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1738494Sobrien *    notice, this list of conditions and the following disclaimer in the
1838494Sobrien *    documentation and/or other materials provided with the distribution.
1938494Sobrien * 3. All advertising materials mentioning features or use of this software
2042633Sobrien *    must display the following acknowledgment:
2138494Sobrien *      This product includes software developed by the University of
2238494Sobrien *      California, Berkeley and its contributors.
2338494Sobrien * 4. Neither the name of the University nor the names of its contributors
2438494Sobrien *    may be used to endorse or promote products derived from this software
2538494Sobrien *    without specific prior written permission.
2638494Sobrien *
2738494Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2838494Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2938494Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3038494Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3138494Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3238494Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3338494Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3438494Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3538494Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3638494Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3738494Sobrien * SUCH DAMAGE.
3838494Sobrien *
3938494Sobrien *      %W% (Berkeley) %G%
4038494Sobrien *
4142633Sobrien * $Id: wire-test.c,v 1.3 1998/11/14 03:13:33 obrien Exp $
4238494Sobrien *
4338494Sobrien */
4438494Sobrien
4538494Sobrien#ifdef HAVE_CONFIG_H
4638494Sobrien# include <config.h>
4738494Sobrien#endif /* HAVE_CONFIG_H */
4838494Sobrien#include <am_defs.h>
4938494Sobrien
5038494Sobrien#define STRMAX	100
5138494Sobrien
5238494Sobrien/* dummy variables */
5342633Sobrien#if 0
5442633Sobrienchar *progname;
5538494Sobrienpid_t mypid;
5638494Sobrienserv_state amd_state;
5742633Sobrienint foreground, orig_umask;
5842633Sobrienint debug_flags;
5942633Sobrien#endif
6038494Sobrien
6142633Sobrienchar hostname[MAXHOSTNAMELEN + 1];
6242633Sobrien
6342633Sobrien
6438494Sobrienint
6538494Sobrienmain(int argc, char **argv)
6638494Sobrien{
6738494Sobrien  char *networkName1, *networkNumber1;
6838494Sobrien  struct in_addr myipaddr;	/* (An) IP address of this host */
6938494Sobrien  char *testhost, *proto, *tmp_buf;
7038494Sobrien  int nv, ret;
7138494Sobrien  struct sockaddr_in *ip;
7238494Sobrien  struct hostent *hp = 0;
7338494Sobrien
7442633Sobrien  am_set_progname(argv[0]);
7542633Sobrien#if 0
7638494Sobrien  mypid = getpid();
7738494Sobrien  orig_umask = umask(0);
7842633Sobrien#endif
7938494Sobrien
8041145Sobrien  if (gethostname(hostname, sizeof(hostname)) < 0) {
8138494Sobrien    perror(argv[0]);
8238494Sobrien    exit(1);
8338494Sobrien  }
8438500Sobrien  hostname[sizeof(hostname) - 1] = '\0';
8538494Sobrien
8638494Sobrien  /* get list of networks */
8738494Sobrien  getwire(&networkName1, &networkNumber1);
8838494Sobrien  tmp_buf = print_wires();
8938494Sobrien  if (tmp_buf) {
9038494Sobrien    fprintf(stderr, "%s", tmp_buf);
9138494Sobrien    XFREE(tmp_buf);
9238494Sobrien  }
9338494Sobrien
9438494Sobrien  /* also print my IP address */
9538494Sobrien  amu_get_myaddress(&myipaddr);
9638494Sobrien  fprintf(stderr, "My IP address is 0x%x.\n", (unsigned int) htonl(myipaddr.s_addr));
9738494Sobrien
9838494Sobrien  /*
9938494Sobrien   * NFS VERSION/PROTOCOL TESTS:
10038494Sobrien   * If argv[1] is specified  perform nfs tests to that host, else use
10138494Sobrien   * localhost.
10238494Sobrien   */
10338494Sobrien  if (argc > 1)
10438494Sobrien    testhost = argv[1];
10538494Sobrien  else
10638494Sobrien    testhost = "localhost";
10738494Sobrien  hp = gethostbyname(testhost);
10838494Sobrien  if (!hp) {
10938494Sobrien    fprintf(stderr, "NFS vers/proto failed: no such hostname \"%s\"\n", testhost);
11038494Sobrien    exit(1);
11138494Sobrien  }
11238494Sobrien  ip = (struct sockaddr_in *) xmalloc(sizeof(struct sockaddr_in));
11338494Sobrien  memset((voidp) ip, 0, sizeof(*ip));
11438494Sobrien  ip->sin_family = AF_INET;
11538494Sobrien  memmove((voidp) &ip->sin_addr, (voidp) hp->h_addr, sizeof(ip->sin_addr));
11638494Sobrien  ip->sin_port = htons(NFS_PORT);
11738494Sobrien
11838494Sobrien  xlog_level = 0;		/* turn off debugging */
11938494Sobrien  fprintf(stderr, "NFS Version and protocol tests to host \"%s\"...\n", testhost);
12038494Sobrien  proto = "udp";
12138494Sobrien  for (nv=2; nv<=3; ++nv) {
12238494Sobrien    fprintf(stderr, "\ttesting vers=%d, proto=\"%s\" -> ", nv, proto);
12338494Sobrien    ret = get_nfs_version(testhost, ip, nv, proto);
12438494Sobrien    if (ret == 0)
12538494Sobrien      fprintf(stderr, "failed!\n");
12638494Sobrien    else
12738494Sobrien      fprintf(stderr, "found version %d.\n", ret);
12838494Sobrien  }
12938494Sobrien
13038494Sobrien  proto = "tcp";
13138494Sobrien  for (nv=2; nv<=3; ++nv) {
13238494Sobrien    fprintf(stderr, "\ttesting vers=%d, proto=\"%s\" -> ", nv, proto);
13338494Sobrien    ret = get_nfs_version(testhost, ip, nv, proto);
13438494Sobrien    if (ret == 0)
13538494Sobrien      fprintf(stderr, "failed!\n");
13638494Sobrien    else
13738494Sobrien      fprintf(stderr, "found version %d.\n", ret);
13838494Sobrien  }
13938494Sobrien
14038494Sobrien  exit(0);
14138494Sobrien  return 0; /* should never reach here */
14238494Sobrien}
143