summaryrefslogtreecommitdiff
path: root/print-ntp.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix spaces before tabs in indentationFrancois-Xavier Le Bail2023-02-151-4/+4
|
* Include <time.h> from netdissect.h.Denis Ovsienko2023-02-151-2/+0
| | | | | | | | | | | | | | | netdissect.h since commit 7578e1c requires <time.h> for struct tm. The dependency is difficult to notice because the warning pops up when compiling strdup.c only and only on Linux, and Linux most certainly has strdup(), so normally strdup.c is never compiled on Linux. Make it correct anyway to eliminate a space for future surprises in other files. $ make strdup.o In file included from ./missing/strdup.c:38: ./netdissect.h:441:38: warning: 'struct tm' declared inside parameter list will not be visible outside of this definition or declaration gcc (Debian 10.2.1-6) 10.2.1 20210110
* configure, CMakeLists.txt: don't check for snprintf().Guy Harris2023-01-301-2/+0
| | | | | | | | It's specified by the C90 standard (and, as I remember, by the C89 standard, although I no longer have my paper copy); no need to worry about ancient environments that lack it, and we have some cases where we call it in code not protected by #ifdef HAVE_STRFTIME/#endif and haven't seen any reports of problems.
* NTP: Modernize packet parsing style. [skip ci]Denis Ovsienko2021-01-191-19/+3
| | | | | | Enable ND_LONGJMP_FROM_TCHECK. Remove a few redundant ND_TCHECK() instances. Move one ND_TCHECK_4() to where it belongs. Have nd_printjn() guard the snapshot end.
* Remove many (762) now redundant ND_TCHECK_n() callsFrancois-Xavier Le Bail2020-09-061-17/+0
| | | | | | | | | | | ND_TCHECK_n(e), n in { 1, 2, 3, 4, 8 }. They are redundant because they are followed by a GET_.*_n(e) call, same n, same e, which do the bounds check. Remove unused 'trunc' labels and most associated codes. Update the outputs of some tests accordingly.
* Extract NTP printingHerwin Weststrate2020-04-211-89/+1
| | | | This method is required to dissect some RADIUS attributes
* More bounds checking when fetching addresses and converting to strings.Guy Harris2020-01-191-2/+2
| | | | | | | | | | | | | | Replace more calls to ipaddr_string()/ip6addr_string() with calls to GET_IPADDR_STRING()/GET_IP6ADDR_STRING() macros performing bounds checking. Add similar bounds-checking inline functions and macros to wrap linkaddr_string(), etheraddr_string(), and isonsap_string() and convert calls to them to use the macros as well. Shuffle the inline functions in addrtoname.h around a bit, so that the inline functions, external declarations, and macros are all in the same order.
* Use the new GET_ macros instead of the EXTRACT_ onesFrancois-Xavier Le Bail2019-03-261-32/+32
| | | | | | | The exceptions are currently: Some EXTRACT_ in print-juniper.c, not used on packet buffer pointer. An EXTRACT_BE_U_3 in addrtoname.c, not always used on packet buffer pointer.
* Add the nd_print_invalid() functionFrancois-Xavier Le Bail2018-09-111-2/+2
| | | | | | | It prints " (invalid)", used for malformed or corrupted packets. Moreover: Update CONTRIBUTING.
* Fix spacesFrancois-Xavier Le Bail2018-09-031-19/+19
|
* NTP: Fix UTC/GMT timestamps printing according to RFC3339Francois-Xavier Le Bail2018-08-141-1/+1
| | | | | | | | | | | Add the "Z" suffix for UTC. According to the RFC3339: Z A suffix which, when applied to a time, denotes a UTC offset of 00:00; often spoken "Zulu" from the ICAO phonetic alphabet representation of the letter "Z". Update the output of some tests accordingly.
* NTP: Fix extracting the poll valueFrancois-Xavier Le Bail2018-05-201-1/+1
| | | | Use EXTRACT_S_1 for ppoll (signed).
* Fix space printing with istr[]Francois-Xavier Le Bail2018-05-181-2/+2
| | | | | | | Because istr[] is assign to " (invalid)", avoid adding a space before it. Moreover: Avoid also useless '\n'
* Print truncations with nd_print_trunc() instead of tstr[] stringsFrancois-Xavier Le Bail2018-05-041-4/+3
| | | | | | | | Remove the tstr[] strings. Update the output of some tests accordingly. Moreover: Add or update some ndo_protocol fields.
* Rename the fn_printX() functions to nd_printX()Francois-Xavier Le Bail2018-04-301-1/+1
| | | | | | | The functions are: nd_print, nd_printztn, nd_printn and nd_printzp. Trying to make it clearer that they currently have to be used only on part of the packet buffer. Update some comments.
* Add the ndo_protocol field in the netdissect_options structureFrancois-Xavier Le Bail2018-03-161-0/+1
| | | | | Update this field in printer entry functions. It will be used for some printings.
* Do time stamp deltas with unsigned arithmetic.Guy Harris2018-02-021-10/+10
| | | | | | | | | First, check whether the originate timestamp is greater than the other timestamp and, if so, calculate (originate - other) and print a - instead of a + before it. This means we're not trying to stuff the difference between two unsigned values into a signed value of the same width (the result of which is undefined if the difference doesn't fit in the signed variable).
* Have ip{6}addr_string take a u_char * as the second argument.Guy Harris2018-01-311-2/+2
| | | | Fix warnings that introduces.
* NTP: Replace ND_TCHECK calls by ND_TCHECK_SIZE callsFrancois-Xavier Le Bail2018-01-221-6/+6
|
* Always include <config.h> rather than "config.h".Guy Harris2018-01-211-1/+1
| | | | | | | | This can prevent bizarre failures if, for example, you've done a configuration in the top-level source directory, leaving behind one config.h file, and then do an out-of-tree build in another directory, with different configuration options. This way, we always pick up the same config.h, in the build directory.
* Use quoted include netdissect-stdinc.h instead of angle-bracketed oneFrancois-Xavier Le Bail2018-01-211-1/+1
|
* Check against various modes explicitly.Guy Harris2018-01-141-4/+16
| | | | | This avoids a "comparison is always true" warning when checking whether mode is >= MODE_UNSPEC.
* Clean up signed vs. unsigned.Guy Harris2018-01-111-2/+2
|
* Remove unneeded '&' when getting a pointer to an nd_uintN_t typeFrancois-Xavier Le Bail2018-01-081-9/+9
| | | | They are arrays.
* NTP: Use more ND_TCHECK_n() macrosFrancois-Xavier Le Bail2018-01-071-2/+2
|
* Update ND_PRINT() as a variadic macroFrancois-Xavier Le Bail2018-01-071-53/+53
|
* NTP: Replace ND_TCHECK2 calls by ND_TCHECK_LEN callsFrancois-Xavier Le Bail2017-12-141-3/+3
|
* Remove all storage class specifier 'register'Francois-Xavier Le Bail2017-12-131-22/+22
| | | | | | Let the compiler do the optimizations (or not) based on build options. Avoid 'value has been optimized out' messages in gdb using '-O0'.
* C99 type, not BSD type; use uint8_t.Guy Harris2017-12-131-1/+1
|
* Replace ND_TTEST2()/ND_TCHECK2() macros by macros using pointers (1/n)Francois-Xavier Le Bail2017-12-111-2/+2
| | | | | ND_TTEST2(var, l) -> ND_TTEST_LEN(p, l) ND_TCHECK2(var, l) -> ND_TCHECK_LEN(p, l)
* Make nd_uint8_t and nd_int8_t arrays, to catch direct references.Guy Harris2017-12-101-36/+50
| | | | | | | | | | This catches direct references, so we can change them to use EXTRACT_U_1 or EXTRACT_S_1. Also, change some structures to use the nd_ types that weren't already using them. Then make the appropriate EXTRACT_{U,S}_1() changes.
* Rename EXTRACT_ macrosFrancois-Xavier Le Bail2017-11-221-26/+26
| | | | | | | | | | | | | | | | Now all the macros have a name meaning a count in bytes. With _S_: signed, _U_: unsigned e.g.: EXTRACT_BE_32BITS -> EXTRACT_BE_U_4 EXTRACT_LE_32BITS -> EXTRACT_LE_U_4 ... EXTRACT_BE_INT32 -> EXTRACT_BE_S_4 and have: EXTRACT_8BITS -> EXTRACT_U_1 EXTRACT_INT8 -> EXTRACT_S_1
* Rename EXTRACT_nBITS() macros to EXTRACT_BE_nBITS()Francois-Xavier Le Bail2017-11-181-26/+26
| | | | | It indicates clearly that these macros are used to extract big-endian integral values.
* Make the delta between 1970 and 1900 a 64-bit signed integral constant.Guy Harris2017-09-211-1/+1
| | | | | | It doesn't fit in a 32-bit signed integral constant, so make sure it's 64-bit; the only use is to subtract it from a 64-bit signed integral value.
* Fix handling of NTP time stamps.Guy Harris2017-09-201-7/+26
| | | | | | | | | | | | | | | | | | | | | | | The seconds value in a 64-bit NTP timestamp is unsigned. Treat it as such. When converting it to a UN*X seconds-since-the-Epoch, cast the 32-bit seconds value from an NTP timestap to a 64-bit signed value (which is always possible), and then subtract the signed delta between 1900 and 1970, giving a signed seconds-since-the-Epoch value. Then assign that to a time_t; if that variable doesn't have the same value as the calculated 64-bit value, we can't represent it in a time_t, so just report it as unrepresentable. Otherwise, use that resulting value in a gmtime() call - and make sure gmtime() doesn't return NULL, which it can do with some versions of the Microsoft C runtime. If it does, report the time as unrepresentable, otherwise report it as YYYY-MM-DDTHH:MM:SS. This fixes the 32-bit vs. 64-bit issue for tests. It also changes the test output, so update that.
* Actually, the UNALIGNED might not be necessary.Guy Harris2017-09-201-4/+4
|
* NTP: Remove some duplicate output.Denis Ovsienko2017-09-201-24/+0
| | | | | | In ntp_time_print() do not print the information already printed in ntp_print(): mode, leap indicator, version (all part of the Status header field) and length. Update the test case.
* Try marking structures as UNALIGNED.Guy Harris2017-09-201-4/+4
| | | | | | | | | See if this fixes the crashes on the OpenCSW SPARC buildbots. If so, it means that the compiler may think that even structures made up of nothing but bytes (char/unsigned char) and arrays of bytes are aligned, even if there's no guarantee of that. (Bad compiler! No biscuit!)
* NTP: Add missing bounds checks.Denis Ovsienko2017-09-041-1/+9
| | | | | | This change adds checks that were missing from the recent NTP code and could cause a buffer over-read vulnerability (see earlier commits for rationale).
* NTP: Update length checks after the recent commit.Denis Ovsienko2017-09-041-12/+24
| | | | | | Rename NTP_MSG_MINLEN to NTP_TIMEMSG_MINLEN for clarity and introduce and use NTP_CTRLMSG_MINLEN. With this change ntp_control_print() can detect invalid packets better.
* NTP: Use nd_XXXXX integer types in the structures.Denis Ovsienko2017-09-041-23/+21
| | | | | This prevents alignment issues when the structures are used to access the input buffer (see earlier commits for more detailed rationale).
* NTP: Use tstr for truncation indicator.Denis Ovsienko2017-09-041-3/+5
| | | | This implements the same convention as in all other decoders.
* print-ntp.c: Handle NTP Control MessagesUlrich Windl2017-09-041-9/+132
| | | | | | | | | | | | | | | | | | | | In print-ntp.c: Rename struct ntpdata into struct ntp_time_data and add new struct ntp_control_data to map NTP Control messages. Add figure of NTP Control Message Header as comment. Add union ntpdata to provide a common view on NTP messages. Rename ntp_print() to ntp_time_print(), using new structures. Improve comment and re-arrange fields in ntp_print(). Add ntp_control_print() to handle NTP Control Messages. Output R, E, M, OpCode, Sequence, Status, Assoc, Offset, and Count in ntp_control_print(). A new ntp_print() will decode only the very basics (VN, LI and Mode) to call ntp_time_print() or ntp_control_print(), depending on Mode.
* Squelch a warning.Guy Harris2017-09-041-5/+5
| | | | | | poll() is a system API on UN*Xes, so calling a variable "poll" causes "declaration of 'poll' shadows a global declaration" warnings in some compilers. Call the argument "poll_interval" instead.
* NTP: Improve length checks.Denis Ovsienko2017-08-301-4/+23
| | | | | | | | | | In ntp_print() add a missing length check to reject packets that are declared too short, make the existing length checks easier to follow and add a catch-all block after the known message layouts. This fixes a bug where an invalid packet could be erroneously printed like it is valid so long as the provided buffer was large enough. That said, the bounds checks were done correctly so there was no over-read.
* Print NTP MAC with 160-bit digest.Miroslav Lichvar2017-08-301-4/+14
| | | | | An NTP packet authenticated with a key using stronger hash function than MD5 may have a 160-bit digest.
* Print NTP timestamps as UTC, not local timeUlrich Windl2017-08-291-3/+4
| | | | | | | print-ntp.c: Change p_ntp_time() to print NTP timestamps in UTC instead of local time. This allows for consistent output for automatic testing different time zones. Also use an ISO 8601 (RFC3339) format for the time stamps.
* Prepare print-ntp.c for NTP Control MessagesUlrich Windl2017-08-291-2/+4
| | | | | Add shift constants LEAPSHIFT(6) and MODESHIFT(0). Rename MODE_RES1 to MODE_CONTROL, adjusting ntp_mode_values[].
* print-ntp.c: Add and use VERSIONSHIFTUlrich Windl2017-08-291-1/+2
| | | | Add shift constant VERSIONSHIFT(3), and use it in ntp_print().
* NTP: For clarity use 0x with hexadecimal format.Denis Ovsienko2017-08-291-1/+1
|