/* * Combines ethernet IP addresses and speed (if requested) for displaying * */ void print_eth_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down) { const char *walk; const char *ip_address = get_ip_addr(interface); char *outwalk = buffer; INSTANCE(interface); if (ip_address == NULL) { START_COLOR("color_bad"); outwalk += sprintf(outwalk, "%s", format_down); goto out; } START_COLOR("color_good"); for (walk = format_up; *walk != '\0'; walk++) { if (*walk != '%') { *(outwalk++) = *walk; continue; } if (strncmp(walk+1, "ip", strlen("ip")) == 0) { outwalk += sprintf(outwalk, "%s", ip_address); walk += strlen("ip"); } else if (strncmp(walk+1, "speed", strlen("speed")) == 0) { outwalk += print_eth_speed(outwalk, interface); walk += strlen("speed"); } } out: END_COLOR; OUTPUT_FULL_TEXT(buffer); }
/* * Combines ethernet IP addresses and speed (if requested) for displaying * */ void print_eth_info(const char *interface, const char *format_up, const char *format_down) { const char *walk; const char *ip_address = get_ip_addr(interface); if (ip_address == NULL) { printf("%s", color("#FF0000")); printf("%s", format_down); (void)printf("%s", endcolor()); return; } else { printf("%s", color("#00FF00")); } for (walk = format_up; *walk != '\0'; walk++) { if (*walk != '%') { putchar(*walk); continue; } if (strncmp(walk+1, "ip", strlen("ip")) == 0) { printf("%s", ip_address); walk += strlen("ip"); } else if (strncmp(walk+1, "speed", strlen("speed")) == 0) { print_eth_speed(interface); walk += strlen("speed"); } } (void)printf("%s", endcolor()); }