Annotation of 43BSD/etc/routed/tools/trace.c, revision 1.1

1.1     ! root        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 <errno.h>
        !            22: #include <stdio.h>
        !            23: #include <netdb.h>
        !            24: #include <protocols/routed.h>
        !            25: 
        !            26: struct sockaddr_in myaddr = { AF_INET, IPPORT_RESERVED-1 };
        !            27: char   packet[MAXPACKETSIZE];
        !            28: 
        !            29: main(argc, argv)
        !            30:        int argc;
        !            31:        char *argv[];
        !            32: {
        !            33:        int size, s;
        !            34:        struct sockaddr from;
        !            35:        struct sockaddr_in router;
        !            36:        register struct rip *msg = (struct rip *)packet;
        !            37:        struct hostent *hp;
        !            38:        struct servent *sp;
        !            39:        
        !            40:        if (argc < 3) {
        !            41: usage:
        !            42:                printf("usage: trace cmd machines,\n");
        !            43:                printf("cmd either \"on filename\", or \"off\"\n");
        !            44:                exit(1);
        !            45:        }
        !            46:        s = socket(AF_INET, SOCK_DGRAM, 0);
        !            47:        if (s < 0) {
        !            48:                perror("socket");
        !            49:                exit(2);
        !            50:        }
        !            51: #ifdef vax || pdp11
        !            52:        myaddr.sin_port = htons(myaddr.sin_port);
        !            53: #endif
        !            54:        if (bind(s, &myaddr, sizeof(myaddr)) < 0) {
        !            55:                perror("bind");
        !            56:                exit(2);
        !            57:        }
        !            58: 
        !            59:        argv++, argc--;
        !            60:        msg->rip_cmd = strcmp(*argv, "on") == 0 ?
        !            61:                RIPCMD_TRACEON : RIPCMD_TRACEOFF;
        !            62:        msg->rip_vers = RIPVERSION;
        !            63:        argv++, argc--;
        !            64:        size = sizeof (int);
        !            65:        if (msg->rip_cmd == RIPCMD_TRACEON) {
        !            66:                strcpy(msg->rip_tracefile, *argv);
        !            67:                size += strlen(*argv);
        !            68:                argv++, argc--;
        !            69:        }
        !            70:        if (argc == 0)
        !            71:                goto usage;
        !            72:        bzero((char *)&router, sizeof (router));
        !            73:        router.sin_family = AF_INET;
        !            74:        sp = getservbyname("router", "udp");
        !            75:        if (sp == 0) {
        !            76:                printf("udp/router: service unknown\n");
        !            77:                exit(1);
        !            78:        }
        !            79:        router.sin_port = sp->s_port;
        !            80:        while (argc > 0) {
        !            81:                router.sin_family = AF_INET;
        !            82:                router.sin_addr.s_addr = inet_addr(*argv);
        !            83:                if (router.sin_addr.s_addr == -1) {
        !            84:                        hp = gethostbyname(*argv);
        !            85:                        if (hp == 0) {
        !            86:                                printf("%s: unknown\n", *argv);
        !            87:                                exit(1);
        !            88:                        }
        !            89:                        bcopy(hp->h_addr, &router.sin_addr, hp->h_length);
        !            90:                }
        !            91:                if (sendto(s, packet, size, 0, &router, sizeof(router)) < 0)
        !            92:                        perror(*argv);
        !            93:                argv++, argc--;
        !            94:        }
        !            95: }

unix.superglobalmegacorp.com

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