1/* BEGIN LICENSE BLOCK
2 * Version: CMPL 1.1
3 *
4 * The contents of this file are subject to the Cisco-style Mozilla Public
5 * License Version 1.1 (the "License"); you may not use this file except
6 * in compliance with the License.  You may obtain a copy of the License
7 * at www.eclipse-clp.org/license.
8 *
9 * Software distributed under the License is distributed on an "AS IS"
10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11 * the License for the specific language governing rights and limitations
12 * under the License.
13 *
14 * The Original Code is  The ECLiPSe Constraint Logic Programming System.
15 * The Initial Developer of the Original Code is  Cisco Systems, Inc.
16 * Portions created by the Initial Developer are
17 * Copyright (C) 1994-2006 Cisco Systems, Inc.  All Rights Reserved.
18 *
19 * Contributor(s): Kees Schuerman, ECRC
20 *
21 * END LICENSE BLOCK */
22/**********************************************************************
23**      System: Parallel Distributed System
24**        File: nsrv_ping.c
25**      Author: Kees Schuerman
26**      SccsId: "@(#)nsrv_ping.c	1.3 5/15/95"
27** Description: Name Server Ping
28***********************************************************************/
29
30#include "machine.h"	/* architecture specific constant definitions */
31
32#include <sys/types.h>
33#include <sys/param.h>
34#include <signal.h>
35#include <stdlib.h>
36#include <stdio.h>
37#include <netdb.h>
38#include <errno.h>
39
40#include "pds.h"
41#include "nsrv.h"
42
43
44
45/**********************************************************************
46** Global Variables
47***********************************************************************/
48
49static char * hostname = (char *) 0;
50static unsigned port_number = 0;
51
52
53
54/**********************************************************************
55** A-Layer Primitives
56***********************************************************************/
57
58void
59amsg_warn(msg_warn,culprit)
60    amsg_warn_t msg_warn;
61    aport_id_t culprit;
62{
63}
64
65
66void
67amsg_error(msg_error,culprit)
68    amsg_error_t msg_error;
69    aport_id_t culprit;
70{
71}
72
73
74void
75amsg_panic(msg_panic,culprit)
76    amsg_panic_t msg_panic;
77    aport_id_t culprit;
78{
79}
80
81
82
83/**********************************************************************
84** B-Layer Primitives
85***********************************************************************/
86
87void
88bport_ack(port_id, port_primitive, ret)
89    bport_id_t port_id;
90    bport_primitive_t port_primitive;
91    bmsg_ret_t ret;
92{
93}
94
95
96void
97bport_notify(port_id,port_primitive)
98    bport_id_t port_id;
99    bport_primitive_t port_primitive;
100{
101}
102
103
104void
105bmem_ack(mem_id,mem_primitive,ret)
106    bmem_id_t mem_id;
107    bmem_primitive_t mem_primitive;
108    bmsg_ret_t ret;
109{
110}
111
112
113void
114bmem_notify(port_id,mem_primitive,mem_address,mem_data_size)
115    bport_id_t port_id;
116    bmem_primitive_t mem_primitive;
117    bmem_address_t mem_address;
118    bmem_size_t mem_data_size;
119{
120}
121
122
123void
124bmsg_warn(msg_warn,culprit)
125    bmsg_warn_t msg_warn;
126    bport_id_t culprit;
127{
128}
129
130
131void
132bmsg_error(msg_error,culprit)
133    bmsg_error_t msg_error;
134    bport_id_t culprit;
135{
136}
137
138
139void
140bmsg_panic(msg_panic,culprit)
141    bmsg_panic_t msg_panic;
142    bport_id_t culprit;
143{
144}
145
146
147void
148bproc_trigger(port)
149    bport_t * port;
150{
151    return;
152}
153
154
155
156/**********************************************************************
157** Local Primitives
158***********************************************************************/
159
160static void
161usage(program_name)
162    char *program_name;
163{
164    fprintf(stderr,
165            "\nUsage: %s [-p port_number] [-m machine_name] [-h]\n",
166            program_name);
167
168    fprintf(stderr, "       -p port_number: port number \n");
169    fprintf(stderr, "       -m machine_name: machine name \n");
170    fprintf(stderr, "       -h: help \n");
171    fprintf(stderr, "\n");
172    exit(0);
173}
174
175
176static void
177args(argc, argv)
178    int argc;
179    char *argv[];
180{
181    int i;
182
183    for (i = 1; i < argc; i++) {
184        if (argv[i][0] == '-')
185            switch (argv[i][1]) {
186                case 'h': /* help */
187                    usage(argv[0]); /* exit with usage message */
188                    break;
189                case 'm': /* machine name */
190		    if (++i >= argc) {
191                        fprintf(stderr,
192                                "\nmachine name parameter expected !\n");
193                        usage(argv[0]);
194                        break;
195                    }
196                    else
197                        hostname = argv[i];
198		    break;
199                case 'p': /* port number */
200                    if (++i >= argc) {
201                        fprintf(stderr,
202                                "\nport number parameter expected !\n");
203                        usage(argv[0]);
204                        break;
205                    }
206                    else {
207                        int number;
208                        number = atoi(argv[i]);
209                        if ((number < 1024) ||
210                            (number > 0xffff)) {
211                            fprintf(stderr,
212                                    "\n Invalid port number !\n");
213                            usage(argv[0]);
214                            break;
215                        }
216                        else
217                            port_number = number;
218                    }
219                    break;
220                default :
221                    usage(argv[0]); /* exit with usage message */
222                    break;
223        }
224    }
225    if (!hostname) {
226	hostname = (char *) malloc(MAXHOSTNAMELEN + 1);
227	if (!hostname) {
228	    fprintf(stderr, "Not enough memory !\n");
229	    exit(-1);
230	}
231	if (gethostname(hostname,MAXHOSTNAMELEN)) {
232	    perror("Implementation error: gethostname() ");
233	    exit(-1);
234	}
235    }
236}
237
238
239
240/**********************************************************************
241** Main
242***********************************************************************/
243
244int
245main(argc, argv)
246    int argc;
247    char *argv[];
248{
249    nsrv_ret_t nret;
250
251    /* get arguments */
252    args(argc, argv);
253
254    nret = nsrv_ping(hostname,&port_number);
255    switch (nret) {
256	case NSRV_OK :
257	    printf("Name server nsrv on host %s is listening on port %d !\n",
258	           hostname,
259	           port_number);
260	    break;
261	case NSRV_NOHOST :
262	    printf("No host %s !\n", hostname);
263	    break;
264	default :
265	    if (!port_number)
266	        printf("No name server nsrv on host %s listening on default ports !\n",
267	               hostname);
268	    else
269	        printf("No name server nsrv on host %s listening on port %d !\n",
270	               hostname,
271	               port_number);
272	    break;
273    }
274
275    return(0);
276}
277
278