X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvppinfra%2Funix-formats.c;h=fd0539c7d2b29a45d42b0872d4db734591ab6cb9;hb=009fd6a22ffe7726f1e33e45162428f515e2830f;hp=a4c81ca2f70de93b856cb004181b1d01f6e38dce;hpb=7cd468a3d7dee7d6c92f69a0bb7061ae208ec727;p=vpp.git diff --git a/src/vppinfra/unix-formats.c b/src/vppinfra/unix-formats.c index a4c81ca2f70..fd0539c7d2b 100644 --- a/src/vppinfra/unix-formats.c +++ b/src/vppinfra/unix-formats.c @@ -37,11 +37,17 @@ #ifdef __KERNEL__ +#if __linux__ # include # include +#endif #else /* ! __KERNEL__ */ +#ifdef __APPLE__ +#define _XOPEN_SOURCE +#endif + #define _GNU_SOURCE /* to get REG_* in ucontext.h */ #include #undef _GNU_SOURCE @@ -49,6 +55,7 @@ #include #include +#include #include #include @@ -56,11 +63,14 @@ #include #include +#if __linux__ +#include #ifdef AF_NETLINK #include #include #endif +#endif #endif /* ! __KERNEL__ */ @@ -230,6 +240,7 @@ u8 * format_sockaddr (u8 * s, va_list * args) { void * v = va_arg (*args, void *); struct sockaddr * sa = v; + static u32 local_counter; switch (sa->sa_family) { @@ -242,6 +253,17 @@ u8 * format_sockaddr (u8 * s, va_list * args) } break; + case AF_LOCAL: + { + /* + * There isn't anything useful to print. + * The unix cli world uses the output to make a node name, + * so we need to return a unique name. + */ + s = format (s, "local:%u", local_counter++); + } + break; + #ifndef __KERNEL__ #ifdef AF_NETLINK case AF_NETLINK: @@ -263,6 +285,7 @@ u8 * format_sockaddr (u8 * s, va_list * args) return s; } +#ifndef __APPLE__ u8 * format_tcp4_packet (u8 * s, va_list * args) { u8 * p = va_arg (*args, u8 *); @@ -699,7 +722,7 @@ u8 * format_ethernet_packet (u8 * s, va_list * args) struct ethhdr * h = va_arg (*args, struct ethhdr *); uword proto = h->h_proto; u8 * payload = (void *) (h + 1); - uword indent; + u32 indent; /* Check for 802.2/802.3 encapsulation. */ if (proto < ETH_DATA_LEN) @@ -789,11 +812,11 @@ u8 * format_timeval (u8 * s, va_list * args) break; case 'm': what = tm->tm_mon + 1; - what_fmt = "%2d"; + what_fmt = "%02d"; break; case 'd': what = tm->tm_mday; - what_fmt = "%2d"; + what_fmt = "%02d"; break; case 'H': what = tm->tm_hour; @@ -818,6 +841,7 @@ u8 * format_timeval (u8 * s, va_list * args) return s; } +#endif u8 * format_time_float (u8 * s, va_list * args) { @@ -915,4 +939,29 @@ u8 * format_ucontext_pc (u8 * s, va_list * args) return format (s, "%p", regs[reg_no]); } +__clib_export uword +unformat_unix_gid (unformat_input_t * input, va_list * args) +{ + gid_t *gid = va_arg (*args, gid_t *); + struct group *grp = 0; + int r; + u8 *s; + + if (unformat (input, "%d", &r)) + { + grp = getgrgid (r); + } + else if (unformat (input, "%s", &s)) + { + grp = getgrnam ((char *) s); + vec_free (s); + } + if (grp) + { + *gid = grp->gr_gid; + return 1; + } + return 0; +} + #endif /* __KERNEL__ */