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 the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 18 #ifndef lint 19 char copyright[] = 20 "@(#) Copyright (c) 1983 Regents of the University of California.\n\ 21 All rights reserved.\n"; 22 #endif /* not lint */ 23 24 #ifndef lint 25 static char sccsid[] = "@(#)trace.c 5.6 (Berkeley) 10/10/88"; 26 #endif /* not lint */ 27 28 #include <sys/param.h> 29 #include <sys/protosw.h> 30 #include <sys/socket.h> 31 #include <netinet/in.h> 32 #include <errno.h> 33 #include <stdio.h> 34 #include <netdb.h> 35 #include <protocols/routed.h> 36 37 struct sockaddr_in myaddr = { AF_INET, IPPORT_RESERVED-1 }; 38 char packet[MAXPACKETSIZE]; 39 40 main(argc, argv) 41 int argc; 42 char *argv[]; 43 { 44 int size, s; 45 struct sockaddr from; 46 struct sockaddr_in router; 47 register struct rip *msg = (struct rip *)packet; 48 struct hostent *hp; 49 struct servent *sp; 50 51 if (argc < 3) { 52 usage: 53 printf("usage: trace cmd machines,\n"); 54 printf("cmd either \"on filename\", or \"off\"\n"); 55 exit(1); 56 } 57 s = socket(AF_INET, SOCK_DGRAM, 0); 58 if (s < 0) { 59 perror("socket"); 60 exit(2); 61 } 62 #ifdef vax || pdp11 63 myaddr.sin_port = htons(myaddr.sin_port); 64 #endif 65 if (bind(s, &myaddr, sizeof(myaddr)) < 0) { 66 perror("bind"); 67 exit(2); 68 } 69 70 argv++, argc--; 71 msg->rip_cmd = strcmp(*argv, "on") == 0 ? 72 RIPCMD_TRACEON : RIPCMD_TRACEOFF; 73 msg->rip_vers = RIPVERSION; 74 argv++, argc--; 75 size = sizeof (int); 76 if (msg->rip_cmd == RIPCMD_TRACEON) { 77 strcpy(msg->rip_tracefile, *argv); 78 size += strlen(*argv); 79 argv++, argc--; 80 } 81 if (argc == 0) 82 goto usage; 83 bzero((char *)&router, sizeof (router)); 84 router.sin_family = AF_INET; 85 sp = getservbyname("router", "udp"); 86 if (sp == 0) { 87 printf("udp/router: service unknown\n"); 88 exit(1); 89 } 90 router.sin_port = sp->s_port; 91 while (argc > 0) { 92 router.sin_family = AF_INET; 93 router.sin_addr.s_addr = inet_addr(*argv); 94 if (router.sin_addr.s_addr == -1) { 95 hp = gethostbyname(*argv); 96 if (hp == NULL) { 97 fprintf(stderr, "trace: %s: ", *argv); 98 herror((char *)NULL); 99 exit(1); 100 } 101 bcopy(hp->h_addr, &router.sin_addr, hp->h_length); 102 } 103 if (sendto(s, packet, size, 0, &router, sizeof(router)) < 0) 104 perror(*argv); 105 argv++, argc--; 106 } 107 } 108