diff options
-rw-r--r-- | ethtool.c | 80 |
1 files changed, 21 insertions, 59 deletions
@@ -1132,10 +1132,11 @@ static void parse_cmdline(int argc, char **argp) exit_bad_args(); } +static void dump_link_caps(const char *prefix, const char *an_prefix, u32 mask); + static void dump_supported(struct ethtool_cmd *ep) { - u_int32_t mask = ep->supported; - int did1; + u32 mask = ep->supported; fprintf(stdout, " Supported ports: [ "); if (mask & SUPPORTED_TP) @@ -1150,64 +1151,25 @@ static void dump_supported(struct ethtool_cmd *ep) fprintf(stdout, "FIBRE "); fprintf(stdout, "]\n"); - fprintf(stdout, " Supported link modes: "); - did1 = 0; - if (mask & SUPPORTED_10baseT_Half) { - did1++; fprintf(stdout, "10baseT/Half "); - } - if (mask & SUPPORTED_10baseT_Full) { - did1++; fprintf(stdout, "10baseT/Full "); - } - if (did1 && (mask & (SUPPORTED_100baseT_Half|SUPPORTED_100baseT_Full))) { - fprintf(stdout, "\n"); - fprintf(stdout, " "); - } - if (mask & SUPPORTED_100baseT_Half) { - did1++; fprintf(stdout, "100baseT/Half "); - } - if (mask & SUPPORTED_100baseT_Full) { - did1++; fprintf(stdout, "100baseT/Full "); - } - if (did1 && (mask & (SUPPORTED_1000baseT_Half|SUPPORTED_1000baseT_Full))) { - fprintf(stdout, "\n"); - fprintf(stdout, " "); - } - if (mask & SUPPORTED_1000baseT_Half) { - did1++; fprintf(stdout, "1000baseT/Half "); - } - if (mask & SUPPORTED_1000baseT_Full) { - did1++; fprintf(stdout, "1000baseT/Full "); - } - if (did1 && (mask & SUPPORTED_2500baseX_Full)) { - fprintf(stdout, "\n"); - fprintf(stdout, " "); - } - if (mask & SUPPORTED_2500baseX_Full) { - did1++; fprintf(stdout, "2500baseX/Full "); - } - if (did1 && (mask & SUPPORTED_10000baseT_Full)) { - fprintf(stdout, "\n"); - fprintf(stdout, " "); - } - if (mask & SUPPORTED_10000baseT_Full) { - did1++; fprintf(stdout, "10000baseT/Full "); - } - fprintf(stdout, "\n"); - - fprintf(stdout, " Supports auto-negotiation: "); - if (mask & SUPPORTED_Autoneg) - fprintf(stdout, "Yes\n"); - else - fprintf(stdout, "No\n"); + dump_link_caps("Supported", "Supports", mask); } -static void dump_advertised(struct ethtool_cmd *ep, - const char *prefix, u_int32_t mask) +/* Print link capability flags (supported, advertised or lp_advertised). + * Assumes that the corresponding SUPPORTED and ADVERTISED flags are equal. + */ +static void +dump_link_caps(const char *prefix, const char *an_prefix, u32 mask) { - int indent = strlen(prefix) + 14; + int indent; int did1; - fprintf(stdout, " %s link modes: ", prefix); + /* Indent just like the separate functions used to */ + indent = strlen(prefix) + 14; + if (indent < 24) + indent = 24; + + fprintf(stdout, " %s link modes:%*s", prefix, + indent - strlen(prefix) - 12, ""); did1 = 0; if (mask & ADVERTISED_10baseT_Half) { did1++; fprintf(stdout, "10baseT/Half "); @@ -1266,7 +1228,7 @@ static void dump_advertised(struct ethtool_cmd *ep, fprintf(stdout, "No\n"); } - fprintf(stdout, " %s auto-negotiation: ", prefix); + fprintf(stdout, " %s auto-negotiation: ", an_prefix); if (mask & ADVERTISED_Autoneg) fprintf(stdout, "Yes\n"); else @@ -1278,10 +1240,10 @@ static int dump_ecmd(struct ethtool_cmd *ep) u32 speed; dump_supported(ep); - dump_advertised(ep, "Advertised", ep->advertising); + dump_link_caps("Advertised", "Advertised", ep->advertising); if (ep->lp_advertising) - dump_advertised(ep, "Link partner advertised", - ep->lp_advertising); + dump_link_caps("Link partner advertised", + "Link partner advertised", ep->lp_advertising); fprintf(stdout, " Speed: "); speed = ethtool_cmd_speed(ep); |