1: /*
   2:  * Copyright (c) 1983 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: char copyright[] =
   9: "@(#) Copyright (c) 1983 Regents of the University of California.\n\
  10:  All rights reserved.\n";
  11: #endif not lint
  12: 
  13: #ifndef lint
  14: static char sccsid[] = "@(#)trace.c	5.3 (Berkeley) 2/12/86";
  15: #endif not lint
  16: 
  17: #include <sys/param.h>
  18: #include <sys/protosw.h>
  19: #include <sys/socket.h>
  20: #include <netinet/in.h>
  21: #include <arpa/inet.h>
  22: #include <errno.h>
  23: #include <stdio.h>
  24: #include <netdb.h>
  25: #include <protocols/routed.h>
  26: 
  27: struct  sockaddr_in myaddr = { AF_INET, IPPORT_RESERVED-1 };
  28: char    packet[MAXPACKETSIZE];
  29: 
  30: main(argc, argv)
  31:     int argc;
  32:     char *argv[];
  33: {
  34:     int size, s;
  35:     struct sockaddr from;
  36:     struct sockaddr_in router;
  37:     register struct rip *msg = (struct rip *)packet;
  38:     struct hostent *hp;
  39:     struct servent *sp;
  40: 
  41:     if (argc < 3) {
  42: usage:
  43:         printf("usage: trace cmd machines,\n");
  44:         printf("cmd either \"on filename\", or \"off\"\n");
  45:         exit(1);
  46:     }
  47:     s = socket(AF_INET, SOCK_DGRAM, 0);
  48:     if (s < 0) {
  49:         perror("socket");
  50:         exit(2);
  51:     }
  52: #ifdef vax || pdp11
  53:     myaddr.sin_port = htons(myaddr.sin_port);
  54: #endif
  55:     if (bind(s, &myaddr, sizeof(myaddr)) < 0) {
  56:         perror("bind");
  57:         exit(2);
  58:     }
  59: 
  60:     argv++, argc--;
  61:     msg->rip_cmd = strcmp(*argv, "on") == 0 ?
  62:         RIPCMD_TRACEON : RIPCMD_TRACEOFF;
  63:     msg->rip_vers = RIPVERSION;
  64:     argv++, argc--;
  65:     size = sizeof (int);
  66:     if (msg->rip_cmd == RIPCMD_TRACEON) {
  67:         strcpy(msg->rip_tracefile, *argv);
  68:         size += strlen(*argv);
  69:         argv++, argc--;
  70:     }
  71:     if (argc == 0)
  72:         goto usage;
  73:     bzero((char *)&router, sizeof (router));
  74:     router.sin_family = AF_INET;
  75:     sp = getservbyname("router", "udp");
  76:     if (sp == 0) {
  77:         printf("udp/router: service unknown\n");
  78:         exit(1);
  79:     }
  80:     router.sin_port = sp->s_port;
  81:     while (argc > 0) {
  82:         router.sin_family = AF_INET;
  83:         router.sin_addr.s_addr = inet_addr(*argv);
  84:         if (router.sin_addr.s_addr == -1) {
  85:             hp = gethostbyname(*argv);
  86:             if (hp == 0) {
  87:                 printf("%s: unknown\n", *argv);
  88:                 exit(1);
  89:             }
  90:             bcopy(hp->h_addr, &router.sin_addr, hp->h_length);
  91:         }
  92:         if (sendto(s, packet, size, 0, &router, sizeof(router)) < 0)
  93:             perror(*argv);
  94:         argv++, argc--;
  95:     }
  96: }

Defined functions

main defined in line 30; never used

Defined variables

copyright defined in line 8; never used
myaddr defined in line 27; used 4 times
packet defined in line 28; used 2 times
sccsid defined in line 14; never used
Last modified: 1988-08-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3323
Valid CSS Valid XHTML 1.0 Strict