|
|
1.1 root 1: /*
2: * Copyright (c) 1983 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that this notice is preserved and that due credit is given
7: * to the University of California at Berkeley. The name of the University
8: * may not be used to endorse or promote products derived from this
9: * software without specific prior written permission. This software
10: * is provided ``as is'' without express or implied warranty.
11: */
12:
13: #ifndef lint
14: char copyright[] =
15: "@(#) Copyright (c) 1983 Regents of the University of California.\n\
16: All rights reserved.\n";
17: #endif /* not lint */
18:
19: #ifndef lint
20: static char sccsid[] = "@(#)trace.c 5.4 (Berkeley) 2/16/88";
21: #endif /* not lint */
22:
23: #include <sys/param.h>
24: #include <sys/protosw.h>
25: #include <sys/socket.h>
26: #include <netinet/in.h>
27: #include <errno.h>
28: #include <stdio.h>
29: #include <netdb.h>
30: #include <protocols/routed.h>
31:
32: struct sockaddr_in myaddr = { AF_INET, IPPORT_RESERVED-1 };
33: char packet[MAXPACKETSIZE];
34:
35: main(argc, argv)
36: int argc;
37: char *argv[];
38: {
39: int size, s;
40: struct sockaddr from;
41: struct sockaddr_in router;
42: register struct rip *msg = (struct rip *)packet;
43: struct hostent *hp;
44: struct servent *sp;
45:
46: if (argc < 3) {
47: usage:
48: printf("usage: trace cmd machines,\n");
49: printf("cmd either \"on filename\", or \"off\"\n");
50: exit(1);
51: }
52: s = socket(AF_INET, SOCK_DGRAM, 0);
53: if (s < 0) {
54: perror("socket");
55: exit(2);
56: }
57: #ifdef vax || pdp11
58: myaddr.sin_port = htons(myaddr.sin_port);
59: #endif
60: if (bind(s, &myaddr, sizeof(myaddr)) < 0) {
61: perror("bind");
62: exit(2);
63: }
64:
65: argv++, argc--;
66: msg->rip_cmd = strcmp(*argv, "on") == 0 ?
67: RIPCMD_TRACEON : RIPCMD_TRACEOFF;
68: msg->rip_vers = RIPVERSION;
69: argv++, argc--;
70: size = sizeof (int);
71: if (msg->rip_cmd == RIPCMD_TRACEON) {
72: strcpy(msg->rip_tracefile, *argv);
73: size += strlen(*argv);
74: argv++, argc--;
75: }
76: if (argc == 0)
77: goto usage;
78: bzero((char *)&router, sizeof (router));
79: router.sin_family = AF_INET;
80: sp = getservbyname("router", "udp");
81: if (sp == 0) {
82: printf("udp/router: service unknown\n");
83: exit(1);
84: }
85: router.sin_port = sp->s_port;
86: while (argc > 0) {
87: router.sin_family = AF_INET;
88: router.sin_addr.s_addr = inet_addr(*argv);
89: if (router.sin_addr.s_addr == -1) {
90: hp = gethostbyname(*argv);
91: if (hp == 0) {
92: printf("%s: unknown\n", *argv);
93: exit(1);
94: }
95: bcopy(hp->h_addr, &router.sin_addr, hp->h_length);
96: }
97: if (sendto(s, packet, size, 0, &router, sizeof(router)) < 0)
98: perror(*argv);
99: argv++, argc--;
100: }
101: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.