]>
git.saurik.com Git - apple/network_cmds.git/blob - ecnprobe/support.c
3 International Computer Science Institute
6 This file may contain software code originally developed for the
7 Sting project. The Sting software carries the following copyright:
9 Copyright (c) 1998, 1999
10 Stefan Savage and the University of Washington.
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions
16 1. Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
18 2. Redistributions in binary form must reproduce the above copyright
19 notice, this list of conditions and the following disclaimer in the
20 documentation and/or other materials provided with the distribution.
21 3. All advertising materials mentioning features or use of this software
22 must display the following acknowledgment:
23 This product includes software developed by ACIRI, the AT&T
24 Center for Internet Research at ICSI (the International Computer
25 Science Institute). This product may also include software developed
26 by Stefan Savage at the University of Washington.
27 4. The names of ACIRI, ICSI, Stefan Savage and University of Washington
28 may not be used to endorse or promote products derived from this software
29 without specific prior written permission.
31 THIS SOFTWARE IS PROVIDED BY ICSI AND CONTRIBUTORS ``AS IS'' AND
32 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34 ARE DISCLAIMED. IN NO EVENT SHALL ICSI OR CONTRIBUTORS BE LIABLE
35 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 #include <sys/types.h>
44 #include <sys/param.h>
55 extern struct TcpSession session
;
62 if (session
.dont_send_reset
)
65 if ((p
= (struct IPPacket
*)calloc(1, sizeof(struct IPPacket
))) == NULL
) {
66 perror("ERROR: Could not allocate RST packet:") ;
70 if ((p
->ip
= (struct IpHeader
*)calloc(1, sizeof(struct IpHeader
))) == NULL
) {
71 perror("ERROR: Could not allocate IP Header for RST packet:") ;
75 if ((p
->tcp
= (struct TcpHeader
*)calloc(1, sizeof(struct TcpHeader
))) == NULL
) {
76 perror("ERROR: Could not allocate TCP Header for RST packet:") ;
80 for (i
= 0; i
< MAXRESETRETRANSMITS
; i
++) {
82 //sizeof(struct IPPacket),
83 sizeof(struct IpHeader
) + sizeof(struct TcpHeader
),
98 /* make a clean exit on interrupts */
99 void SigHandle (int signo
)
114 /* If a firewall rule has been installed then remove it */
115 if (session
.initFirewall
> 0) {
118 #define IP_FW_DEL (IP_FW_DELETE)
121 sprintf(ipfw_rule
, "ipfw del 00%d", session
.firewall_rule_number
);
122 r
= system(ipfw_rule
);
126 if (session
.initSession
> 0) {
129 shutdown(session
.socket
,2);
133 if (session
.initCapture
> 0) {
154 double postEpochSecs
;
156 if (gettimeofday(&tv
, &tz
) < 0) {
161 postEpochSecs
= (double)tv
.tv_sec
+ ((double)tv
.tv_usec
/(double)1000000.0);
162 return postEpochSecs
;
165 double GetTimeMicroSeconds()
169 double postEpochMicroSecs
;
171 if (gettimeofday(&tv
, &tz
) < 0) {
172 perror("GetTimeMicroSeconds");
176 postEpochMicroSecs
= (double)tv
.tv_sec
* 1000000 + (double)tv
.tv_usec
;
177 return postEpochMicroSecs
;
181 void PrintTimeStamp(struct timeval
*ts
)
183 (void)printf("%02d:%02d:%02d.%06u ",
184 (unsigned int)ts
->tv_sec
/ 3600,
185 ((unsigned int)ts
->tv_sec
% 3600) / 60,
186 (unsigned int)ts
->tv_sec
% 60, (unsigned int)ts
->tv_usec
);
189 void processBadPacket (struct IPPacket
*p
)
192 if (session
.debug
== SESSION_DEBUG_HIGH
) {
193 printf("In ProcessBadPacket...\n");
196 * reset? the other guy does not like us?
198 if (INSESSION(p
,session
.dst
,session
.dport
,session
.src
,session
.sport
) && (p
->tcp
->tcp_flags
& TCPFLAGS_RST
)) {
199 printf("ERROR: EARLY_RST.\nRETURN CODE: %d\n", EARLY_RST
);
203 * some other packet between us that is none of the above
205 if (INSESSION(p
, session
.src
, session
.sport
, session
.dst
, session
.dport
) ||
206 INSESSION(p
, session
.dst
, session
.dport
, session
.src
, session
.sport
)) {
208 printf("ERROR: Unexpected packet\nRETURN CODE: %d\n", UNEXPECTED_PKT
);
209 printf("Expecting:\n");
210 printf("\tsrc = %s:%d (seq=%u, ack=%u)\n",
211 InetAddress(session
.src
), session
.sport
,
212 session
.snd_nxt
-session
.iss
,
213 session
.rcv_nxt
-session
.irs
);
214 printf("\tdst = %s:%d (seq=%u, ack=%u)\n",
215 InetAddress(session
.dst
),session
.dport
,
216 session
.rcv_nxt
-session
.irs
, session
.snd_una
-session
.iss
);
217 printf("Received:\n\t");
219 printf ("session.snd_nxt=%d, session.rcv_nxt=%d, session.snd_una=%d\n",
220 session
.snd_nxt
-session
.iss
, session
.rcv_nxt
-session
.irs
, session
.snd_una
-session
.iss
);
221 Quit(UNEXPECTED_PKT
);
225 * so we must be seeing packets
226 * from some other flow!
229 printf("ERRROR: Received packet from different flow\nRETURN CODE: %d\n", DIFF_FLOW
);
234 if (session
.debug
== SESSION_DEBUG_HIGH
) {
235 printf("Out ProcessBadPacket...\n");
239 void busy_wait (double wait
)
241 double now
= GetTime();
243 while ((x
- now
) < wait
) {