122009Sdist /* 2*36833Skarels * 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*36833Skarels "@(#) 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*36833Skarels static char sccsid[] = "@(#)trace.c 5.7 (Berkeley) 02/18/89"; 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> 327214Ssam #include <errno.h> 337214Ssam #include <stdio.h> 348340Ssam #include <netdb.h> 3525382Skarels #include <protocols/routed.h> 367214Ssam 37*36833Skarels struct sockaddr_in myaddr; 3815760Skarels char packet[MAXPACKETSIZE]; 397214Ssam 407214Ssam main(argc, argv) 417214Ssam int argc; 427214Ssam char *argv[]; 437214Ssam { 447214Ssam int size, s; 457214Ssam struct sockaddr from; 467214Ssam struct sockaddr_in router; 477214Ssam register struct rip *msg = (struct rip *)packet; 488340Ssam struct hostent *hp; 498340Ssam struct servent *sp; 507214Ssam 517214Ssam if (argc < 3) { 527214Ssam usage: 537214Ssam printf("usage: trace cmd machines,\n"); 547214Ssam printf("cmd either \"on filename\", or \"off\"\n"); 557214Ssam exit(1); 567214Ssam } 5715760Skarels s = socket(AF_INET, SOCK_DGRAM, 0); 5815760Skarels if (s < 0) { 5915760Skarels perror("socket"); 6015760Skarels exit(2); 6115760Skarels } 62*36833Skarels myaddr.sin_family = AF_INET; 63*36833Skarels myaddr.sin_port = htons(IPPORT_RESERVED-1); 6415760Skarels if (bind(s, &myaddr, sizeof(myaddr)) < 0) { 6515760Skarels perror("bind"); 667214Ssam exit(2); 677214Ssam } 6815760Skarels 697214Ssam argv++, argc--; 707214Ssam msg->rip_cmd = strcmp(*argv, "on") == 0 ? 717214Ssam RIPCMD_TRACEON : RIPCMD_TRACEOFF; 7215760Skarels msg->rip_vers = RIPVERSION; 737214Ssam argv++, argc--; 747214Ssam size = sizeof (int); 757214Ssam if (msg->rip_cmd == RIPCMD_TRACEON) { 767214Ssam strcpy(msg->rip_tracefile, *argv); 777214Ssam size += strlen(*argv); 787214Ssam argv++, argc--; 797214Ssam } 807214Ssam if (argc == 0) 817214Ssam goto usage; 827214Ssam bzero((char *)&router, sizeof (router)); 837214Ssam router.sin_family = AF_INET; 848340Ssam sp = getservbyname("router", "udp"); 858340Ssam if (sp == 0) { 868340Ssam printf("udp/router: service unknown\n"); 878340Ssam exit(1); 888340Ssam } 8915760Skarels router.sin_port = sp->s_port; 907214Ssam while (argc > 0) { 9126146Skarels router.sin_family = AF_INET; 9226146Skarels router.sin_addr.s_addr = inet_addr(*argv); 9326146Skarels if (router.sin_addr.s_addr == -1) { 9426146Skarels hp = gethostbyname(*argv); 9535781Sbostic if (hp == NULL) { 9635781Sbostic fprintf(stderr, "trace: %s: ", *argv); 9735781Sbostic herror((char *)NULL); 98*36833Skarels continue; 9926146Skarels } 10026146Skarels bcopy(hp->h_addr, &router.sin_addr, hp->h_length); 1017214Ssam } 10215760Skarels if (sendto(s, packet, size, 0, &router, sizeof(router)) < 0) 1037214Ssam perror(*argv); 1047214Ssam argv++, argc--; 1057214Ssam } 1067214Ssam } 107