/* main(): * The equivalent of the MONCMD server built into uMon... * Blocks on port 777 waiting for an incoming message, then * responds with "thanks". */ int main(int argc, char *argv[]) { int rc = 0; unetStart(); cmdInit(); mon_printf("%s: MONCMD server using uMon's ethernet API...\n", argv[0]); /* This loop processes incoming UDP and incoming serial port * (console) activity... Terminate on reception of ctrl-c * (0x03) from console. */ while(1) { if (mon_gotachar()) { int c = mon_getchar(); if (c == 0x03) { mon_printf("\n<ctrl-c>\n"); break; } else processChar(c); } /* Set up the server to receive packets on any port... * Then after udpRecvFrom returns, use the value of u.dport * to determine which port the packet came in on. */ udpInfo.dport = ANY_UDP_PORT; udpInfo.packet = (char *)unetPacket; udpInfo.plen = sizeof(unetPacket); /* Check for an incoming packet. This does not block. It will * return negative if there is an error, zero of there is no packet * pending; else some positive number representing the incoming * packet size. */ rc = udpRecvFrom(&udpInfo); if (rc > 0) { if (udpInfo.dport == 777) { udp_umoncmd((char *)udpInfo.udata); } else { mon_printf("\nUDP rcv'd on port %d, from %d.%d.%d.%d:%d ...\n", udpInfo.dport, IP1(udpInfo.sip.s_addr), IP2(udpInfo.sip.s_addr), IP3(udpInfo.sip.s_addr), IP4(udpInfo.sip.s_addr), udpInfo.sport); mon_printmem((char *)udpInfo.udata,rc,1); } } else if (rc < 0) { unetError("recv",rc,UNETACT_ALL); } } unetStop(); return(0); }
/* * Read one character from UART. * * return -1 if there's no data, otherwise return * the character in lowest 8 bits of returned int. */ static int umoncons_read(int minor) { if ( !mon_gotachar() ) return -1; return mon_getchar(); }