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

1.1     ! root        1: #ifndef lint
        !             2: static char sccsid[] = "@(#)trace.c    4.2 10/6/82";
        !             3: #endif
        !             4: 
        !             5: #include <sys/param.h>
        !             6: #include <sys/protosw.h>
        !             7: #include <sys/socket.h>
        !             8: #include <net/in.h>
        !             9: #include <errno.h>
        !            10: #include <stdio.h>
        !            11: #include <netdb.h>
        !            12: #include "rip.h"
        !            13: 
        !            14: struct sockaddr_in myaddr = { AF_INET, IPPORT_RESERVED-1 };
        !            15: 
        !            16: main(argc, argv)
        !            17:        int argc;
        !            18:        char *argv[];
        !            19: {
        !            20:        int size, s;
        !            21:        struct sockaddr from;
        !            22:        struct sockaddr_in router;
        !            23:        char packet[MAXPACKETSIZE];
        !            24:        register struct rip *msg = (struct rip *)packet;
        !            25:        struct hostent *hp;
        !            26:        struct servent *sp;
        !            27:        
        !            28:        if (argc < 3) {
        !            29: usage:
        !            30:                printf("usage: trace cmd machines,\n");
        !            31:                printf("cmd either \"on filename\", or \"off\"\n");
        !            32:                exit(1);
        !            33:        }
        !            34: #ifdef vax || pdp11
        !            35:        myaddr.sin_port = htons(myaddr.sin_port);
        !            36: #endif
        !            37:        s = socket(SOCK_DGRAM, 0, &myaddr, 0);
        !            38:        if (s < 0) {
        !            39:                perror("socket");
        !            40:                exit(2);
        !            41:        }
        !            42:        argv++, argc--;
        !            43:        msg->rip_cmd = strcmp(*argv, "on") == 0 ?
        !            44:                RIPCMD_TRACEON : RIPCMD_TRACEOFF;
        !            45:        argv++, argc--;
        !            46:        size = sizeof (int);
        !            47:        if (msg->rip_cmd == RIPCMD_TRACEON) {
        !            48:                strcpy(msg->rip_tracefile, *argv);
        !            49:                size += strlen(*argv);
        !            50:                argv++, argc--;
        !            51:        }
        !            52:        if (argc == 0)
        !            53:                goto usage;
        !            54:        bzero((char *)&router, sizeof (router));
        !            55:        router.sin_family = AF_INET;
        !            56:        sp = getservbyname("router", "udp");
        !            57:        if (sp == 0) {
        !            58:                printf("udp/router: service unknown\n");
        !            59:                exit(1);
        !            60:        }
        !            61:        router.sin_port = htons(sp->s_port);
        !            62:        while (argc > 0) {
        !            63:                hp = gethostbyname(*argv);
        !            64:                if (hp == 0) {
        !            65:                        printf("%s: unknown\n", *argv);
        !            66:                        continue;
        !            67:                }
        !            68:                bcopy(hp->h_addr, &router.sin_addr, hp->h_length);
        !            69:                if (send(s, &router, packet, size) < 0)
        !            70:                        perror(*argv);
        !            71:                argv++, argc--;
        !            72:        }
        !            73: }

unix.superglobalmegacorp.com

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