]>
git.saurik.com Git - apple/network_cmds.git/blob - routed.tproj/trace/trace.c
2d03ea26ee283fac09b920f10095c44ee5d54f22
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
27 * Copyright (c) 1983, 1988, 1993
28 * The Regents of the University of California. All rights reserved.
30 * The NEXTSTEP Software License Agreement specifies the terms
31 * and conditions for redistribution.
36 static char copyright
[] =
37 "@(#) Copyright (c) 1983, 1988, 1993\n\
38 The Regents of the University of California. All rights reserved.\n";
42 static char sccsid
[] = "@(#)trace.c 8.2 (Berkeley) 4/28/95";
45 #include <sys/param.h>
46 #include <sys/protosw.h>
47 #include <sys/socket.h>
48 #include <netinet/in.h>
49 #include <protocols/routed.h>
50 #include <arpa/inet.h>
56 struct sockaddr_in myaddr
;
57 char packet
[MAXPACKETSIZE
];
65 struct sockaddr_in router
;
66 register struct rip
*msg
= (struct rip
*)packet
;
72 printf("usage: trace cmd machines,\n");
73 printf("cmd either \"on filename\", or \"off\"\n");
76 s
= socket(AF_INET
, SOCK_DGRAM
, 0);
81 myaddr
.sin_family
= AF_INET
;
82 myaddr
.sin_port
= htons(IPPORT_RESERVED
-1);
83 if (bind(s
, (struct sockaddr
*)&myaddr
, sizeof(myaddr
)) < 0) {
89 msg
->rip_cmd
= strcmp(*argv
, "on") == 0 ?
90 RIPCMD_TRACEON
: RIPCMD_TRACEOFF
;
91 msg
->rip_vers
= RIPVERSION
;
94 if (msg
->rip_cmd
== RIPCMD_TRACEON
) {
95 strcpy(msg
->rip_tracefile
, *argv
);
96 size
+= strlen(*argv
);
101 memset(&router
, 0, sizeof (router
));
102 router
.sin_family
= AF_INET
;
103 sp
= getservbyname("router", "udp");
105 printf("udp/router: service unknown\n");
108 router
.sin_port
= sp
->s_port
;
110 router
.sin_family
= AF_INET
;
111 router
.sin_addr
.s_addr
= inet_addr(*argv
);
112 if (router
.sin_addr
.s_addr
== -1) {
113 hp
= gethostbyname(*argv
);
115 fprintf(stderr
, "trace: %s: ", *argv
);
116 herror((char *)NULL
);
119 memmove(&router
.sin_addr
, hp
->h_addr
, hp
->h_length
);
121 if (sendto(s
, packet
, size
, 0,
122 (struct sockaddr
*)&router
, sizeof(router
)) < 0)