122009Sdist /* 222009Sdist * Copyright (c) 1983 Regents of the University of California. 333488Sbostic * All rights reserved. 433488Sbostic * 533488Sbostic * Redistribution and use in source and binary forms are permitted 6*34770Sbostic * provided that the above copyright notice and this paragraph are 7*34770Sbostic * duplicated in all such forms and that any documentation, 8*34770Sbostic * advertising materials, and other materials related to such 9*34770Sbostic * distribution and use acknowledge that the software was developed 10*34770Sbostic * by the University of California, Berkeley. The name of the 11*34770Sbostic * University may not be used to endorse or promote products derived 12*34770Sbostic * from this software without specific prior written permission. 13*34770Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*34770Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*34770Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1622009Sdist */ 1722009Sdist 187214Ssam #ifndef lint 1922009Sdist char copyright[] = 2022009Sdist "@(#) Copyright (c) 1983 Regents of the University of California.\n\ 2122009Sdist All rights reserved.\n"; 2233488Sbostic #endif /* not lint */ 237214Ssam 2422009Sdist #ifndef lint 25*34770Sbostic static char sccsid[] = "@(#)trace.c 5.5 (Berkeley) 06/18/88"; 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 377214Ssam struct sockaddr_in myaddr = { AF_INET, IPPORT_RESERVED-1 }; 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 } 627214Ssam #ifdef vax || pdp11 637214Ssam myaddr.sin_port = htons(myaddr.sin_port); 647214Ssam #endif 6515760Skarels if (bind(s, &myaddr, sizeof(myaddr)) < 0) { 6615760Skarels perror("bind"); 677214Ssam exit(2); 687214Ssam } 6915760Skarels 707214Ssam argv++, argc--; 717214Ssam msg->rip_cmd = strcmp(*argv, "on") == 0 ? 727214Ssam RIPCMD_TRACEON : RIPCMD_TRACEOFF; 7315760Skarels msg->rip_vers = RIPVERSION; 747214Ssam argv++, argc--; 757214Ssam size = sizeof (int); 767214Ssam if (msg->rip_cmd == RIPCMD_TRACEON) { 777214Ssam strcpy(msg->rip_tracefile, *argv); 787214Ssam size += strlen(*argv); 797214Ssam argv++, argc--; 807214Ssam } 817214Ssam if (argc == 0) 827214Ssam goto usage; 837214Ssam bzero((char *)&router, sizeof (router)); 847214Ssam router.sin_family = AF_INET; 858340Ssam sp = getservbyname("router", "udp"); 868340Ssam if (sp == 0) { 878340Ssam printf("udp/router: service unknown\n"); 888340Ssam exit(1); 898340Ssam } 9015760Skarels router.sin_port = sp->s_port; 917214Ssam while (argc > 0) { 9226146Skarels router.sin_family = AF_INET; 9326146Skarels router.sin_addr.s_addr = inet_addr(*argv); 9426146Skarels if (router.sin_addr.s_addr == -1) { 9526146Skarels hp = gethostbyname(*argv); 9626146Skarels if (hp == 0) { 9726146Skarels printf("%s: unknown\n", *argv); 9826146Skarels exit(1); 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