ucmd_netinfo.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* netinfo: ring-3 command. NIC, addresses and DHCP lease. */
  2. #include "ucmd_lib.h"
  3. void _start(const char *arg)
  4. {
  5. struct sys_netinfo n;
  6. unsigned char srv[4];
  7. unsigned int lease = 0;
  8. (void)arg;
  9. if (u_syscall1(SYS_NET_INFO, (int)&n) != 1) {
  10. u_puts("netinfo: no NIC found\n");
  11. u_exit(0);
  12. }
  13. u_puts("netdev: ");
  14. u_puts(n.name);
  15. u_puts(" (");
  16. u_puts(n.chip);
  17. u_puts(")\n");
  18. u_puts("link: ");
  19. u_puts(n.link ? "up" : "down");
  20. u_puts("\n");
  21. u_syscall0(SYS_NET_PRINT_INFO);
  22. u_puts("ip=");
  23. u_put_ip(n.ip);
  24. if (n.mask[0] || n.mask[1] || n.mask[2] || n.mask[3]) {
  25. u_puts("/");
  26. u_put_ip(n.mask);
  27. }
  28. u_putc('\n');
  29. if (n.gw[0] || n.gw[1] || n.gw[2] || n.gw[3]) {
  30. u_puts("gw=");
  31. u_put_ip(n.gw);
  32. u_putc('\n');
  33. }
  34. if (n.dns[0] || n.dns[1] || n.dns[2] || n.dns[3]) {
  35. u_puts("dns=");
  36. u_put_ip(n.dns);
  37. u_putc('\n');
  38. }
  39. if (u_syscall2(SYS_DHCP_INFO, (int)srv, (int)&lease) == 1) {
  40. u_puts("dhcp: server ");
  41. u_put_ip(srv);
  42. u_puts(" lease ");
  43. u_putdec(lease);
  44. u_puts("s\n");
  45. }
  46. u_exit(0);
  47. }