ethtool.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ynl.h>
  5. #include <net/if.h>
  6. #include "ethtool-user.h"
  7. int main(int argc, char **argv)
  8. {
  9. struct ethtool_channels_get_req_dump creq = {};
  10. struct ethtool_rings_get_req_dump rreq = {};
  11. struct ethtool_channels_get_list *channels;
  12. struct ethtool_rings_get_list *rings;
  13. struct ynl_sock *ys;
  14. ys = ynl_sock_create(&ynl_ethtool_family, NULL);
  15. if (!ys)
  16. return 1;
  17. creq._present.header = 1; /* ethtool needs an empty nest, sigh */
  18. channels = ethtool_channels_get_dump(ys, &creq);
  19. if (!channels)
  20. goto err_close;
  21. printf("Channels:\n");
  22. ynl_dump_foreach(channels, dev) {
  23. printf(" %8s: ", dev->header.dev_name);
  24. if (dev->_present.rx_count)
  25. printf("rx %d ", dev->rx_count);
  26. if (dev->_present.tx_count)
  27. printf("tx %d ", dev->tx_count);
  28. if (dev->_present.combined_count)
  29. printf("combined %d ", dev->combined_count);
  30. printf("\n");
  31. }
  32. ethtool_channels_get_list_free(channels);
  33. rreq._present.header = 1; /* ethtool needs an empty nest.. */
  34. rings = ethtool_rings_get_dump(ys, &rreq);
  35. if (!rings)
  36. goto err_close;
  37. printf("Rings:\n");
  38. ynl_dump_foreach(rings, dev) {
  39. printf(" %8s: ", dev->header.dev_name);
  40. if (dev->_present.rx)
  41. printf("rx %d ", dev->rx);
  42. if (dev->_present.tx)
  43. printf("tx %d ", dev->tx);
  44. printf("\n");
  45. }
  46. ethtool_rings_get_list_free(rings);
  47. ynl_sock_destroy(ys);
  48. return 0;
  49. err_close:
  50. fprintf(stderr, "YNL (%d): %s\n", ys->err.code, ys->err.msg);
  51. ynl_sock_destroy(ys);
  52. return 2;
  53. }