cmds.c revision 1.22 1 1.22 cbiere /* $NetBSD: cmds.c,v 1.22 2007/01/27 00:37:56 cbiere Exp $ */
2 1.6 mrg
3 1.3 cgd /*-
4 1.3 cgd * Copyright (c) 1985, 1993 The Regents of the University of California.
5 1.1 cgd * All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.14 agc * 3. Neither the name of the University nor the names of its contributors
16 1.1 cgd * may be used to endorse or promote products derived from this software
17 1.1 cgd * without specific prior written permission.
18 1.1 cgd *
19 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 cgd * SUCH DAMAGE.
30 1.1 cgd */
31 1.1 cgd
32 1.7 lukem #include <sys/cdefs.h>
33 1.1 cgd #ifndef lint
34 1.7 lukem #if 0
35 1.6 mrg static char sccsid[] = "@(#)cmds.c 8.2 (Berkeley) 3/26/95";
36 1.7 lukem #else
37 1.22 cbiere __RCSID("$NetBSD: cmds.c,v 1.22 2007/01/27 00:37:56 cbiere Exp $");
38 1.7 lukem #endif
39 1.1 cgd #endif /* not lint */
40 1.1 cgd
41 1.1 cgd #include "timedc.h"
42 1.3 cgd #include <sys/file.h>
43 1.3 cgd
44 1.1 cgd #include <netinet/in_systm.h>
45 1.1 cgd #include <netinet/ip.h>
46 1.1 cgd #include <netinet/ip_icmp.h>
47 1.3 cgd
48 1.20 cbiere #include <rpc/rpc.h>
49 1.20 cbiere
50 1.3 cgd #include <stdlib.h>
51 1.8 lukem #include <string.h>
52 1.3 cgd #include <unistd.h>
53 1.19 christos #include <err.h>
54 1.3 cgd
55 1.1 cgd #define TSPTYPES
56 1.1 cgd #include <protocols/timed.h>
57 1.3 cgd
58 1.3 cgd #define SECHR (60*60)
59 1.3 cgd #define SECDAY (24*SECHR)
60 1.3 cgd
61 1.3 cgd # define DATE_PROTO "udp"
62 1.3 cgd # define DATE_PORT "time"
63 1.3 cgd
64 1.1 cgd
65 1.1 cgd int sock;
66 1.1 cgd int sock_raw;
67 1.9 mrg char myname[MAXHOSTNAMELEN + 1];
68 1.3 cgd struct hostent *hp;
69 1.1 cgd struct sockaddr_in server;
70 1.21 cbiere static struct sockaddr_in dayaddr;
71 1.1 cgd extern int measure_delta;
72 1.3 cgd
73 1.3 cgd void bytenetorder(struct tsp *);
74 1.3 cgd void bytehostorder(struct tsp *);
75 1.20 cbiere void set_tsp_name(struct tsp *, const char *);
76 1.20 cbiere void get_tsp_name(const struct tsp *, char *, size_t);
77 1.3 cgd
78 1.3 cgd
79 1.21 cbiere #define BU 2208988800UL /* seconds before UNIX epoch */
80 1.3 cgd
81 1.3 cgd
82 1.3 cgd /* compute the difference between our date and another machine
83 1.3 cgd */
84 1.3 cgd static int /* difference in days from our time */
85 1.3 cgd daydiff(char *hostname)
86 1.3 cgd {
87 1.3 cgd int i;
88 1.3 cgd int trials;
89 1.12 mycroft int tout;
90 1.12 mycroft struct timeval now;
91 1.12 mycroft struct pollfd set[1];
92 1.21 cbiere struct sockaddr_in from;
93 1.17 mrg socklen_t fromlen;
94 1.21 cbiere uint32_t sec;
95 1.3 cgd
96 1.3 cgd
97 1.3 cgd /* wait 2 seconds between 10 tries */
98 1.12 mycroft tout = 2000;
99 1.12 mycroft set[0].fd = sock;
100 1.12 mycroft set[0].events = POLLIN;
101 1.3 cgd for (trials = 0; trials < 10; trials++) {
102 1.21 cbiere ssize_t ret;
103 1.21 cbiere
104 1.3 cgd /* ask for the time */
105 1.3 cgd sec = 0;
106 1.21 cbiere ret = sendto(sock, &sec, sizeof(sec), 0,
107 1.21 cbiere (struct sockaddr*)&dayaddr, sizeof(dayaddr));
108 1.21 cbiere if (ret < sizeof(sec)) {
109 1.21 cbiere if (ret < 0)
110 1.21 cbiere warn("sendto(sock)");
111 1.21 cbiere else
112 1.21 cbiere warnx("sendto(sock): incomplete");
113 1.3 cgd return 0;
114 1.3 cgd }
115 1.3 cgd
116 1.3 cgd for (;;) {
117 1.12 mycroft i = poll(set, 1, tout);
118 1.3 cgd if (i < 0) {
119 1.3 cgd if (errno == EINTR)
120 1.3 cgd continue;
121 1.19 christos warn("poll(date read)");
122 1.3 cgd return 0;
123 1.3 cgd }
124 1.3 cgd if (0 == i)
125 1.3 cgd break;
126 1.3 cgd
127 1.3 cgd fromlen = sizeof(from);
128 1.21 cbiere ret = recvfrom(sock, &sec, sizeof(sec), 0,
129 1.21 cbiere (struct sockaddr*)&from, &fromlen);
130 1.21 cbiere if (ret >= 0 && (
131 1.21 cbiere from.sin_family != dayaddr.sin_family ||
132 1.21 cbiere from.sin_addr.s_addr != dayaddr.sin_addr.s_addr ||
133 1.21 cbiere from.sin_port != dayaddr.sin_port))
134 1.21 cbiere continue;
135 1.21 cbiere
136 1.21 cbiere if (ret < sizeof(sec)) {
137 1.21 cbiere if (ret < 0)
138 1.21 cbiere warn("recvfrom(date read)");
139 1.21 cbiere else
140 1.21 cbiere warnx("recvfrom(date read): incomplete");
141 1.3 cgd return 0;
142 1.3 cgd }
143 1.3 cgd
144 1.3 cgd sec = ntohl(sec);
145 1.3 cgd if (sec < BU) {
146 1.19 christos warnx("%s says it is before 1970: %lu",
147 1.21 cbiere hostname, (unsigned long)sec);
148 1.3 cgd return 0;
149 1.3 cgd }
150 1.3 cgd sec -= BU;
151 1.1 cgd
152 1.3 cgd (void)gettimeofday(&now, (struct timezone*)0);
153 1.3 cgd return (sec - now.tv_sec);
154 1.3 cgd }
155 1.3 cgd }
156 1.3 cgd
157 1.3 cgd /* if we get here, we tried too many times */
158 1.19 christos warnx("%s will not tell us the date", hostname);
159 1.3 cgd return 0;
160 1.3 cgd }
161 1.3 cgd
162 1.3 cgd
163 1.1 cgd /*
164 1.3 cgd * Clockdiff computes the difference between the time of the machine on
165 1.1 cgd * which it is called and the time of the machines given as argument.
166 1.1 cgd * The time differences measured by clockdiff are obtained using a sequence
167 1.1 cgd * of ICMP TSTAMP messages which are returned to the sender by the IP module
168 1.1 cgd * in the remote machine.
169 1.3 cgd * In order to compare clocks of machines in different time zones, the time
170 1.3 cgd * is transmitted (as a 32-bit value) in milliseconds since midnight UT.
171 1.1 cgd * If a hosts uses a different time format, it should set the high order
172 1.1 cgd * bit of the 32-bit quantity it transmits.
173 1.1 cgd * However, VMS apparently transmits the time in milliseconds since midnight
174 1.3 cgd * local time (rather than GMT) without setting the high order bit.
175 1.3 cgd * Furthermore, it does not understand daylight-saving time. This makes
176 1.1 cgd * clockdiff behaving inconsistently with hosts running VMS.
177 1.1 cgd *
178 1.3 cgd * In order to reduce the sensitivity to the variance of message transmission
179 1.3 cgd * time, clockdiff sends a sequence of messages. Yet, measures between
180 1.3 cgd * two `distant' hosts can be affected by a small error. The error can,
181 1.3 cgd * however, be reduced by increasing the number of messages sent in each
182 1.3 cgd * measurement.
183 1.1 cgd */
184 1.3 cgd void
185 1.11 wiz clockdiff(int argc, char *argv[])
186 1.1 cgd {
187 1.1 cgd int measure_status;
188 1.3 cgd extern int measure(u_long, u_long, char *, struct sockaddr_in*, int);
189 1.16 perry int avg_cnt;
190 1.16 perry long avg;
191 1.3 cgd struct servent *sp;
192 1.1 cgd
193 1.3 cgd if (argc < 2) {
194 1.1 cgd printf("Usage: clockdiff host ... \n");
195 1.1 cgd return;
196 1.1 cgd }
197 1.1 cgd
198 1.3 cgd (void)gethostname(myname,sizeof(myname));
199 1.9 mrg myname[sizeof(myname) - 1] = '\0';
200 1.3 cgd
201 1.3 cgd /* get the address for the date ready */
202 1.3 cgd sp = getservbyname(DATE_PORT, DATE_PROTO);
203 1.3 cgd if (!sp) {
204 1.19 christos warnx("%s/%s is an unknown service", DATE_PORT, DATE_PROTO);
205 1.3 cgd dayaddr.sin_port = 0;
206 1.3 cgd } else {
207 1.3 cgd dayaddr.sin_port = sp->s_port;
208 1.3 cgd }
209 1.1 cgd
210 1.1 cgd while (argc > 1) {
211 1.1 cgd argc--; argv++;
212 1.1 cgd hp = gethostbyname(*argv);
213 1.1 cgd if (hp == NULL) {
214 1.19 christos warnx("Error resolving %s (%s)", *argv,
215 1.19 christos hstrerror(h_errno));
216 1.1 cgd continue;
217 1.1 cgd }
218 1.3 cgd
219 1.1 cgd server.sin_family = hp->h_addrtype;
220 1.20 cbiere memcpy(&server.sin_addr.s_addr, hp->h_addr, hp->h_length);
221 1.3 cgd for (avg_cnt = 0, avg = 0; avg_cnt < 16; avg_cnt++) {
222 1.3 cgd measure_status = measure(10000,100, *argv, &server, 1);
223 1.3 cgd if (measure_status != GOOD)
224 1.3 cgd break;
225 1.3 cgd avg += measure_delta;
226 1.1 cgd }
227 1.3 cgd if (measure_status == GOOD)
228 1.3 cgd measure_delta = avg/avg_cnt;
229 1.3 cgd
230 1.1 cgd switch (measure_status) {
231 1.1 cgd case HOSTDOWN:
232 1.1 cgd printf("%s is down\n", hp->h_name);
233 1.1 cgd continue;
234 1.1 cgd case NONSTDTIME:
235 1.15 wiz printf("%s transmits a non-standard time format\n",
236 1.3 cgd hp->h_name);
237 1.1 cgd continue;
238 1.1 cgd case UNREACHABLE:
239 1.1 cgd printf("%s is unreachable\n", hp->h_name);
240 1.1 cgd continue;
241 1.3 cgd }
242 1.3 cgd
243 1.3 cgd /*
244 1.3 cgd * Try to get the date only after using ICMP timestamps to
245 1.3 cgd * get the time. This is because the date protocol
246 1.3 cgd * is optional.
247 1.3 cgd */
248 1.3 cgd if (dayaddr.sin_port != 0) {
249 1.3 cgd dayaddr.sin_family = hp->h_addrtype;
250 1.20 cbiere memcpy(&dayaddr.sin_addr.s_addr, hp->h_addr,
251 1.3 cgd hp->h_length);
252 1.3 cgd avg = daydiff(*argv);
253 1.3 cgd if (avg > SECDAY) {
254 1.3 cgd printf("time on %s is %ld days ahead %s\n",
255 1.3 cgd hp->h_name, avg/SECDAY, myname);
256 1.3 cgd continue;
257 1.3 cgd } else if (avg < -SECDAY) {
258 1.3 cgd printf("time on %s is %ld days behind %s\n",
259 1.3 cgd hp->h_name, -avg/SECDAY, myname);
260 1.3 cgd continue;
261 1.3 cgd }
262 1.1 cgd }
263 1.1 cgd
264 1.3 cgd if (measure_delta > 0) {
265 1.3 cgd printf("time on %s is %d ms. ahead of time on %s\n",
266 1.3 cgd hp->h_name, measure_delta, myname);
267 1.3 cgd } else if (measure_delta == 0) {
268 1.3 cgd printf("%s and %s have the same time\n",
269 1.3 cgd hp->h_name, myname);
270 1.3 cgd } else {
271 1.3 cgd printf("time on %s is %d ms. behind time on %s\n",
272 1.3 cgd hp->h_name, -measure_delta, myname);
273 1.3 cgd }
274 1.1 cgd }
275 1.1 cgd return;
276 1.1 cgd }
277 1.3 cgd
278 1.3 cgd
279 1.1 cgd /*
280 1.1 cgd * finds location of master timedaemon
281 1.1 cgd */
282 1.3 cgd void
283 1.3 cgd msite(int argc, char *argv[])
284 1.1 cgd {
285 1.1 cgd int cc;
286 1.12 mycroft struct pollfd set[1];
287 1.1 cgd struct sockaddr_in dest;
288 1.17 mrg int i;
289 1.17 mrg socklen_t length;
290 1.3 cgd struct sockaddr from;
291 1.12 mycroft int tout;
292 1.1 cgd struct tsp msg;
293 1.1 cgd struct servent *srvp;
294 1.3 cgd char *tgtname;
295 1.1 cgd
296 1.3 cgd if (argc < 1) {
297 1.3 cgd printf("Usage: msite [hostname]\n");
298 1.1 cgd return;
299 1.1 cgd }
300 1.1 cgd
301 1.1 cgd srvp = getservbyname("timed", "udp");
302 1.1 cgd if (srvp == 0) {
303 1.19 christos warnx("udp/timed: unknown service");
304 1.1 cgd return;
305 1.1 cgd }
306 1.1 cgd dest.sin_port = srvp->s_port;
307 1.1 cgd dest.sin_family = AF_INET;
308 1.1 cgd
309 1.3 cgd (void)gethostname(myname, sizeof(myname));
310 1.3 cgd i = 1;
311 1.12 mycroft tout = 15000;
312 1.12 mycroft set[0].fd = sock;
313 1.12 mycroft set[0].events = POLLIN;
314 1.3 cgd do {
315 1.3 cgd tgtname = (i >= argc) ? myname : argv[i];
316 1.3 cgd hp = gethostbyname(tgtname);
317 1.3 cgd if (hp == 0) {
318 1.19 christos warnx("Error resolving %s (%s)", tgtname,
319 1.19 christos hstrerror(h_errno));
320 1.3 cgd continue;
321 1.3 cgd }
322 1.20 cbiere memcpy(&dest.sin_addr.s_addr, hp->h_addr, hp->h_length);
323 1.1 cgd
324 1.20 cbiere set_tsp_name(&msg, myname);
325 1.3 cgd msg.tsp_type = TSP_MSITE;
326 1.3 cgd msg.tsp_vers = TSPVERSION;
327 1.3 cgd bytenetorder(&msg);
328 1.3 cgd if (sendto(sock, &msg, sizeof(struct tsp), 0,
329 1.3 cgd (struct sockaddr*)&dest,
330 1.3 cgd sizeof(struct sockaddr)) < 0) {
331 1.19 christos warn("sendto");
332 1.3 cgd continue;
333 1.3 cgd }
334 1.1 cgd
335 1.12 mycroft if (poll(set, 1, tout)) {
336 1.3 cgd length = sizeof(struct sockaddr);
337 1.3 cgd cc = recvfrom(sock, &msg, sizeof(struct tsp), 0,
338 1.3 cgd &from, &length);
339 1.3 cgd if (cc < 0) {
340 1.19 christos warn("recvfrom");
341 1.3 cgd continue;
342 1.3 cgd }
343 1.3 cgd bytehostorder(&msg);
344 1.3 cgd if (msg.tsp_type == TSP_ACK) {
345 1.3 cgd printf("master timedaemon at %s is %s\n",
346 1.3 cgd tgtname, msg.tsp_name);
347 1.3 cgd } else {
348 1.3 cgd printf("received wrong ack: %s\n",
349 1.3 cgd tsptype[msg.tsp_type]);
350 1.3 cgd }
351 1.3 cgd } else {
352 1.3 cgd printf("communication error with %s\n", tgtname);
353 1.1 cgd }
354 1.3 cgd } while (++i < argc);
355 1.1 cgd }
356 1.1 cgd
357 1.1 cgd /*
358 1.1 cgd * quits timedc
359 1.1 cgd */
360 1.3 cgd void
361 1.7 lukem quit(int argc, char *argv[])
362 1.1 cgd {
363 1.20 cbiere (void) argc;
364 1.20 cbiere (void) argv;
365 1.1 cgd exit(0);
366 1.1 cgd }
367 1.1 cgd
368 1.1 cgd
369 1.1 cgd /*
370 1.1 cgd * Causes the election timer to expire on the selected hosts
371 1.1 cgd * It sends just one udp message per machine, relying on
372 1.1 cgd * reliability of communication channel.
373 1.1 cgd */
374 1.3 cgd void
375 1.3 cgd testing(int argc, char *argv[])
376 1.1 cgd {
377 1.1 cgd struct servent *srvp;
378 1.20 cbiere struct sockaddr_in addr;
379 1.1 cgd struct tsp msg;
380 1.1 cgd
381 1.3 cgd if (argc < 2) {
382 1.3 cgd printf("Usage: election host1 [host2 ...]\n");
383 1.1 cgd return;
384 1.1 cgd }
385 1.1 cgd
386 1.1 cgd srvp = getservbyname("timed", "udp");
387 1.1 cgd if (srvp == 0) {
388 1.19 christos warnx("udp/timed: unknown service");
389 1.1 cgd return;
390 1.3 cgd }
391 1.1 cgd
392 1.1 cgd while (argc > 1) {
393 1.1 cgd argc--; argv++;
394 1.1 cgd hp = gethostbyname(*argv);
395 1.1 cgd if (hp == NULL) {
396 1.19 christos warnx("Error resolving %s (%s)", *argv,
397 1.19 christos hstrerror(h_errno));
398 1.1 cgd argc--; argv++;
399 1.1 cgd continue;
400 1.1 cgd }
401 1.20 cbiere addr.sin_port = srvp->s_port;
402 1.20 cbiere addr.sin_family = hp->h_addrtype;
403 1.20 cbiere memcpy(&addr.sin_addr.s_addr, hp->h_addr, hp->h_length);
404 1.3 cgd
405 1.3 cgd msg.tsp_type = TSP_TEST;
406 1.3 cgd msg.tsp_vers = TSPVERSION;
407 1.3 cgd (void)gethostname(myname, sizeof(myname));
408 1.20 cbiere set_tsp_name(&msg, myname);
409 1.3 cgd bytenetorder(&msg);
410 1.3 cgd if (sendto(sock, &msg, sizeof(struct tsp), 0,
411 1.20 cbiere (struct sockaddr*)&addr,
412 1.3 cgd sizeof(struct sockaddr)) < 0) {
413 1.19 christos warn("sendto");
414 1.1 cgd }
415 1.1 cgd }
416 1.1 cgd }
417 1.1 cgd
418 1.3 cgd
419 1.1 cgd /*
420 1.1 cgd * Enables or disables tracing on local timedaemon
421 1.1 cgd */
422 1.3 cgd void
423 1.3 cgd tracing(int argc, char *argv[])
424 1.1 cgd {
425 1.1 cgd int onflag;
426 1.17 mrg socklen_t length;
427 1.1 cgd int cc;
428 1.12 mycroft struct pollfd set[1];
429 1.1 cgd struct sockaddr_in dest;
430 1.3 cgd struct sockaddr from;
431 1.12 mycroft int tout;
432 1.1 cgd struct tsp msg;
433 1.1 cgd struct servent *srvp;
434 1.1 cgd
435 1.1 cgd if (argc != 2) {
436 1.1 cgd printf("Usage: tracing { on | off }\n");
437 1.1 cgd return;
438 1.1 cgd }
439 1.1 cgd
440 1.1 cgd srvp = getservbyname("timed", "udp");
441 1.1 cgd if (srvp == 0) {
442 1.19 christos warnx("udp/timed: unknown service");
443 1.1 cgd return;
444 1.3 cgd }
445 1.1 cgd dest.sin_port = srvp->s_port;
446 1.1 cgd dest.sin_family = AF_INET;
447 1.1 cgd
448 1.3 cgd (void)gethostname(myname,sizeof(myname));
449 1.3 cgd hp = gethostbyname(myname);
450 1.20 cbiere memcpy(&dest.sin_addr.s_addr, hp->h_addr, hp->h_length);
451 1.1 cgd
452 1.1 cgd if (strcmp(argv[1], "on") == 0) {
453 1.1 cgd msg.tsp_type = TSP_TRACEON;
454 1.1 cgd onflag = ON;
455 1.1 cgd } else {
456 1.1 cgd msg.tsp_type = TSP_TRACEOFF;
457 1.1 cgd onflag = OFF;
458 1.1 cgd }
459 1.1 cgd
460 1.20 cbiere set_tsp_name(&msg, myname);
461 1.1 cgd msg.tsp_vers = TSPVERSION;
462 1.1 cgd bytenetorder(&msg);
463 1.3 cgd if (sendto(sock, &msg, sizeof(struct tsp), 0,
464 1.3 cgd (struct sockaddr*)&dest, sizeof(struct sockaddr)) < 0) {
465 1.19 christos warn("sendto");
466 1.1 cgd return;
467 1.1 cgd }
468 1.1 cgd
469 1.12 mycroft tout = 5000;
470 1.12 mycroft set[0].fd = sock;
471 1.12 mycroft set[0].events = POLLIN;
472 1.12 mycroft if (poll(set, 1, tout)) {
473 1.3 cgd length = sizeof(struct sockaddr);
474 1.3 cgd cc = recvfrom(sock, &msg, sizeof(struct tsp), 0,
475 1.3 cgd &from, &length);
476 1.1 cgd if (cc < 0) {
477 1.19 christos warn("recvfrom");
478 1.1 cgd return;
479 1.1 cgd }
480 1.1 cgd bytehostorder(&msg);
481 1.1 cgd if (msg.tsp_type == TSP_ACK)
482 1.1 cgd if (onflag)
483 1.1 cgd printf("timed tracing enabled\n");
484 1.1 cgd else
485 1.1 cgd printf("timed tracing disabled\n");
486 1.1 cgd else
487 1.3 cgd printf("wrong ack received: %s\n",
488 1.1 cgd tsptype[msg.tsp_type]);
489 1.1 cgd } else
490 1.1 cgd printf("communication error\n");
491 1.1 cgd }
492 1.1 cgd
493 1.3 cgd int
494 1.11 wiz priv_resources(void)
495 1.1 cgd {
496 1.22 cbiere if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
497 1.22 cbiere warn("Cannot open UDP socket");
498 1.19 christos return -1;
499 1.19 christos }
500 1.19 christos
501 1.19 christos if ((sock_raw = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) == -1) {
502 1.19 christos warn("Cannot open raw socket");
503 1.19 christos (void)close(sock);
504 1.19 christos return -1;
505 1.1 cgd }
506 1.19 christos return 1;
507 1.1 cgd }
508