X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/f0ff49cc4da980f56cc08211c03b9260e6c5400f..11a7aeda39732ea8a889baf36678d73fc46a1aa1:/print.c diff --git a/print.c b/print.c index 05e05227..20d8ab51 100644 --- a/print.c +++ b/print.c @@ -226,26 +226,19 @@ static const struct printer printers[] = { static void ndo_default_print(netdissect_options *ndo, const u_char *bp, u_int length); -static void ndo_error(netdissect_options *ndo _U_, const char *fmt, ...) - __attribute__((noreturn)) -#ifdef __ATTRIBUTE___FORMAT_OK - __attribute__((format (printf, 2, 3))) -#endif /* __ATTRIBUTE___FORMAT_OK */ - ; -static void ndo_warning(netdissect_options *ndo _U_, const char *fmt, ...) -#ifdef __ATTRIBUTE___FORMAT_OK - __attribute__((format (printf, 2, 3))) -#endif /* __ATTRIBUTE___FORMAT_OK */ - ; - -static int ndo_printf(netdissect_options *ndo _U_, const char *fmt, ...) -#ifdef __ATTRIBUTE___FORMAT_OK - __attribute ((format (printf, 2, 3))) -#endif /* __ATTRIBUTE___FORMAT_OK */ - ; +static void NORETURN ndo_error(netdissect_options *ndo, + FORMAT_STRING(const char *fmt), ...) + PRINTFLIKE(2, 3); +static void ndo_warning(netdissect_options *ndo, + FORMAT_STRING(const char *fmt), ...) + PRINTFLIKE(2, 3); + +static int ndo_printf(netdissect_options *ndo, + FORMAT_STRING(const char *fmt), ...) + PRINTFLIKE(2, 3); void -init_print(netdissect_options *ndo, u_int32_t localnet, u_int32_t mask, +init_print(netdissect_options *ndo, uint32_t localnet, uint32_t mask, uint32_t timezone_offset) { @@ -329,8 +322,8 @@ pretty_print_packet(netdissect_options *ndo, const struct pcap_pkthdr *h, ts_print(ndo, &h->ts); /* - * Some printers want to check that they're not walking off the - * end of the packet. + * Printers must check that they're not walking off the end of + * the packet. * Rather than pass it all the way down, we set this member * of the netdissect_options structure. */ @@ -401,7 +394,7 @@ pretty_print_packet(netdissect_options *ndo, const struct pcap_pkthdr *h, } } - putchar('\n'); + ND_PRINT((ndo, "\n")); } /* @@ -429,6 +422,7 @@ ndo_error(netdissect_options *ndo, const char *fmt, ...) if (fmt[-1] != '\n') (void)fputc('\n', stderr); } + nd_cleanup(); exit(1); /* NOTREACHED */ } @@ -453,7 +447,7 @@ ndo_warning(netdissect_options *ndo, const char *fmt, ...) } static int -ndo_printf(netdissect_options *ndo _U_, const char *fmt, ...) +ndo_printf(netdissect_options *ndo, const char *fmt, ...) { va_list args; int ret; @@ -462,6 +456,8 @@ ndo_printf(netdissect_options *ndo _U_, const char *fmt, ...) ret = vfprintf(stdout, fmt, args); va_end(args); + if (ret < 0) + ndo_error(ndo, "Unable to write output: %s", pcap_strerror(errno)); return (ret); }