Commit Graph

195 Commits

Author SHA1 Message Date
Gleb Smirnoff
d6cd14974c Add a new feature to ping(8) - possibility to specify maximum
wait time for a packet. This allows to:

 - Count number of packets received before and after specified
   time.
 - Shorten time of execution of 'ping -c 1' scripts.

Submitted by:	Lytochkin Boris <lytboris gmail.com>
2006-04-05 12:30:42 +00:00
Ruslan Ermilov
ee3e1c4c08 Sync usage() with SYNOPSIS. 2005-12-01 22:03:34 +00:00
Ruslan Ermilov
4e9e907d63 -mdoc sweep. 2005-11-18 10:36:29 +00:00
Gleb Smirnoff
9ff95228e8 Implement a new feature for ping(8) - sweeping pings. In a sweeping
ping ICMP payload of packets being sent is increased with given step.
Sweeping pings are useful for testing problematic channels, MTU
issues or traffic policing functions in networks.

PR:		bin/82625
Submitted by:	Chris Hellberg <chellberg juniper.net> (with some cleanups)
2005-08-15 14:15:37 +00:00
Maxim Konovalov
13e3f0b717 o Store timestamp in network byte order.
o Remove an assumption sizeof(struct timeval) == 8 (this is not
  true on sparc64).

Reviewed by:	imp, -hackers
Obtained from:	NetBSD (rev. 1.75)
MT5 after:	1 month
2004-09-30 07:35:56 +00:00
Stefan Farfeleder
4eae39bfdf Avoid using void pointers in additive expressions.
PR:		56653
2004-08-14 17:46:10 +00:00
Mark Murray
4c723140a4 Remove advertising clause from University of California Regent's license,
per letter dated July 22, 1999.

Approved by: core, imp
2004-04-09 19:58:40 +00:00
Ian Dowse
a8616db8fd Don't turn off the regular SIGINFO status information. The use of
the NOKERNINFO flag only marginally de-clutters the output and
has a number of unwanted side effects:
  o The kernel info might be what you want to see
  o ^T is left non-functional if ping is killed non-cleanly
  o "ping -q foo &" gets suspended on tty output

Encouraged by:	bde
2004-04-07 18:48:11 +00:00
Johan Karlsson
604d24db95 style.Makefile(5):
Use WARNS?= instead of WARNS=.
2004-02-23 20:25:27 +00:00
Ian Dowse
c8bb99e577 Certain ICMP error replies cause ping to perform a reverse DNS
lookup on an IP address from the packet (such as the IP that sent
a TTL exceeded error). If the DNS lookup takes a long time, ^C will
appear to be ineffective since the SIGINT handler just sets a flag
and returns. Work around this by exiting immediately on receipt of
a second SIGINT when DNS lookups are enabled.

PR:		bin/4696
MFC after:	1 week
2004-02-08 21:59:17 +00:00
Ruslan Ermilov
fe08efe680 mdoc(7): Use the new feature of the .In macro. 2003-09-08 19:57:22 +00:00
Maxim Konovalov
007fe4e38a o Rename local variables, do not shadow global declarations. 2003-07-14 12:43:48 +00:00
Maxim Konovalov
0fe0c0cc20 o Kill MINICMPLEN, there is ICMP_MINLEN already. 2003-07-14 12:42:47 +00:00
Maxim Konovalov
e88178dd90 o Be ready to get a reply with length up to IP_MAXPACKET.
o Warn when recieved packet length is not equal to length of the
packet we sent out. Idea from NetBSD.
o Fit the dump of packet with wrong data to 80 columns (from NetBSD).

Comments from:	bde
2003-07-14 12:37:03 +00:00
Ruslan Ermilov
a70dc55680 The current recommended default time to live (TTL) for the Internet
Protocol (IP) is 64 [RFC791, RFC1122].

Prodded by:	Igor Kucherenko <kivvy@sunbay.com>
Obtained from:	http://www.iana.org/assignments/ip-parameters
2003-06-25 13:02:18 +00:00
Maxim Konovalov
aed98a27fd Fix SIGINFO handling: do not print incorrect timing statistics
when the data for it is not available.

Founded by:	ping -s0 localhost; press ^T
2003-06-02 10:01:59 +00:00
David E. O'Brien
c69284ca08 Use __FBSDID() to quiet GCC 3.3 warnings. 2003-05-03 18:41:59 +00:00
Maxim Konovalov
29dccd6ae1 o Skip timestamp part when checking payload.
PR:		bin/50909
Submitted by:	Barney Wolff <barney@lab.databus.com>
2003-04-14 08:34:14 +00:00
Matthew N. Dodd
47e9b3ea64 Deal with a case where the returned packed was smaller than the
transmitted packet (because the remote host stripped off our icmp_data).

Submitted by:	 Maxim Konovalov <maxim@macomnet.ru>
2003-04-07 12:05:50 +00:00
Matthew N. Dodd
2c56e246fa Back out support for RFC3514.
RFC3514 poses an unacceptale risk to compliant systems.
2003-04-02 20:14:44 +00:00
Maxim Konovalov
33e1dc7738 IP_EVIL -> IP_EF 2003-04-02 14:52:21 +00:00
Matthew N. Dodd
09139a4537 Implement support for RFC 3514 (The Security Flag in the IPv4 Header).
(See: ftp://ftp.rfc-editor.org/in-notes/rfc3514.txt)

This fulfills the host requirements for userland support by
way of the setsockopt() IP_EVIL_INTENT message.

There are three sysctl tunables provided to govern system behavior.

	net.inet.ip.rfc3514:

		Enables support for rfc3514.  As this is an
		Informational RFC and support is not yet widespread
		this option is disabled by default.

	net.inet.ip.hear_no_evil

		 If set the host will discard all received evil packets.

	net.inet.ip.speak_no_evil

		If set the host will discard all transmitted evil packets.

The IP statistics counter 'ips_evil' (available via 'netstat') provides
information on the number of 'evil' packets recieved.

For reference, the '-E' option to 'ping' has been provided to demonstrate
and test the implementation.
2003-04-01 08:21:44 +00:00
Matthew N. Dodd
c67c1ce843 Default data length should be 56, not 64. 2003-03-28 00:31:51 +00:00
Matthew N. Dodd
d829c3dfee - Make -M mask and -M time exclusive.
- Correct some problems with packet construction.

  +--------+------------+----------+-------------+---------+
  |        |            |          |             |         |
  | IP Hdr | MINICMPLEN | phdr_len | TIMEVAL_LEN | payload |
  |        |            |          |             |         |
  +--------+------------+----------+-------------+---------+
  |        |                       |                       |
  |<- IP ->|<------- ICMP -------->|<------ datalen ------>|

My previous changes tried to mess around with 'datalen' instead of
modifying 'phdr_len'.

I'm including this nice ASCII diagram (from Maxim) to further clarify things
in CVS history.

Submitted by:	 Maxim Konovalov <maxim@macomnet.ru>
2003-03-24 23:48:36 +00:00
Bruce Evans
1104dd84fa Fixed an errx format error in rev.1.81. This should have been fatal
when WARNS was increased recently, but __printf0like() has been
temporarily disabled for 8 months.

Fixed related style bugs (disordered declaraction and silly type for
maxpayload -- assume 16-bit ints like the rest of ping.c).
2003-03-24 11:26:08 +00:00
Ruslan Ermilov
120b4a9366 Demangle the usage message at the source level.
Submitted by:	bde
2003-03-14 07:59:38 +00:00
Ruslan Ermilov
1bd10ba2d9 Fix and sync SYNOPSIS and usage().
Prodded by:	bde
2003-03-11 20:12:39 +00:00
Sean Chittenden
31eac03b4b Update ping to be WARNS=2 compliant.
Reviewed by:	-audit (no objections ~1mo)
Approved by:	nectar
2003-03-05 22:42:03 +00:00
Matthew N. Dodd
1fb474d8b2 Spelling, grammar fixes. 2003-03-05 21:42:23 +00:00
Matthew N. Dodd
9b085129ae Remove documentation of old '-M' flag.
Re-order.
2003-03-05 20:35:45 +00:00
Matthew N. Dodd
eb1543c6ee Support ICMP_TSTAMP/ICMP_TSTAMPREPLY.
This alters the meaning of the '-M' flag.
2003-03-02 21:24:08 +00:00
Ruslan Ermilov
1f6a46318d Sort options. 2003-02-23 01:50:07 +00:00
Matthew N. Dodd
d074d39fef Call fill() after maxpayload has been initialized.
Reviewed by:	 maxim
2003-01-29 20:42:42 +00:00
Matthew N. Dodd
143008a1fe Send ICMP_MASKREQ packets when the '-M' option is specified. 2003-01-28 22:53:24 +00:00
Maxim Konovalov
fb7d32c7ee Better error handling for -s.
Submitted by:	bde

Do not constantify maximum payload size. It is 65467 with -R
(record route), and 65507 without it.

Reviewed by:	silence on -net
Proposed by:	bde

I am going to MFC rev.1.77 - 1.81 ping.c and rev.1.39 and 1.40 ping.8:

MFC after:      6 months
2003-01-23 13:04:42 +00:00
Maxim Konovalov
261e59bb9e style(9) sweep.
Submitted by:	bde
2003-01-23 12:56:10 +00:00
Maxim Konovalov
9bc1a9ec6c Anti-magic: s/255/MAXTTL/ 2003-01-23 12:54:11 +00:00
Maxim Konovalov
0b2f8b3f68 Implement -D (do not fragment) and -z (TOS) options.
PR:		bin/29164
Reviewed by:	silence of -net
Obtained from:	OpenBSD
2003-01-23 12:48:12 +00:00
Maxim Konovalov
cb75aca7cd Print strict source routing option.
Reviewed by:	silence on -net
Proposed by:	David Wang <dsw@juniper.net>
2003-01-23 12:42:56 +00:00
Jens Schweikhardt
57bd0fc6e8 english(4) police. 2002-12-27 12:15:40 +00:00
Ruslan Ermilov
074ad11567 Spelling: s/then/than/ where appropriate. 2002-12-24 16:52:31 +00:00
Maxim Konovalov
3c721ab3c9 Fix LSRR option length check: it has to be less or equal remained header's
length minus sizeof(struct ip).

MFC after:	1 week
2002-10-21 11:43:46 +00:00
Dima Dorfman
8025c44b00 Add an -o option to exit after receiving one reply. This can be used
to test whether a link is live.

PR:		38573
Submitted by:	David Taylor <davidt@yadt.co.uk>
Obtained from:	NetBSD
2002-10-02 03:24:27 +00:00
Peter Wemm
9b2196460d Commit "unrelated style fixes" part of Bruce's patch (regarding
bcopy/memcpy) seperately.

Submitted by:  bde
2002-09-11 18:16:40 +00:00
Peter Wemm
9d2b0ab82a Modify previous commit to solve the real problem that made gcc think
the timestamp was aligned.  ie: Use a void * instead of struct timeval *
which gcc assumes will be aligned.  Go back to memcpy().

Submitted by: bde
2002-09-11 18:12:29 +00:00
Jacques Vidrine
7e5bbd6847 In reference to previous commit: use err(3).
Noticed by:	bde
2002-09-09 18:51:59 +00:00
Jacques Vidrine
ef9d72e14c Check for FD_SET overrun. 2002-09-09 15:58:08 +00:00
Ian Dowse
9c1b8868dc Add the -A flag to the usage line.
Submitted by:	Yutaka KAWASE <yutaka@mailhost.net>
MFC after:	3 days
2002-08-27 08:09:37 +00:00
Peter Wemm
11bad678c6 Fix the broken "avoid unaligned data" fix. The problem is that the builtin
gcc memcpy "knows" about types that are supposed to be actually already
aligned and triggers alignment errors doing the memcpy itself.
"Fix" this by changing it to a bcopy().  In this case, we had:
  struct timeval *tp;
  struct timeval tv1;
  memcpy(&tv1,tp,sizeof(tv1));
.. and since gcc *knows* that a pointer to a timeval is longword aligned
and that tv1 is longword aligned, then it can use an inline that assumes
alignment.  The following works too:
  cp = (char *)tp;
  memcpy(&tv1,cp,sizeof(tv1));
Simply casting (char *)tp  for the memcpy doesn't work. :-(
This affected different 64 bit platforms in different ways and depends
a lot on gcc as well.  I've seen this on alpha and ia64 at least, although
alpha isn't doing it right now.
2002-08-10 03:00:55 +00:00
Philippe Charnier
e1205e80e5 The .Nm utility 2002-07-06 19:34:18 +00:00
Maxim Konovalov
4fba6582cb o Change almost all magic numbers to the appropriate constants.
o Fix zero payloading, unbreak ping -s 0.
o Increase socket recieve buffer, ping -s 65467 is working now.

Submitted by:	anti-magic sweep based on kris's patch
Reviewed by:	bde, silence on -audit
MFC after:	2 months
2002-07-05 11:52:54 +00:00
Maxim Konovalov
301207dffe More strict ip options parsing.
Reviewed by:	bde (style), silence on -audit
MFC after:	2 months
2002-07-05 11:47:33 +00:00
Maxim Konovalov
c6facae4d9 WARNS fixes.
Submitted by:	kris
Reviewed by:	bde
Approved by:	ru
MFC after:	2 weeks
2002-04-02 10:15:32 +00:00
Maxim Konovalov
1ad0b1beb4 style(9) cleanup.
Submitted by:	kris (an early version of this patch)
Reviewed by:	bde
Approved by:	ru
MFC after:	2 weeks
2002-04-02 09:36:46 +00:00
David E. O'Brien
efc8588d57 Style(9) local vars after 'register' removal.
Requested by:	bde
2002-03-23 18:10:59 +00:00
David E. O'Brien
3d438ad61f Remove 'register' keyword.
It does not help modern compilers, and some may take some hit from it.
(I also found several functions that listed *every* of its 10 local vars with
 "register" -- just how many free registers do people think machines have?)
2002-03-20 17:55:10 +00:00
Bill Fenner
5db89bc7e6 Use network byte order for the ICMP sequence number. This is only
significant when monitoring packets on another system, since
 otherwise the ICMP sequence number is only used by the ping client.
2002-02-27 22:37:22 +00:00
Maxim Konovalov
605af08d9f Document ping(8) reaction to SIGINFO.
PR:		doc/33639
Reviewed by:	ru
Approved by:	ru
MFC after:	1 week
2002-02-07 16:47:22 +00:00
Ruslan Ermilov
32af342f58 Fixed two bugs with the "-l preload" option:
- first ping after a preload was sent undelayed
- we could send more than -c packets in preload

PR:		bin/32354
2002-01-14 14:33:35 +00:00
David E. O'Brien
2d68bf45bf Default to WARNS=2.
Binary builds that cannot handle this must explicitly set WARNS=0.

Reviewed by:	mike
2001-12-04 02:19:58 +00:00
Ian Dowse
2510719736 The -A option (beep when packets are dropped) didn't work quite
right; after a single packet was dropped it beeped after every
transmission.

Change its implementation to only output a bell when there is an
increase in the maximum value of the number of packets that were
sent but not yet received. This has the benefit that even for very
long round-trip times, ping -A will do roughly the right thing
after a few inital false-positives.

Reviewed by:	ru
2001-09-25 20:22:33 +00:00
Ruslan Ermilov
cda2a9b2f0 Set BINOWN=root explicitly for setuid root binaries.
This is not "useless", as one may have non-default
setting for BINOWN in make.conf, and we still want
these to be installed setuid root in this case.
2001-09-13 06:48:18 +00:00
Dima Dorfman
f328d583a2 Use CFLAGS, not COPTS, in the Makefile. bsd.prog.mk conveniently adds
COPTS towards the end of final CFLAGS so that it can be used to
override Makefile and other defaults.  Using it in Makefiles risks
having options set using it clobbered when somebody uses it on the
command line.

Approved by:	bde
2001-09-05 20:10:59 +00:00
Ruslan Ermilov
c4d9468ea0 mdoc(7) police:
Avoid using parenthesis enclosure macros (.Pq and .Po/.Pc) with plain text.
Not only this slows down the mdoc(7) processing significantly, but it also
has an undesired (in this case) effect of disabling hyphenation within the
entire enclosed block.
2001-08-07 15:48:51 +00:00
Dima Dorfman
7ebcc426ef Remove whitespace at EOL. 2001-07-15 07:53:42 +00:00
Ruslan Ermilov
9fe48c6e8d mdoc(7) police: removed HISTORY info from the .Os call. 2001-07-10 11:04:34 +00:00
Matt Jacob
d389e86a04 Ian Dowse writes:
The original code was certainly broken; it knows that whereto is
	to be used for a sockaddr_in, so it should be declared as such.
	To support multiple protocols, there is also a sockaddr_storage
	struct that can be used; I don't think struct sockaddr is supposed
	to be used anywhere other than for casts and pointers.

Submitted by:	Ian Dowse <iedowse@maths.tcd.ie>
MFC after:	3 weeks
2001-07-07 19:09:21 +00:00
Matt Jacob
c77eed5304 Fix unaligned access faults on alpha.
This one is strange and goes against my rusty compiler knowledge.

The global declaration

struct sockaddr whereto;

produces for both i386 && alpha:

        .comm   whereto,16,1

which means common storage, byte aligned. Ahem. I though structs
were supposed to be ALDOUBLE always? I mean, w/o pragma packed?

Later on, this address is coerced to:

		to = (struct sockaddr_in *)&whereto;

Up until now, we've been fine on alpha because the address
just ended up aligned to a 4 byte boundary. Lately, though,
it end up as:

0000000120027b0f B whereto

And, tra la, you get unaligned access faults. The solution I picked, in
lieu of understanding what the compiler was doing, is to put whereto
as a union of a sockaddr and sockaddr_in. That's more formally correct
if somewhat awkward looking.
2001-07-07 05:01:06 +00:00
Robert Watson
e8bd25cef9 Modify ping so that it increases the send socket buffer size if the
user runs with privilege, allowing the sending of icmp packets with
larger size (up to 48k, the default receive buffer size in ping),
which is useful for network driver development testing, as well
as experimentation with fragmentation.

Reviewed by:	wpaul
2001-06-30 06:46:33 +00:00
Poul-Henning Kamp
ca517ad854 Add a -A option to ping which beeps when packets are lost.
PR:		11818
Submitted by:	Marc Evans marc@destek.net
2001-05-24 09:17:52 +00:00
Ruslan Ermilov
0a5779d45b - Backout botched attempt to introduce MANSECT feature.
- MAN[1-9] -> MAN.
2001-03-26 14:33:27 +00:00
Ruslan Ermilov
fe655281c5 Set the default manual section for sbin/ to 8. 2001-03-20 18:13:31 +00:00
Ruslan Ermilov
211bfbd228 Add new option -m which allows the user to set IP TTL. 2001-03-09 13:20:23 +00:00
Ruslan Ermilov
1252c1bb05 Prepare for mdoc(7)NG. 2000-12-18 15:16:24 +00:00
Ruslan Ermilov
7c7fb079b9 mdoc(7) police: use the new features of the Nm macro. 2000-11-20 16:52:27 +00:00
Kris Kennaway
ffd4007070 Format string paranoia 2000-11-19 13:30:36 +00:00
Yoshinobu Inoue
6ecbec7768 Use CMSG_LEN() to compute ping SCM_TIMESTAMP cmsg_len.
Without this, cmsg_len size should be smaller than necessary on alpha.
(Though, no obvious error was seen on ping time value on beast.)
2000-03-14 17:37:19 +00:00
Yoshinobu Inoue
7d0d8dc306 CMSG_XXX macros alignment fixes to follow RFC2292.
Approved by: jkh

Submitted by: Partly from tech@openbsd
Reviewed by: itojun
2000-03-03 11:13:12 +00:00
Sheldon Hearn
ef8f7ac935 Remove single-space hard sentence breaks. These degrade the quality
of the typeset output, tend to make diffs harder to read and provide
bad examples for new-comers to mdoc.
2000-03-01 11:27:47 +00:00
Yoshinobu Inoue
e870738008 ping -S option was missing from IPsec merge, so enable it again.
Approved by: jkh

Submitted by: Matthew Reimer <mreimer@vpop.net>
2000-02-08 05:07:50 +00:00
Bill Fumerola
bf113f1b05 Brucify:
add an upper limit to -t
	match the types of return values and the variables they are stuffed in
	make the man page and usage() a little more consistantly ugly
	less obfuscation.

Submitted by:	adrian, billf
2000-01-20 20:48:51 +00:00
Bill Fumerola
7237fd9478 Add '-t X' which times out after pinging for X seconds.
Submitted by:	adrian
2000-01-14 23:40:38 +00:00
Mike Smith
3285f64159 Don't try to include ipsec support if we are building for the install
floppy image.
2000-01-07 19:06:54 +00:00
Yoshinobu Inoue
9a4365d0e0 libipsec and IPsec related apps. (and some KAME related man pages)
Reviewed by: freebsd-arch, cvs-committers
Obtained from: KAME project
2000-01-06 12:40:54 +00:00
Pierre Beyssac
09333e7833 Make last commit bde-compliant:
- correct indentation
	- change data types for consistency with the rest of ping.c
	- create new variable separate from "answer" for clarity
1999-11-18 10:20:45 +00:00
Pierre Beyssac
3ec12efecc Fix aliasing bug causing in_cksum() to fail on odd packet sizes
due to compiler optimization.

PR:		bin/13292
Suggested by:	wollman
1999-11-15 20:04:53 +00:00
Peter Wemm
7f3dea244c $Id$ -> $FreeBSD$ 1999-08-28 00:22:10 +00:00
Chris Costello
d6636ad7b3 Re-add -Wmissing-prototypes to `COPTS'. I mistook -W for -Wno in this case. 1999-08-16 21:22:39 +00:00
Chris Costello
55cb3cb6be -Wmissing-prototypes is unnecessary here. There are no warnings produced
with this option disabled.
1999-08-16 08:13:17 +00:00
Stephen McKay
5e2cc0f4b0 Make flood ping flood again. It hasn't worked since 2.2.6. Make the "-l"
option work as described in the manual, not as another flood ping variant.

Once discussed to death with: bde
1999-05-07 14:38:48 +00:00
Warner Losh
ebe70c8f68 More egcs warning fixes:
o main returns int not void
	o use braces to avoid potentially ambiguous else

Note: The fix to natd is potentially functional in nature since I used
the indentation as the right thing rather than the struct semantics.
Someone more familiar with the code should double check me on this one.

Reviewed by: obrien and chuckr
1999-04-25 22:33:30 +00:00
Warner Losh
2faab3cddd Finish documenting -S src-addr change.
Forgotten by: me
Forgotten for: Far Too Long
Gently Reminded by: Ruslan Ermilov <ru@ucb.crimea.ua>
Submitted by: Ruslan Ermilov <ru@ucb.crimea.ua>
1999-02-19 07:40:59 +00:00
Warner Losh
99490ede3a Allow PINGing from any address on multihomed hosts
In the words of the submitter:
"The patch below allows to ping from any address on the multihomed host.
 The man page is also updated, the text was cutted from traceroute(8)."

Submitted by: Ruslan Ermilov
PR: 6832
1999-01-06 07:54:28 +00:00
Bruce Evans
0ed77db893 Fixed non-use of .Nm and hard line breaks in rev.1.16-1.17: 1998-11-29 13:20:04 +00:00
David E. O'Brien
be0cde6f10 Remove useless `BINOWN=root' now that it is the default. 1998-09-19 22:42:06 +00:00
Doug Rabson
69beb1913e Disable gcc's builtin memcpy for alpha since it doesn't cope with unaligned
regions properly and this triggers an unaligned access trap.
1998-09-05 15:11:47 +00:00
Matthew Dillon
0b0c1554a8 Updated manual page. Removed description of (now defunct) -c restrictions. 1998-08-27 16:34:38 +00:00
Dag-Erling Smørgrav
ce6f26dde3 Remove -c restrictions from previous commit. 1998-08-26 18:51:37 +00:00
Matthew Dillon
526f06b278 (well tested at BEST): -i option can now take FP values (e.g. -i 0.1),
extremely useful for networking testing.  Other options secured from
    user-level D.O.S. attacks.  -f, -s now root-only.  -i wait times < 1.0
    root-only.  -c count limited to 100 and defaults to 16 when ping run
    by non-root user.
1998-08-26 01:58:39 +00:00
Philippe Charnier
e345a80d5d Correct use of .Nm. Remove unused #includes. Use warn(). cosmetic in usage()
string.
Translate 0 sec 1000000 usec to 1 sec 0 usec.
1998-07-15 06:45:02 +00:00