summaryrefslogtreecommitdiffstats
path: root/lib/libdtrace/common/dt_printf.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libdtrace/common/dt_printf.c')
-rw-r--r--lib/libdtrace/common/dt_printf.c76
1 files changed, 70 insertions, 6 deletions
diff --git a/lib/libdtrace/common/dt_printf.c b/lib/libdtrace/common/dt_printf.c
index 953511b..5290478 100644
--- a/lib/libdtrace/common/dt_printf.c
+++ b/lib/libdtrace/common/dt_printf.c
@@ -20,12 +20,9 @@
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <sys/sysmacros.h>
#include <strings.h>
#include <stdlib.h>
@@ -34,6 +31,11 @@
#include <ctype.h>
#include <errno.h>
#include <limits.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
#include <dt_printf.h>
#include <dt_string.h>
@@ -330,7 +332,7 @@ pfprint_addr(dtrace_hdl_t *dtp, FILE *fp, const char *format,
do {
n = len;
s = alloca(n);
- } while ((len = dtrace_addr2str(dtp, val, s, n)) >= n);
+ } while ((len = dtrace_addr2str(dtp, val, s, n)) > n);
return (dt_printf(dtp, fp, format, s));
}
@@ -383,7 +385,7 @@ pfprint_uaddr(dtrace_hdl_t *dtp, FILE *fp, const char *format,
do {
n = len;
s = alloca(n);
- } while ((len = dtrace_uaddr2str(dtp, pid, val, s, n)) >= n);
+ } while ((len = dtrace_uaddr2str(dtp, pid, val, s, n)) > n);
return (dt_printf(dtp, fp, format, s));
}
@@ -494,6 +496,49 @@ pfprint_time822(dtrace_hdl_t *dtp, FILE *fp, const char *format,
/*ARGSUSED*/
static int
+pfprint_port(dtrace_hdl_t *dtp, FILE *fp, const char *format,
+ const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
+{
+ uint16_t port = htons(*((uint16_t *)addr));
+ char buf[256];
+ struct servent *sv, res;
+
+ if ((sv = getservbyport_r(port, NULL, &res, buf, sizeof (buf))) != NULL)
+ return (dt_printf(dtp, fp, format, sv->s_name));
+
+ (void) snprintf(buf, sizeof (buf), "%d", *((uint16_t *)addr));
+ return (dt_printf(dtp, fp, format, buf));
+}
+
+/*ARGSUSED*/
+static int
+pfprint_inetaddr(dtrace_hdl_t *dtp, FILE *fp, const char *format,
+ const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
+{
+ char *s = alloca(size + 1);
+ struct hostent *host, res;
+ char inetaddr[NS_IN6ADDRSZ];
+ char buf[1024];
+ int e;
+
+ bcopy(addr, s, size);
+ s[size] = '\0';
+
+ if (strchr(s, ':') == NULL && inet_pton(AF_INET, s, inetaddr) != -1) {
+ if ((host = gethostbyaddr_r(inetaddr, NS_INADDRSZ,
+ AF_INET, &res, buf, sizeof (buf), &e)) != NULL)
+ return (dt_printf(dtp, fp, format, host->h_name));
+ } else if (inet_pton(AF_INET6, s, inetaddr) != -1) {
+ if ((host = getipnodebyaddr(inetaddr, NS_IN6ADDRSZ,
+ AF_INET6, &e)) != NULL)
+ return (dt_printf(dtp, fp, format, host->h_name));
+ }
+
+ return (dt_printf(dtp, fp, format, s));
+}
+
+/*ARGSUSED*/
+static int
pfprint_cstr(dtrace_hdl_t *dtp, FILE *fp, const char *format,
const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
{
@@ -597,6 +642,7 @@ static const dt_pfconv_t _dtrace_conversions[] = {
{ "hx", "x", "short", pfcheck_xshort, pfprint_uint },
{ "hX", "X", "short", pfcheck_xshort, pfprint_uint },
{ "i", "i", pfproto_xint, pfcheck_dint, pfprint_dint },
+{ "I", "s", pfproto_cstr, pfcheck_str, pfprint_inetaddr },
{ "k", "s", "stack", pfcheck_stack, pfprint_stack },
{ "lc", "lc", "int", pfcheck_type, pfprint_sint }, /* a.k.a. wint_t */
{ "ld", "d", "long", pfcheck_type, pfprint_sint },
@@ -619,6 +665,7 @@ static const dt_pfconv_t _dtrace_conversions[] = {
{ "LG", "G", "long double", pfcheck_type, pfprint_fp },
{ "o", "o", pfproto_xint, pfcheck_xint, pfprint_uint },
{ "p", "x", pfproto_addr, pfcheck_addr, pfprint_uint },
+{ "P", "s", "uint16_t", pfcheck_type, pfprint_port },
{ "s", "s", "char [] or string (or use stringof)", pfcheck_str, pfprint_cstr },
{ "S", "s", pfproto_cstr, pfcheck_str, pfprint_estr },
{ "T", "s", "int64_t", pfcheck_time, pfprint_time822 },
@@ -1225,6 +1272,20 @@ pfprint_average(dtrace_hdl_t *dtp, FILE *fp, const char *format,
/*ARGSUSED*/
static int
+pfprint_stddev(dtrace_hdl_t *dtp, FILE *fp, const char *format,
+ const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
+{
+ const uint64_t *data = addr;
+
+ if (size != sizeof (uint64_t) * 4)
+ return (dt_set_errno(dtp, EDT_DMISMATCH));
+
+ return (dt_printf(dtp, fp, format,
+ dt_stddev((uint64_t *)data, normal)));
+}
+
+/*ARGSUSED*/
+static int
pfprint_quantize(dtrace_hdl_t *dtp, FILE *fp, const char *format,
const dt_pfargd_t *pfd, const void *addr, size_t size, uint64_t normal)
{
@@ -1415,6 +1476,9 @@ dt_printf_format(dtrace_hdl_t *dtp, FILE *fp, const dt_pfargv_t *pfv,
case DTRACEAGG_AVG:
func = pfprint_average;
break;
+ case DTRACEAGG_STDDEV:
+ func = pfprint_stddev;
+ break;
case DTRACEAGG_QUANTIZE:
func = pfprint_quantize;
break;
OpenPOWER on IntegriCloud