ping.c (d63a94876b132d3a6741cd2336d79c61a9b13211) ping.c (ff77ab831ae8fc64a1888e1117abf6bc923dff2a)
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Mike Muuss.

--- 85 unchanged lines hidden (view full) ---

94#include <signal.h>
95#include <stdio.h>
96#include <stdlib.h>
97#include <string.h>
98#include <sysexits.h>
99#include <time.h>
100#include <unistd.h>
101
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Mike Muuss.

--- 85 unchanged lines hidden (view full) ---

94#include <signal.h>
95#include <stdio.h>
96#include <stdlib.h>
97#include <string.h>
98#include <sysexits.h>
99#include <time.h>
100#include <unistd.h>
101
102#include "utils.h"
103
102#define INADDR_LEN ((int)sizeof(in_addr_t))
103#define TIMEVAL_LEN ((int)sizeof(struct tv32))
104#define MASK_LEN (ICMP_MASKLEN - ICMP_MINLEN)
105#define TS_LEN (ICMP_TSLEN - ICMP_MINLEN)
106#define DEFDATALEN 56 /* default data length */
107#define FLOOD_BACKOFF 20000 /* usecs to back off if F_FLOOD mode */
108 /* runs out of buffer space */
109#define MAXIPLEN (sizeof(struct ip) + MAX_IPOPTLEN)

--- 94 unchanged lines hidden (view full) ---

204
205/* nonzero if we've been told to finish up */
206static volatile sig_atomic_t finish_up;
207static volatile sig_atomic_t siginfo_p;
208
209static cap_channel_t *capdns;
210
211static void fill(char *, char *);
104#define INADDR_LEN ((int)sizeof(in_addr_t))
105#define TIMEVAL_LEN ((int)sizeof(struct tv32))
106#define MASK_LEN (ICMP_MASKLEN - ICMP_MINLEN)
107#define TS_LEN (ICMP_TSLEN - ICMP_MINLEN)
108#define DEFDATALEN 56 /* default data length */
109#define FLOOD_BACKOFF 20000 /* usecs to back off if F_FLOOD mode */
110 /* runs out of buffer space */
111#define MAXIPLEN (sizeof(struct ip) + MAX_IPOPTLEN)

--- 94 unchanged lines hidden (view full) ---

206
207/* nonzero if we've been told to finish up */
208static volatile sig_atomic_t finish_up;
209static volatile sig_atomic_t siginfo_p;
210
211static cap_channel_t *capdns;
212
213static void fill(char *, char *);
212static u_short in_cksum(u_char *, int);
213static cap_channel_t *capdns_setup(void);
214static void check_status(void);
215static void finish(void) __dead2;
216static void pinger(void);
217static char *pr_addr(struct in_addr);
218static char *pr_ntime(n_time);
219static void pr_icmph(struct icmp *);
220static void pr_iph(struct ip *);

--- 1118 unchanged lines hidden (view full) ---

1339 }
1340 if (!(options & F_FLOOD)) {
1341 (void)putchar('\n');
1342 (void)fflush(stdout);
1343 }
1344}
1345
1346/*
214static cap_channel_t *capdns_setup(void);
215static void check_status(void);
216static void finish(void) __dead2;
217static void pinger(void);
218static char *pr_addr(struct in_addr);
219static char *pr_ntime(n_time);
220static void pr_icmph(struct icmp *);
221static void pr_iph(struct ip *);

--- 1118 unchanged lines hidden (view full) ---

1340 }
1341 if (!(options & F_FLOOD)) {
1342 (void)putchar('\n');
1343 (void)fflush(stdout);
1344 }
1345}
1346
1347/*
1347 * in_cksum --
1348 * Checksum routine for Internet Protocol family headers (C Version)
1349 */
1350u_short
1351in_cksum(u_char *addr, int len)
1352{
1353 int nleft, sum;
1354 u_char *w;
1355 union {
1356 u_short us;
1357 u_char uc[2];
1358 } last;
1359 u_short answer;
1360
1361 nleft = len;
1362 sum = 0;
1363 w = addr;
1364
1365 /*
1366 * Our algorithm is simple, using a 32 bit accumulator (sum), we add
1367 * sequential 16 bit words to it, and at the end, fold back all the
1368 * carry bits from the top 16 bits into the lower 16 bits.
1369 */
1370 while (nleft > 1) {
1371 u_short data;
1372
1373 memcpy(&data, w, sizeof(data));
1374 sum += data;
1375 w += sizeof(data);
1376 nleft -= sizeof(data);
1377 }
1378
1379 /* mop up an odd byte, if necessary */
1380 if (nleft == 1) {
1381 last.uc[0] = *w;
1382 last.uc[1] = 0;
1383 sum += last.us;
1384 }
1385
1386 /* add back carry outs from top 16 bits to low 16 bits */
1387 sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
1388 sum += (sum >> 16); /* add carry */
1389 answer = ~sum; /* truncate to 16 bits */
1390 return(answer);
1391}
1392
1393/*
1394 * status --
1395 * Print out statistics when SIGINFO is received.
1396 */
1397
1398static void
1399status(int sig __unused)
1400{
1401

--- 398 unchanged lines hidden ---
1348 * status --
1349 * Print out statistics when SIGINFO is received.
1350 */
1351
1352static void
1353status(int sig __unused)
1354{
1355

--- 398 unchanged lines hidden ---