Annotation of 43BSDReno/sbin/routed/trace/trace.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1983,1988 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,1988 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.7 (Berkeley) 2/18/89";
                     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;
                     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:        myaddr.sin_family = AF_INET;
                     63:        myaddr.sin_port = htons(IPPORT_RESERVED-1);
                     64:        if (bind(s, &myaddr, sizeof(myaddr)) < 0) {
                     65:                perror("bind");
                     66:                exit(2);
                     67:        }
                     68: 
                     69:        argv++, argc--;
                     70:        msg->rip_cmd = strcmp(*argv, "on") == 0 ?
                     71:                RIPCMD_TRACEON : RIPCMD_TRACEOFF;
                     72:        msg->rip_vers = RIPVERSION;
                     73:        argv++, argc--;
                     74:        size = sizeof (int);
                     75:        if (msg->rip_cmd == RIPCMD_TRACEON) {
                     76:                strcpy(msg->rip_tracefile, *argv);
                     77:                size += strlen(*argv);
                     78:                argv++, argc--;
                     79:        }
                     80:        if (argc == 0)
                     81:                goto usage;
                     82:        bzero((char *)&router, sizeof (router));
                     83:        router.sin_family = AF_INET;
                     84:        sp = getservbyname("router", "udp");
                     85:        if (sp == 0) {
                     86:                printf("udp/router: service unknown\n");
                     87:                exit(1);
                     88:        }
                     89:        router.sin_port = sp->s_port;
                     90:        while (argc > 0) {
                     91:                router.sin_family = AF_INET;
                     92:                router.sin_addr.s_addr = inet_addr(*argv);
                     93:                if (router.sin_addr.s_addr == -1) {
                     94:                        hp = gethostbyname(*argv);
                     95:                        if (hp == NULL) {
                     96:                                fprintf(stderr, "trace: %s: ", *argv);
                     97:                                herror((char *)NULL);
                     98:                                continue;
                     99:                        }
                    100:                        bcopy(hp->h_addr, &router.sin_addr, hp->h_length);
                    101:                }
                    102:                if (sendto(s, packet, size, 0, &router, sizeof(router)) < 0)
                    103:                        perror(*argv);
                    104:                argv++, argc--;
                    105:        }
                    106: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.