ucmd_pong.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* pong: ring-3 command. Answer ARP/ICMP for our IP for 30 s. */
  2. #include "ucmd_lib.h"
  3. #define NET_FRAME_MAX 1518
  4. #define NETLOG_PORT 19290
  5. static unsigned char rx_buf[NET_FRAME_MAX];
  6. static unsigned char reply_buf[NET_FRAME_MAX];
  7. void _start(const char *arg)
  8. {
  9. unsigned char ip[4];
  10. unsigned int deadline, count = 0;
  11. (void)arg;
  12. if (u_syscall0(SYS_NET_ACQUIRE) != 0) {
  13. u_puts("pong: no NIC found\n");
  14. u_exit(1);
  15. }
  16. u_syscall1(SYS_NET_GET_IP, (int)ip);
  17. u_puts("pong: answering ARP/ICMP for 30s (ip=");
  18. u_put_ip(ip);
  19. u_puts(")...\n");
  20. deadline = u_ticks_ms() + 30000;
  21. while ((int)(u_ticks_ms() - deadline) < 0) {
  22. int len = u_syscall2(SYS_NET_RX, (int)rx_buf, NET_FRAME_MAX);
  23. int rlen;
  24. if (len < 0)
  25. continue;
  26. rlen = u_syscall3(SYS_NET_REPLY, (int)rx_buf, (unsigned int)len,
  27. (int)reply_buf);
  28. if (rlen > 0) {
  29. if (u_syscall2(SYS_NET_TX, (int)reply_buf,
  30. (unsigned int)rlen) == 0) {
  31. u_puts("reply: ");
  32. u_syscall2(SYS_NET_DECODE, (int)reply_buf,
  33. (unsigned int)rlen);
  34. u_putc('\n');
  35. count++;
  36. }
  37. }
  38. }
  39. u_syscall0(SYS_NET_RELEASE);
  40. u_puts("pong: done (");
  41. u_putdec(count);
  42. u_puts(" replies)\n");
  43. u_exit(0);
  44. }