122009Sdist /* 2*46786Sbostic * Copyright (c) 1983, 1988 Regents of the University of California. 333488Sbostic * All rights reserved. 433488Sbostic * 533488Sbostic * Redistribution and use in source and binary forms are permitted 634770Sbostic * provided that the above copyright notice and this paragraph are 734770Sbostic * duplicated in all such forms and that any documentation, 834770Sbostic * advertising materials, and other materials related to such 934770Sbostic * distribution and use acknowledge that the software was developed 1034770Sbostic * by the University of California, Berkeley. The name of the 1134770Sbostic * University may not be used to endorse or promote products derived 1234770Sbostic * from this software without specific prior written permission. 1334770Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1434770Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1534770Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1622009Sdist */ 1722009Sdist 187214Ssam #ifndef lint 1922009Sdist char copyright[] = 20*46786Sbostic "@(#) Copyright (c) 1983, 1988 Regents of the University of California.\n\ 2122009Sdist All rights reserved.\n"; 2233488Sbostic #endif /* not lint */ 237214Ssam 2422009Sdist #ifndef lint 25*46786Sbostic static char sccsid[] = "@(#)trace.c 5.8 (Berkeley) 02/28/91"; 2633488Sbostic #endif /* not lint */ 2722009Sdist 287214Ssam #include <sys/param.h> 297214Ssam #include <sys/protosw.h> 307214Ssam #include <sys/socket.h> 3115760Skarels #include <netinet/in.h> 32*46786Sbostic #include <protocols/routed.h> 33*46786Sbostic #include <arpa/inet.h> 34*46786Sbostic #include <netdb.h> 357214Ssam #include <stdio.h> 36*46786Sbostic #include <stdlib.h> 37*46786Sbostic #include <string.h> 387214Ssam 3936833Skarels struct sockaddr_in myaddr; 4015760Skarels char packet[MAXPACKETSIZE]; 417214Ssam 427214Ssam main(argc, argv) 437214Ssam int argc; 44*46786Sbostic char **argv; 457214Ssam { 467214Ssam int size, s; 477214Ssam struct sockaddr from; 487214Ssam struct sockaddr_in router; 497214Ssam register struct rip *msg = (struct rip *)packet; 508340Ssam struct hostent *hp; 518340Ssam struct servent *sp; 527214Ssam 537214Ssam if (argc < 3) { 547214Ssam usage: 557214Ssam printf("usage: trace cmd machines,\n"); 567214Ssam printf("cmd either \"on filename\", or \"off\"\n"); 577214Ssam exit(1); 587214Ssam } 5915760Skarels s = socket(AF_INET, SOCK_DGRAM, 0); 6015760Skarels if (s < 0) { 6115760Skarels perror("socket"); 6215760Skarels exit(2); 6315760Skarels } 6436833Skarels myaddr.sin_family = AF_INET; 6536833Skarels myaddr.sin_port = htons(IPPORT_RESERVED-1); 66*46786Sbostic if (bind(s, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) { 6715760Skarels perror("bind"); 687214Ssam exit(2); 697214Ssam } 7015760Skarels 717214Ssam argv++, argc--; 727214Ssam msg->rip_cmd = strcmp(*argv, "on") == 0 ? 737214Ssam RIPCMD_TRACEON : RIPCMD_TRACEOFF; 7415760Skarels msg->rip_vers = RIPVERSION; 757214Ssam argv++, argc--; 767214Ssam size = sizeof (int); 777214Ssam if (msg->rip_cmd == RIPCMD_TRACEON) { 787214Ssam strcpy(msg->rip_tracefile, *argv); 797214Ssam size += strlen(*argv); 807214Ssam argv++, argc--; 817214Ssam } 827214Ssam if (argc == 0) 837214Ssam goto usage; 847214Ssam bzero((char *)&router, sizeof (router)); 857214Ssam router.sin_family = AF_INET; 868340Ssam sp = getservbyname("router", "udp"); 878340Ssam if (sp == 0) { 888340Ssam printf("udp/router: service unknown\n"); 898340Ssam exit(1); 908340Ssam } 9115760Skarels router.sin_port = sp->s_port; 927214Ssam while (argc > 0) { 9326146Skarels router.sin_family = AF_INET; 9426146Skarels router.sin_addr.s_addr = inet_addr(*argv); 9526146Skarels if (router.sin_addr.s_addr == -1) { 9626146Skarels hp = gethostbyname(*argv); 9735781Sbostic if (hp == NULL) { 9835781Sbostic fprintf(stderr, "trace: %s: ", *argv); 9935781Sbostic herror((char *)NULL); 10036833Skarels continue; 10126146Skarels } 10226146Skarels bcopy(hp->h_addr, &router.sin_addr, hp->h_length); 1037214Ssam } 104*46786Sbostic if (sendto(s, packet, size, 0, 105*46786Sbostic (struct sockaddr *)&router, sizeof(router)) < 0) 1067214Ssam perror(*argv); 1077214Ssam argv++, argc--; 1087214Ssam } 1097214Ssam } 110