diff --git a/lib/libc/stdtime/strftime.c b/lib/libc/stdtime/strftime.c index d19a70c42eb4..5f22b240cdf1 100644 --- a/lib/libc/stdtime/strftime.c +++ b/lib/libc/stdtime/strftime.c @@ -1,640 +1,642 @@ /* + * SPDX-License-Identifier: BSD-4.3TAHOE + * * Copyright (c) 1989 The Regents of the University of California. * All rights reserved. * * Copyright (c) 2011 The FreeBSD Foundation * * Portions of this software were developed by David Chisnall * under sponsorship from the FreeBSD Foundation. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * advertising materials, and other materials related to such * distribution and use acknowledge that the software was developed * by the University of California, Berkeley. The name of the * University may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef lint #ifndef NOID static const char elsieid[] = "@(#)strftime.3 8.3"; /* * Based on the UCB version with the ID appearing below. * This is ANSIish only when "multibyte character == plain character". */ #endif /* !defined NOID */ #endif /* !defined lint */ #include "namespace.h" #include "private.h" #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)strftime.c 5.4 (Berkeley) 3/14/89"; #endif /* LIBC_SCCS and not lint */ #include "tzfile.h" #include #include #include #include "un-namespace.h" #include "timelocal.h" static char * _add(const char *, char *, const char *); static char * _conv(int, const char *, char *, const char *, locale_t); static char * _fmt(const char *, const struct tm *, char *, const char *, int *, locale_t); static char * _yconv(int, int, int, int, char *, const char *, locale_t); extern char * tzname[]; #ifndef YEAR_2000_NAME #define YEAR_2000_NAME "CHECK_STRFTIME_FORMATS_FOR_TWO_DIGIT_YEARS" #endif /* !defined YEAR_2000_NAME */ #define IN_NONE 0 #define IN_SOME 1 #define IN_THIS 2 #define IN_ALL 3 #define PAD_DEFAULT 0 #define PAD_LESS 1 #define PAD_SPACE 2 #define PAD_ZERO 3 static const char fmt_padding[][4][5] = { /* DEFAULT, LESS, SPACE, ZERO */ #define PAD_FMT_MONTHDAY 0 #define PAD_FMT_HMS 0 #define PAD_FMT_CENTURY 0 #define PAD_FMT_SHORTYEAR 0 #define PAD_FMT_MONTH 0 #define PAD_FMT_WEEKOFYEAR 0 #define PAD_FMT_DAYOFMONTH 0 { "%02d", "%d", "%2d", "%02d" }, #define PAD_FMT_SDAYOFMONTH 1 #define PAD_FMT_SHMS 1 { "%2d", "%d", "%2d", "%02d" }, #define PAD_FMT_DAYOFYEAR 2 { "%03d", "%d", "%3d", "%03d" }, #define PAD_FMT_YEAR 3 { "%04d", "%d", "%4d", "%04d" } }; size_t strftime_l(char * __restrict s, size_t maxsize, const char * __restrict format, const struct tm * __restrict t, locale_t loc) { char * p; int warn; FIX_LOCALE(loc); tzset(); warn = IN_NONE; p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn, loc); #ifndef NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU if (warn != IN_NONE && getenv(YEAR_2000_NAME) != NULL) { (void) fprintf_l(stderr, loc, "\n"); if (format == NULL) (void) fputs("NULL strftime format ", stderr); else (void) fprintf_l(stderr, loc, "strftime format \"%s\" ", format); (void) fputs("yields only two digits of years in ", stderr); if (warn == IN_SOME) (void) fputs("some locales", stderr); else if (warn == IN_THIS) (void) fputs("the current locale", stderr); else (void) fputs("all locales", stderr); (void) fputs("\n", stderr); } #endif /* !defined NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU */ if (p == s + maxsize) return (0); *p = '\0'; return p - s; } size_t strftime(char * __restrict s, size_t maxsize, const char * __restrict format, const struct tm * __restrict t) { return strftime_l(s, maxsize, format, t, __get_locale()); } static char * _fmt(const char *format, const struct tm * const t, char *pt, const char * const ptlim, int *warnp, locale_t loc) { int Ealternative, Oalternative, PadIndex; struct lc_time_T *tptr = __get_current_time_locale(loc); for ( ; *format; ++format) { if (*format == '%') { Ealternative = 0; Oalternative = 0; PadIndex = PAD_DEFAULT; label: switch (*++format) { case '\0': --format; break; case 'A': pt = _add((t->tm_wday < 0 || t->tm_wday >= DAYSPERWEEK) ? "?" : tptr->weekday[t->tm_wday], pt, ptlim); continue; case 'a': pt = _add((t->tm_wday < 0 || t->tm_wday >= DAYSPERWEEK) ? "?" : tptr->wday[t->tm_wday], pt, ptlim); continue; case 'B': pt = _add((t->tm_mon < 0 || t->tm_mon >= MONSPERYEAR) ? "?" : (Oalternative ? tptr->alt_month : tptr->month)[t->tm_mon], pt, ptlim); continue; case 'b': case 'h': pt = _add((t->tm_mon < 0 || t->tm_mon >= MONSPERYEAR) ? "?" : tptr->mon[t->tm_mon], pt, ptlim); continue; case 'C': /* * %C used to do a... * _fmt("%a %b %e %X %Y", t); * ...whereas now POSIX 1003.2 calls for * something completely different. * (ado, 1993-05-24) */ pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 0, pt, ptlim, loc); continue; case 'c': { int warn2 = IN_SOME; pt = _fmt(tptr->c_fmt, t, pt, ptlim, &warn2, loc); if (warn2 == IN_ALL) warn2 = IN_THIS; if (warn2 > *warnp) *warnp = warn2; } continue; case 'D': pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp, loc); continue; case 'd': pt = _conv(t->tm_mday, fmt_padding[PAD_FMT_DAYOFMONTH][PadIndex], pt, ptlim, loc); continue; case 'E': if (Ealternative || Oalternative) break; Ealternative++; goto label; case 'O': /* * C99 locale modifiers. * The sequences * %Ec %EC %Ex %EX %Ey %EY * %Od %oe %OH %OI %Om %OM * %OS %Ou %OU %OV %Ow %OW %Oy * are supposed to provide alternate * representations. * * FreeBSD extension * %OB */ if (Ealternative || Oalternative) break; Oalternative++; goto label; case 'e': pt = _conv(t->tm_mday, fmt_padding[PAD_FMT_SDAYOFMONTH][PadIndex], pt, ptlim, loc); continue; case 'F': pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp, loc); continue; case 'H': pt = _conv(t->tm_hour, fmt_padding[PAD_FMT_HMS][PadIndex], pt, ptlim, loc); continue; case 'I': pt = _conv((t->tm_hour % 12) ? (t->tm_hour % 12) : 12, fmt_padding[PAD_FMT_HMS][PadIndex], pt, ptlim, loc); continue; case 'j': pt = _conv(t->tm_yday + 1, fmt_padding[PAD_FMT_DAYOFYEAR][PadIndex], pt, ptlim, loc); continue; case 'k': /* * This used to be... * _conv(t->tm_hour % 12 ? * t->tm_hour % 12 : 12, 2, ' '); * ...and has been changed to the below to * match SunOS 4.1.1 and Arnold Robbins' * strftime version 3.0. That is, "%k" and * "%l" have been swapped. * (ado, 1993-05-24) */ pt = _conv(t->tm_hour, fmt_padding[PAD_FMT_SHMS][PadIndex], pt, ptlim, loc); continue; #ifdef KITCHEN_SINK case 'K': /* ** After all this time, still unclaimed! */ pt = _add("kitchen sink", pt, ptlim); continue; #endif /* defined KITCHEN_SINK */ case 'l': /* * This used to be... * _conv(t->tm_hour, 2, ' '); * ...and has been changed to the below to * match SunOS 4.1.1 and Arnold Robbin's * strftime version 3.0. That is, "%k" and * "%l" have been swapped. * (ado, 1993-05-24) */ pt = _conv((t->tm_hour % 12) ? (t->tm_hour % 12) : 12, fmt_padding[PAD_FMT_SHMS][PadIndex], pt, ptlim, loc); continue; case 'M': pt = _conv(t->tm_min, fmt_padding[PAD_FMT_HMS][PadIndex], pt, ptlim, loc); continue; case 'm': pt = _conv(t->tm_mon + 1, fmt_padding[PAD_FMT_MONTH][PadIndex], pt, ptlim, loc); continue; case 'n': pt = _add("\n", pt, ptlim); continue; case 'p': pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ? tptr->pm : tptr->am, pt, ptlim); continue; case 'R': pt = _fmt("%H:%M", t, pt, ptlim, warnp, loc); continue; case 'r': pt = _fmt(tptr->ampm_fmt, t, pt, ptlim, warnp, loc); continue; case 'S': pt = _conv(t->tm_sec, fmt_padding[PAD_FMT_HMS][PadIndex], pt, ptlim, loc); continue; case 's': { struct tm tm; char buf[INT_STRLEN_MAXIMUM( time_t) + 1]; time_t mkt; tm = *t; mkt = timeoff(&tm, t->tm_gmtoff); if (TYPE_SIGNED(time_t)) (void) sprintf_l(buf, loc, "%ld", (long) mkt); else (void) sprintf_l(buf, loc, "%lu", (unsigned long) mkt); pt = _add(buf, pt, ptlim); } continue; case 'T': pt = _fmt("%H:%M:%S", t, pt, ptlim, warnp, loc); continue; case 't': pt = _add("\t", pt, ptlim); continue; case 'U': pt = _conv((t->tm_yday + DAYSPERWEEK - t->tm_wday) / DAYSPERWEEK, fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex], pt, ptlim, loc); continue; case 'u': /* * From Arnold Robbins' strftime version 3.0: * "ISO 8601: Weekday as a decimal number * [1 (Monday) - 7]" * (ado, 1993-05-24) */ pt = _conv((t->tm_wday == 0) ? DAYSPERWEEK : t->tm_wday, "%d", pt, ptlim, loc); continue; case 'V': /* ISO 8601 week number */ case 'G': /* ISO 8601 year (four digits) */ case 'g': /* ISO 8601 year (two digits) */ /* * From Arnold Robbins' strftime version 3.0: "the week number of the * year (the first Monday as the first day of week 1) as a decimal number * (01-53)." * (ado, 1993-05-24) * * From "http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html" by Markus Kuhn: * "Week 01 of a year is per definition the first week which has the * Thursday in this year, which is equivalent to the week which contains * the fourth day of January. In other words, the first week of a new year * is the week which has the majority of its days in the new year. Week 01 * might also contain days from the previous year and the week before week * 01 of a year is the last week (52 or 53) of the previous year even if * it contains days from the new year. A week starts with Monday (day 1) * and ends with Sunday (day 7). For example, the first week of the year * 1997 lasts from 1996-12-30 to 1997-01-05..." * (ado, 1996-01-02) */ { int year; int base; int yday; int wday; int w; year = t->tm_year; base = TM_YEAR_BASE; yday = t->tm_yday; wday = t->tm_wday; for ( ; ; ) { int len; int bot; int top; len = isleap_sum(year, base) ? DAYSPERLYEAR : DAYSPERNYEAR; /* * What yday (-3 ... 3) does * the ISO year begin on? */ bot = ((yday + 11 - wday) % DAYSPERWEEK) - 3; /* * What yday does the NEXT * ISO year begin on? */ top = bot - (len % DAYSPERWEEK); if (top < -3) top += DAYSPERWEEK; top += len; if (yday >= top) { ++base; w = 1; break; } if (yday >= bot) { w = 1 + ((yday - bot) / DAYSPERWEEK); break; } --base; yday += isleap_sum(year, base) ? DAYSPERLYEAR : DAYSPERNYEAR; } #ifdef XPG4_1994_04_09 if ((w == 52 && t->tm_mon == TM_JANUARY) || (w == 1 && t->tm_mon == TM_DECEMBER)) w = 53; #endif /* defined XPG4_1994_04_09 */ if (*format == 'V') pt = _conv(w, fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex], pt, ptlim, loc); else if (*format == 'g') { *warnp = IN_ALL; pt = _yconv(year, base, 0, 1, pt, ptlim, loc); } else pt = _yconv(year, base, 1, 1, pt, ptlim, loc); } continue; case 'v': /* * From Arnold Robbins' strftime version 3.0: * "date as dd-bbb-YYYY" * (ado, 1993-05-24) */ pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp, loc); continue; case 'W': pt = _conv((t->tm_yday + DAYSPERWEEK - (t->tm_wday ? (t->tm_wday - 1) : (DAYSPERWEEK - 1))) / DAYSPERWEEK, fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex], pt, ptlim, loc); continue; case 'w': pt = _conv(t->tm_wday, "%d", pt, ptlim, loc); continue; case 'X': pt = _fmt(tptr->X_fmt, t, pt, ptlim, warnp, loc); continue; case 'x': { int warn2 = IN_SOME; pt = _fmt(tptr->x_fmt, t, pt, ptlim, &warn2, loc); if (warn2 == IN_ALL) warn2 = IN_THIS; if (warn2 > *warnp) *warnp = warn2; } continue; case 'y': *warnp = IN_ALL; pt = _yconv(t->tm_year, TM_YEAR_BASE, 0, 1, pt, ptlim, loc); continue; case 'Y': pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 1, pt, ptlim, loc); continue; case 'Z': #ifdef TM_ZONE if (t->TM_ZONE != NULL) pt = _add(t->TM_ZONE, pt, ptlim); else #endif /* defined TM_ZONE */ if (t->tm_isdst >= 0) pt = _add(tzname[t->tm_isdst != 0], pt, ptlim); /* * C99 says that %Z must be replaced by the * empty string if the time zone is not * determinable. */ continue; case 'z': { int diff; char const * sign; if (t->tm_isdst < 0) continue; #ifdef TM_GMTOFF diff = t->TM_GMTOFF; #else /* !defined TM_GMTOFF */ /* * C99 says that the UTC offset must * be computed by looking only at * tm_isdst. This requirement is * incorrect, since it means the code * must rely on magic (in this case * altzone and timezone), and the * magic might not have the correct * offset. Doing things correctly is * tricky and requires disobeying C99; * see GNU C strftime for details. * For now, punt and conform to the * standard, even though it's incorrect. * * C99 says that %z must be replaced by the * empty string if the time zone is not * determinable, so output nothing if the * appropriate variables are not available. */ if (t->tm_isdst == 0) #ifdef USG_COMPAT diff = -timezone; #else /* !defined USG_COMPAT */ continue; #endif /* !defined USG_COMPAT */ else #ifdef ALTZONE diff = -altzone; #else /* !defined ALTZONE */ continue; #endif /* !defined ALTZONE */ #endif /* !defined TM_GMTOFF */ if (diff < 0) { sign = "-"; diff = -diff; } else sign = "+"; pt = _add(sign, pt, ptlim); diff /= SECSPERMIN; diff = (diff / MINSPERHOUR) * 100 + (diff % MINSPERHOUR); pt = _conv(diff, fmt_padding[PAD_FMT_YEAR][PadIndex], pt, ptlim, loc); } continue; case '+': pt = _fmt(tptr->date_fmt, t, pt, ptlim, warnp, loc); continue; case '-': if (PadIndex != PAD_DEFAULT) break; PadIndex = PAD_LESS; goto label; case '_': if (PadIndex != PAD_DEFAULT) break; PadIndex = PAD_SPACE; goto label; case '0': if (PadIndex != PAD_DEFAULT) break; PadIndex = PAD_ZERO; goto label; case '%': /* * X311J/88-090 (4.12.3.5): if conversion char is * undefined, behavior is undefined. Print out the * character itself as printf(3) also does. */ default: break; } } if (pt == ptlim) break; *pt++ = *format; } return (pt); } static char * _conv(const int n, const char * const format, char * const pt, const char * const ptlim, locale_t loc) { char buf[INT_STRLEN_MAXIMUM(int) + 1]; (void) sprintf_l(buf, loc, format, n); return _add(buf, pt, ptlim); } static char * _add(const char *str, char *pt, const char * const ptlim) { while (pt < ptlim && (*pt = *str++) != '\0') ++pt; return (pt); } /* * POSIX and the C Standard are unclear or inconsistent about * what %C and %y do if the year is negative or exceeds 9999. * Use the convention that %C concatenated with %y yields the * same output as %Y, and that %Y contains at least 4 bytes, * with more only if necessary. */ static char * _yconv(const int a, const int b, const int convert_top, const int convert_yy, char *pt, const char * const ptlim, locale_t loc) { register int lead; register int trail; #define DIVISOR 100 trail = a % DIVISOR + b % DIVISOR; lead = a / DIVISOR + b / DIVISOR + trail / DIVISOR; trail %= DIVISOR; if (trail < 0 && lead > 0) { trail += DIVISOR; --lead; } else if (lead < 0 && trail > 0) { trail -= DIVISOR; ++lead; } if (convert_top) { if (lead == 0 && trail < 0) pt = _add("-0", pt, ptlim); else pt = _conv(lead, "%02d", pt, ptlim, loc); } if (convert_yy) pt = _conv(((trail < 0) ? -trail : trail), "%02d", pt, ptlim, loc); return (pt); } diff --git a/usr.sbin/cron/cron/popen.c b/usr.sbin/cron/cron/popen.c index dfa90252fe22..09313d594d7d 100644 --- a/usr.sbin/cron/cron/popen.c +++ b/usr.sbin/cron/cron/popen.c @@ -1,239 +1,241 @@ /* + * SPDX-License-Identifier: BSD-4.3TAHOE + * * Copyright (c) 1988 The Regents of the University of California. * All rights reserved. * * This code is derived from software written by Ken Arnold and * published in UNIX Review, Vol. 6, No. 8. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * advertising materials, and other materials related to such * distribution and use acknowledge that the software was developed * by the University of California, Berkeley. The name of the * University may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ /* this came out of the ftpd sources; it's been modified to avoid the * globbing stuff since we don't need it. also execvp instead of execv. */ #ifndef lint static const char rcsid[] = "$Id: popen.c,v 1.3 1998/08/14 00:32:41 vixie Exp $"; #if 0 static const char sccsid[] = "@(#)popen.c 5.7 (Berkeley) 2/14/89"; #endif #endif /* not lint */ #include "cron.h" #if defined(LOGIN_CAP) # include #endif #define MAX_ARGS 100 #define WANT_GLOBBING 0 /* * Special version of popen which avoids call to shell. This insures no one * may create a pipe to a hidden program as a side effect of a list or dir * command. */ static PID_T *pids; static int fds; FILE * cron_popen(char *program, char *type, entry *e, PID_T *pidptr) { char *cp; FILE *iop; int argc, pdes[2]; PID_T pid; char *usernm; char *argv[MAX_ARGS + 1]; # if defined(LOGIN_CAP) struct passwd *pwd; login_cap_t *lc; # endif #if WANT_GLOBBING char **pop, *vv[2]; int gargc; char *gargv[1000]; extern char **glob(), **copyblk(); #endif if ((*type != 'r' && *type != 'w') || type[1] != '\0') return (NULL); if (!pids) { if ((fds = sysconf(_SC_OPEN_MAX)) <= 0) return (NULL); if (!(pids = calloc(fds, sizeof(PID_T)))) return (NULL); } if (pipe(pdes) < 0) return (NULL); /* break up string into pieces */ for (argc = 0, cp = program; argc < MAX_ARGS; cp = NULL) if (!(argv[argc++] = strtok(cp, " \t\n"))) break; argv[MAX_ARGS] = NULL; #if WANT_GLOBBING /* glob each piece */ gargv[0] = argv[0]; for (gargc = argc = 1; argv[argc]; argc++) { if (!(pop = glob(argv[argc]))) { /* globbing failed */ vv[0] = argv[argc]; vv[1] = NULL; pop = copyblk(vv); } argv[argc] = (char *)pop; /* save to free later */ while (*pop && gargc < 1000) gargv[gargc++] = *pop++; } gargv[gargc] = NULL; #endif iop = NULL; switch(pid = fork()) { case -1: /* error */ (void)close(pdes[0]); (void)close(pdes[1]); goto pfree; /* NOTREACHED */ case 0: /* child */ if (e != NULL) { #ifdef SYSLOG closelog(); #endif /* get new pgrp, void tty, etc. */ (void) setsid(); } if (*type == 'r') { /* Do not share our parent's stdin */ (void)close(0); (void)open(_PATH_DEVNULL, O_RDWR); if (pdes[1] != 1) { dup2(pdes[1], 1); dup2(pdes[1], 2); /* stderr, too! */ (void)close(pdes[1]); } (void)close(pdes[0]); } else { if (pdes[0] != 0) { dup2(pdes[0], 0); (void)close(pdes[0]); } /* Hack: stdout gets revoked */ (void)close(1); (void)open(_PATH_DEVNULL, O_RDWR); (void)close(2); (void)open(_PATH_DEVNULL, O_RDWR); (void)close(pdes[1]); } if (e != NULL) { /* Set user's entire context, but skip the environment * as cron provides a separate interface for this */ usernm = env_get("LOGNAME", e->envp); # if defined(LOGIN_CAP) if ((pwd = getpwnam(usernm)) == NULL) pwd = getpwuid(e->uid); lc = NULL; if (pwd != NULL) { pwd->pw_gid = e->gid; if (e->class != NULL) lc = login_getclass(e->class); } if (pwd && setusercontext(lc, pwd, e->uid, LOGIN_SETALL & ~(LOGIN_SETPATH|LOGIN_SETENV)) == 0) (void) endpwent(); else { /* fall back to the old method */ (void) endpwent(); # endif /* * Set our directory, uid and gid. Set gid * first since once we set uid, we've lost * root privileges. */ if (setgid(e->gid) != 0) _exit(ERROR_EXIT); # if defined(BSD) if (initgroups(usernm, e->gid) != 0) _exit(ERROR_EXIT); # endif if (setlogin(usernm) != 0) _exit(ERROR_EXIT); if (setuid(e->uid) != 0) _exit(ERROR_EXIT); /* we aren't root after this..*/ #if defined(LOGIN_CAP) } if (lc != NULL) login_close(lc); #endif chdir(env_get("HOME", e->envp)); } #if WANT_GLOBBING execvp(gargv[0], gargv); #else execvp(argv[0], argv); #endif _exit(1); } /* parent; assume fdopen can't fail... */ if (*type == 'r') { iop = fdopen(pdes[0], type); (void)close(pdes[1]); } else { iop = fdopen(pdes[1], type); (void)close(pdes[0]); } pids[fileno(iop)] = pid; pfree: #if WANT_GLOBBING for (argc = 1; argv[argc] != NULL; argc++) { /* blkfree((char **)argv[argc]); */ free((char *)argv[argc]); } #endif *pidptr = pid; return (iop); } int cron_pclose(FILE *iop) { int fdes; int omask; WAIT_T stat_loc; PID_T pid; /* * pclose returns -1 if stream is not associated with a * `popened' command, or, if already `pclosed'. */ if (pids == 0 || pids[fdes = fileno(iop)] == 0) return (-1); (void)fclose(iop); omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP)); while ((pid = wait(&stat_loc)) != pids[fdes] && pid != -1) ; (void)sigsetmask(omask); pids[fdes] = 0; return (pid == -1 ? -1 : WEXITSTATUS(stat_loc)); } diff --git a/usr.sbin/ppp/arp.c b/usr.sbin/ppp/arp.c index fa45502f488a..3502d714a561 100644 --- a/usr.sbin/ppp/arp.c +++ b/usr.sbin/ppp/arp.c @@ -1,316 +1,316 @@ /* * sys-bsd.c - System-dependent procedures for setting up * PPP interfaces on bsd-4.4-ish systems (including 386BSD, NetBSD, etc.) * - * SPDX-License-Identifier: BSD-1-Clause + * SPDX-License-Identifier: BSD-4.3TAHOE * * Copyright (c) 1989 Carnegie Mellon University. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * advertising materials, and other materials related to such * distribution and use acknowledge that the software was developed * by Carnegie Mellon University. The name of the * University may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ /* * TODO: */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "layer.h" #include "mbuf.h" #include "log.h" #include "id.h" #include "timer.h" #include "fsm.h" #include "defs.h" #include "iplist.h" #include "throughput.h" #include "slcompress.h" #include "lqr.h" #include "hdlc.h" #include "ncpaddr.h" #include "ipcp.h" #include "ipv6cp.h" #include "descriptor.h" #include "lcp.h" #include "ccp.h" #include "link.h" #include "mp.h" #include "ncp.h" #include "filter.h" #ifndef NORADIUS #include "radius.h" #endif #include "bundle.h" #include "iface.h" #include "arp.h" /* * SET_SA_FAMILY - set the sa_family field of a struct sockaddr, * if it exists. */ #define SET_SA_FAMILY(addr, family) \ memset((char *) &(addr), '\0', sizeof(addr)); \ addr.sa_family = (family); \ addr.sa_len = sizeof(addr); #if RTM_VERSION >= 3 /* * arp_SetProxy - Make a proxy ARP entry for the peer. */ static struct { struct rt_msghdr hdr; struct sockaddr_in dst; struct sockaddr_dl hwa; char extra[128]; } arpmsg; static int arp_ProxySub(struct bundle *bundle, struct in_addr addr, int add) { int routes; /* * Get the hardware address of an interface on the same subnet as our local * address. */ memset(&arpmsg, 0, sizeof arpmsg); if (!arp_EtherAddr(addr, &arpmsg.hwa, 0)) { log_Printf(LogWARN, "%s: Cannot determine ethernet address for proxy ARP\n", inet_ntoa(addr)); return 0; } routes = ID0socket(PF_ROUTE, SOCK_RAW, AF_INET); if (routes < 0) { log_Printf(LogERROR, "arp_SetProxy: opening routing socket: %s\n", strerror(errno)); return 0; } arpmsg.hdr.rtm_type = add ? RTM_ADD : RTM_DELETE; arpmsg.hdr.rtm_flags = RTF_ANNOUNCE | RTF_HOST | RTF_STATIC | RTF_LLDATA; arpmsg.hdr.rtm_version = RTM_VERSION; arpmsg.hdr.rtm_seq = ++bundle->routing_seq; arpmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY; arpmsg.hdr.rtm_inits = RTV_EXPIRE; arpmsg.dst.sin_len = sizeof(struct sockaddr_in); arpmsg.dst.sin_family = AF_INET; arpmsg.dst.sin_addr.s_addr = addr.s_addr; arpmsg.hdr.rtm_msglen = (char *) &arpmsg.hwa - (char *) &arpmsg + arpmsg.hwa.sdl_len; if (ID0write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0 && !(!add && errno == ESRCH)) { log_Printf(LogERROR, "%s proxy arp entry %s: %s\n", add ? "Add" : "Delete", inet_ntoa(addr), strerror(errno)); close(routes); return 0; } close(routes); return 1; } int arp_SetProxy(struct bundle *bundle, struct in_addr addr) { return (arp_ProxySub(bundle, addr, 1)); } /* * arp_ClearProxy - Delete the proxy ARP entry for the peer. */ int arp_ClearProxy(struct bundle *bundle, struct in_addr addr) { return (arp_ProxySub(bundle, addr, 0)); } #else /* RTM_VERSION */ /* * arp_SetProxy - Make a proxy ARP entry for the peer. */ int arp_SetProxy(struct bundle *bundle, struct in_addr addr, int s) { struct arpreq arpreq; struct { struct sockaddr_dl sdl; char space[128]; } dls; memset(&arpreq, '\0', sizeof arpreq); /* * Get the hardware address of an interface on the same subnet as our local * address. */ if (!arp_EtherAddr(addr, &dls.sdl, 1)) { log_Printf(LOG_PHASE_BIT, "Cannot determine ethernet address for " "proxy ARP\n"); return 0; } arpreq.arp_ha.sa_len = sizeof(struct sockaddr); arpreq.arp_ha.sa_family = AF_UNSPEC; memcpy(arpreq.arp_ha.sa_data, LLADDR(&dls.sdl), dls.sdl.sdl_alen); SET_SA_FAMILY(arpreq.arp_pa, AF_INET); ((struct sockaddr_in *)&arpreq.arp_pa)->sin_addr.s_addr = addr.s_addr; arpreq.arp_flags = ATF_PERM | ATF_PUBL; if (ID0ioctl(s, SIOCSARP, (caddr_t) & arpreq) < 0) { log_Printf(LogERROR, "arp_SetProxy: ioctl(SIOCSARP): %s\n", strerror(errno)); return 0; } return 1; } /* * arp_ClearProxy - Delete the proxy ARP entry for the peer. */ int arp_ClearProxy(struct bundle *bundle, struct in_addr addr, int s) { struct arpreq arpreq; memset(&arpreq, '\0', sizeof arpreq); SET_SA_FAMILY(arpreq.arp_pa, AF_INET); ((struct sockaddr_in *)&arpreq.arp_pa)->sin_addr.s_addr = addr.s_addr; if (ID0ioctl(s, SIOCDARP, (caddr_t) & arpreq) < 0) { log_Printf(LogERROR, "arp_ClearProxy: ioctl(SIOCDARP): %s\n", strerror(errno)); return 0; } return 1; } #endif /* RTM_VERSION */ /* * arp_EtherAddr - get the hardware address of an interface on the * the same subnet as ipaddr. */ int arp_EtherAddr(struct in_addr ipaddr, struct sockaddr_dl *hwaddr, int verbose) { int mib[6], skip; size_t needed; char *buf, *ptr, *end; struct if_msghdr *ifm; struct ifa_msghdr *ifam; struct sockaddr_dl *dl; struct sockaddr *sa[RTAX_MAX]; mib[0] = CTL_NET; mib[1] = PF_ROUTE; mib[2] = 0; mib[3] = 0; mib[4] = NET_RT_IFLIST; mib[5] = 0; if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) { log_Printf(LogERROR, "arp_EtherAddr: sysctl: estimate: %s\n", strerror(errno)); return 0; } if ((buf = malloc(needed)) == NULL) return 0; if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) { free(buf); return 0; } end = buf + needed; ptr = buf; while (ptr < end) { ifm = (struct if_msghdr *)ptr; /* On if_msghdr */ if (ifm->ifm_type != RTM_IFINFO) break; dl = (struct sockaddr_dl *)(ifm + 1); /* Single _dl at end */ skip = (ifm->ifm_flags & (IFF_UP | IFF_BROADCAST | IFF_POINTOPOINT | IFF_NOARP | IFF_LOOPBACK)) != (IFF_UP | IFF_BROADCAST); ptr += ifm->ifm_msglen; /* First ifa_msghdr */ while (ptr < end) { ifam = (struct ifa_msghdr *)ptr; /* Next ifa_msghdr (alias) */ if (ifam->ifam_type != RTM_NEWADDR) /* finished ? */ break; ptr += ifam->ifam_msglen; if (skip || (ifam->ifam_addrs & (RTA_NETMASK|RTA_IFA)) != (RTA_NETMASK|RTA_IFA)) continue; /* Found a candidate. Do the addresses match ? */ if (log_IsKept(LogDEBUG) && ptr == (char *)ifm + ifm->ifm_msglen + ifam->ifam_msglen) log_Printf(LogDEBUG, "%.*s interface is a candidate for proxy\n", dl->sdl_nlen, dl->sdl_data); iface_ParseHdr(ifam, sa); if (sa[RTAX_IFA]->sa_family == AF_INET) { struct sockaddr_in *ifa, *netmask; ifa = (struct sockaddr_in *)sa[RTAX_IFA]; netmask = (struct sockaddr_in *)sa[RTAX_NETMASK]; if (log_IsKept(LogDEBUG)) { char a[16]; strncpy(a, inet_ntoa(netmask->sin_addr), sizeof a - 1); a[sizeof a - 1] = '\0'; log_Printf(LogDEBUG, "Check addr %s, mask %s\n", inet_ntoa(ifa->sin_addr), a); } if ((ifa->sin_addr.s_addr & netmask->sin_addr.s_addr) == (ipaddr.s_addr & netmask->sin_addr.s_addr)) { log_Printf(verbose ? LogPHASE : LogDEBUG, "Found interface %.*s for %s\n", dl->sdl_nlen, dl->sdl_data, inet_ntoa(ipaddr)); memcpy(hwaddr, dl, dl->sdl_len); free(buf); return 1; } } } } free(buf); return 0; } diff --git a/usr.sbin/traceroute/traceroute.8 b/usr.sbin/traceroute/traceroute.8 index 6b46ec05a1c9..2ed3149152e3 100644 --- a/usr.sbin/traceroute/traceroute.8 +++ b/usr.sbin/traceroute/traceroute.8 @@ -1,468 +1,471 @@ +.\" +.\" SPDX-License-Identifier: BSD-4.3TAHOE +.\" .\" Copyright (c) 1989, 1995, 1996, 1997, 1999, 2000 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms are permitted .\" provided that the above copyright notice and this paragraph are .\" duplicated in all such forms and that any documentation, .\" advertising materials, and other materials related to such .\" distribution and use acknowledge that the software was developed .\" by the University of California, Berkeley. The name of the .\" University may not be used to endorse or promote products derived .\" from this software without specific prior written permission. .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR .\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED .\" WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" .\" $Id: traceroute.8,v 1.19 2000/09/21 08:44:19 leres Exp $ .\" $FreeBSD$ .\" .Dd May 14, 2025 .Dt TRACEROUTE 8 .Os .Sh NAME .Nm traceroute .Nd "print the route packets take to network host" .Sh SYNOPSIS .Nm .Bk -words .Op Fl adDeEFISnrvx .Op Fl f Ar first_ttl .Op Fl g Ar gateway .Op Fl M Ar first_ttl .Op Fl m Ar max_ttl .Op Fl P Ar proto .Op Fl p Ar port .Op Fl q Ar nprobes .Op Fl s Ar src_addr .Op Fl t Ar tos .Op Fl w Ar waittime .Op Fl A Ar as_server .Op Fl z Ar pausemsecs .Ar host .Op Ar packetlen .Ek .Sh DESCRIPTION The Internet is a large and complex aggregation of network hardware, connected together by gateways. Tracking the route one's packets follow (or finding the miscreant gateway that's discarding your packets) can be difficult. .Nm utilizes the IP protocol `time to live' field and attempts to elicit an ICMP TIME_EXCEEDED response from each gateway along the path to some host. .Pp The only mandatory parameter is the destination host name or IP number. The default probe datagram length is 40 bytes, but this may be increased by specifying a packet length (in bytes) after the destination host name. .Pp Other options are: .Bl -tag -width Ds .It Fl a Turn on AS# lookups for each hop encountered. .It Fl A Ar as_server Turn on AS# lookups and use the given server instead of the default. .It Fl e Firewall evasion mode. Use fixed destination ports for UDP, UDP-Lite, TCP and SCTP probes. The destination port does NOT increment with each packet sent. .It Fl E Detect ECN bleaching. Set the .Em IPTOS_ECN_ECT1 Explicit Congestion Notification (ECN) bits .Pq Dv 01 , and report if the hop has bleached .Pq Dv 00 or mangled .Pq Dv 10 them, or if it is experiencing congestion .Pq Dv 11 . Otherwise, report that it passed the bits appropriately. If .Fl t is also specified, the corresponding ECN bits will be replaced. .It Fl f Ar first_ttl Set the initial time-to-live used in the first outgoing probe packet. .It Fl F Set the "don't fragment" bit. .It Fl d Enable socket level debugging. .It Fl D When an ICMP response to our probe datagram is received, print the differences between the transmitted packet and the packet quoted by the ICMP response. A key showing the location of fields within the transmitted packet is printed, followed by the original packet in hex, followed by the quoted packet in hex. Bytes that are unchanged in the quoted packet are shown as underscores. Note, the IP checksum and the TTL of the quoted packet are not expected to match. By default, only one probe per hop is sent with this option. .It Fl g Ar gateway Specify a loose source route gateway (8 maximum). .It Fl i Ar iface Specify a network interface to obtain the source IP address for outgoing probe packets. This is normally only useful on a multi-homed host. (See the .Fl s flag for another way to do this.) .It Fl I Use ICMP ECHO instead of UDP datagrams. (A synonym for "-P icmp"). .It Fl M Ar first_ttl Set the initial time-to-live value used in outgoing probe packets. The default is 1, i.e., start with the first hop. .It Fl m Ar max_ttl Set the max time-to-live (max number of hops) used in outgoing probe packets. The default is the value of the .Va net.inet.ip.ttl .Xr sysctl 8 (the same default used for TCP connections). .It Fl n Print hop addresses numerically rather than symbolically and numerically (saves a nameserver address-to-name lookup for each gateway found on the path). .It Fl P Ar proto Send packets of specified IP protocol. The currently supported protocols are: UDP, UDP-Lite, TCP, SCTP, GRE and ICMP. Other protocols may also be specified (either by name or by number), though .Nm does not implement any special knowledge of their packet formats. This option is useful for determining which router along a path may be blocking packets based on IP protocol number. But see BUGS below. .It Fl p Ar port Protocol specific. For UDP, UDP-Lite, TCP and SCTP, sets the base .Ar port number used in probes (default is 33434). Traceroute hopes that nothing is listening on UDP ports (or UDP-Lite ports if used by .Nm and supported by the peer) .Em port + 1 to .Em port + (max_ttl - first_ttl + 1) * nprobes at the destination host (so an ICMP PORT_UNREACHABLE message will be returned to terminate the route tracing). If something is listening on a port in the default range, this option can be used to pick an unused port range. .It Fl P Ar proto Use packets of specified IP protocol when sending probes. The .Ar proto argument may be one of the following: .Bl -tag -width Ar udplite .It Ar udp Use .Xr udp 4 packets. This is the default. .It Ar icmp Use .Xr icmp 4 .Dq echo request packets. .It Ar udplite Use .Xr udplite 4 packets. .It Ar tcp Use .Xr tcp 4 .Dq SYN packets. This will cause a successful traceroute to end with no response (i.e., a .Dq * response) since .Nm does not know how to detect the RST or SYN+ACK response from the destination host. .It Ar sctp Use .Xr sctp 4 packets. The .Ar packetlen argument must be a multiple of 4. SCTP probes will be constructed as SCTP .Dq INIT chunks, unless the packet length is too small, in which case the probes will be SCTP .Dq SHUTDOWN-ACK chunks followed by zero or one .Dq PAD chunks. .It Ar gre Use .Xr gre 4 packets. The GRE packets will be constructed as if they contain a PPTP (Point-to-Point Tunneling Protocol) payload. .El .Pp Other protocols may also be specified, either by number or by name (see .Xr protocols 5 ) , though .Nm does not implement any special knowledge of their packet formats. This option is useful for determining which router along a path may be blocking packets based on IP protocol number. But see BUGS below. .It Fl q Ar nprobes Set the number of probes per hop (default is 3, unless .Fl D is specified, when it is 1). .It Fl r Bypass the normal routing tables and send directly to a host on an attached network. If the host is not on a directly-attached network, an error is returned. This option can be used to ping a local host through an interface that has no route through it (e.g., after the interface was dropped by .Xr routed 8 . .It Fl s Ar src_addr Use the following IP address (which usually is given as an IP number, not a hostname) as the source address in outgoing probe packets. On multi-homed hosts (those with more than one IP address), this option can be used to force the source address to be something other than the IP address of the interface the probe packet is sent on. If the IP address is not one of this machine's interface addresses, an error is returned and nothing is sent. (See the .Fl i flag for another way to do this.) .It Fl S Print a summary of how many probes were not answered for each hop. .It Fl t Ar tos Set the .Em type-of-service in probe packets to the following value (default zero). The value must be a decimal integer in the range 0 to 255. This option can be used to see if different types-of-service result in different paths. The upper six bits are the Differentiated Services Codepoint (RFC4594). The lower two bits are the Explicit Congestion Notification field (RFC3168). .It Fl v Verbose output. Received ICMP packets other than .Dv TIME_EXCEEDED and .Dv UNREACHABLE Ns s are listed. .It Fl w Ar waittime Set the time (in seconds) to wait for a response to a probe (default 5 sec.). .It Fl x Toggle ip checksums. Normally, this prevents traceroute from calculating ip checksums. In some cases, the operating system can overwrite parts of the outgoing packet but not recalculate the checksum (so in some cases the default is to not calculate checksums and using .Fl x causes them to be calculated). Note that checksums are usually required for the last hop when using ICMP ECHO probes .Pq Fl I . So they are always calculated when using ICMP. .It Fl z Ar pausemsecs Set the time (in milliseconds) to pause between probes (default 0). Some systems such as Solaris and routers such as Ciscos rate limit icmp messages. A good value to use with this this is 500 (e.g. 1/2 second). .El .Pp This program attempts to trace the route an IP packet would follow to some internet host by launching UDP probe packets with a small ttl (time to live) then listening for an ICMP "time exceeded" reply from a gateway. We start our probes with a ttl of one and increase by one until we get an ICMP "port unreachable" (which means we got to "host") or hit a max (which defaults to the amount of hops specified by the .Va net.inet.ip.ttl .Xr sysctl 8 and can be changed with the .Fl m flag). Three probes (change with .Fl q flag) are sent at each ttl setting and a line is printed showing the ttl, address of the gateway and round trip time of each probe. If the probe answers come from different gateways, the address of each responding system will be printed. If there is no response within a 5 sec. timeout interval (changed with the .Fl w flag), a "*" is printed for that probe. .Pp We don't want the destination host to process the UDP probe packets so the destination port is set to an unlikely value (if some clod on the destination is using that value, it can be changed with the .Fl p flag). .Pp A sample use and output might be: .Bd -literal -offset 4n % traceroute nis.nsf.net. traceroute to nis.nsf.net (35.1.1.48), 64 hops max, 38 byte packet 1 helios.ee.lbl.gov (128.3.112.1) 19 ms 19 ms 0 ms 2 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 39 ms 19 ms 3 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 39 ms 19 ms 4 ccngw-ner-cc.Berkeley.EDU (128.32.136.23) 39 ms 40 ms 39 ms 5 ccn-nerif22.Berkeley.EDU (128.32.168.22) 39 ms 39 ms 39 ms 6 128.32.197.4 (128.32.197.4) 40 ms 59 ms 59 ms 7 131.119.2.5 (131.119.2.5) 59 ms 59 ms 59 ms 8 129.140.70.13 (129.140.70.13) 99 ms 99 ms 80 ms 9 129.140.71.6 (129.140.71.6) 139 ms 239 ms 319 ms 10 129.140.81.7 (129.140.81.7) 220 ms 199 ms 199 ms 11 nic.merit.edu (35.1.1.48) 239 ms 239 ms 239 ms .Ed .Pp Note that lines 2 & 3 are the same. This is due to a buggy kernel on the 2nd hop system \- lilac-dmc.Berkeley.EDU \- that forwards packets with a zero ttl (a bug in the distributed version of 4.3BSD). Note that you have to guess what path the packets are taking cross-country since the NSFNet (129.140) doesn't supply address-to-name translations for its NSSes. .Pp A more interesting example is: .Bd -literal -offset 4n % traceroute allspice.lcs.mit.edu. traceroute to allspice.lcs.mit.edu (18.26.0.115), 64 hops max 1 helios.ee.lbl.gov (128.3.112.1) 0 ms 0 ms 0 ms 2 lilac-dmc.Berkeley.EDU (128.32.216.1) 19 ms 19 ms 19 ms 3 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 19 ms 19 ms 4 ccngw-ner-cc.Berkeley.EDU (128.32.136.23) 19 ms 39 ms 39 ms 5 ccn-nerif22.Berkeley.EDU (128.32.168.22) 20 ms 39 ms 39 ms 6 128.32.197.4 (128.32.197.4) 59 ms 119 ms 39 ms 7 131.119.2.5 (131.119.2.5) 59 ms 59 ms 39 ms 8 129.140.70.13 (129.140.70.13) 80 ms 79 ms 99 ms 9 129.140.71.6 (129.140.71.6) 139 ms 139 ms 159 ms 10 129.140.81.7 (129.140.81.7) 199 ms 180 ms 300 ms 11 129.140.72.17 (129.140.72.17) 300 ms 239 ms 239 ms 12 * * * 13 128.121.54.72 (128.121.54.72) 259 ms 499 ms 279 ms 14 * * * 15 * * * 16 * * * 17 * * * 18 ALLSPICE.LCS.MIT.EDU (18.26.0.115) 339 ms 279 ms 279 ms .Ed .Pp Note that the gateways 12, 14, 15, 16 & 17 hops away either don't send ICMP "time exceeded" messages or send them with a ttl too small to reach us. 14 \- 17 are running the MIT C Gateway code that doesn't send "time exceeded"s. God only knows what's going on with 12. .Pp The silent gateway 12 in the above may be the result of a bug in the 4.[23]BSD network code (and its derivatives): 4.x (x <= 3) sends an unreachable message using whatever ttl remains in the original datagram. Since, for gateways, the remaining ttl is zero, the ICMP "time exceeded" is guaranteed to not make it back to us. The behavior of this bug is slightly more interesting when it appears on the destination system: .Bd -literal -offset 4n 1 helios.ee.lbl.gov (128.3.112.1) 0 ms 0 ms 0 ms 2 lilac-dmc.Berkeley.EDU (128.32.216.1) 39 ms 19 ms 39 ms 3 lilac-dmc.Berkeley.EDU (128.32.216.1) 19 ms 39 ms 19 ms 4 ccngw-ner-cc.Berkeley.EDU (128.32.136.23) 39 ms 40 ms 19 ms 5 ccn-nerif35.Berkeley.EDU (128.32.168.35) 39 ms 39 ms 39 ms 6 csgw.Berkeley.EDU (128.32.133.254) 39 ms 59 ms 39 ms 7 * * * 8 * * * 9 * * * 10 * * * 11 * * * 12 * * * 13 rip.Berkeley.EDU (128.32.131.22) 59 ms ! 39 ms ! 39 ms ! .Ed .Pp Notice that there are 12 "gateways" (13 is the final destination) and exactly the last half of them are "missing". What's really happening is that rip (a Sun-3 running Sun OS3.5) is using the ttl from our arriving datagram as the ttl in its ICMP reply. So, the reply will time out on the return path (with no notice sent to anyone since ICMP's aren't sent for ICMP's) until we probe with a ttl that's at least twice the path length. I.e., rip is really only 7 hops away. A reply that returns with a ttl of 1 is a clue this problem exists. Traceroute prints a "!" after the time if the ttl is <= 1. Since vendors ship a lot of obsolete .Pf ( Tn DEC Ns \'s Ultrix, Sun 3.x) or non-standard .Pq Tn HP-UX software, expect to see this problem frequently and/or take care picking the target host of your probes. .Pp Other possible annotations after the time are: .Bl -hang -offset indent -width 12n .It Sy !H Host unreachable. .It Sy !N Network unreachable. .It Sy !P Protocol unreachable. .It Sy !S Source route failed. .It Sy !F\- Fragmentation needed. The RFC1191 Path MTU Discovery value is displayed. .It Sy !U Destination network unknown. .It Sy !W Destination host unknown. .It Sy !I Source host is isolated. .It Sy !A Communication with destination network administratively prohibited. .It Sy !Z Communication with destination host administratively prohibited. .It Sy !Q For this ToS the destination network is unreachable. .It Sy !T For this ToS the destination host is unreachable. .It Sy !X Communication administratively prohibited. .It Sy !V Host precedence violation. .It Sy !C Precedence cutoff in effect. .It Sy ! ICMP unreachable code . .El .Pp These are defined by RFC1812 (which supersedes RFC1716). If almost all the probes result in some kind of unreachable, .Nm will give up and exit. .Pp This program is intended for use in network testing, measurement and management. It should be used primarily for manual fault isolation. Because of the load it could impose on the network, it is unwise to use .Nm during normal operations or from automated scripts. .Sh SEE ALSO .Xr netstat 1 , .Xr ping 8 , .Xr traceroute6 8 . .Sh AUTHORS Implemented by Van Jacobson from a suggestion by Steve Deering. Debugged by a cast of thousands with particularly cogent suggestions or fixes from C. Philip Wood, Tim Seaver and Ken Adelman. .Sh BUGS When using protocols other than UDP, functionality is reduced. In particular, the last packet will often appear to be lost, because even though it reaches the destination host, there's no way to know that because no ICMP message is sent back. In the TCP case, .Nm should listen for a RST from the destination host (or an intermediate router that's filtering packets), but this is not implemented yet. .Pp The AS number capability reports information that may sometimes be inaccurate due to discrepancies between the contents of the routing database server and the current state of the Internet.