// // CS461 Distributed Computing and Networking // Princeton University // Tammo Spalink, Andy Bavier // // Spring 2002, Revision 1 // #include #include #include "interface.h" #include #include #include #include #define FOREVER ;; // A simple clock callback void clockHandler(void) { fprintf(stderr, "!"); } // A simple IO callback to reflect "pings". You'll actually see two dots // printed for every ping; the ECHO_REQUEST message is echoed back to the // sender, who then replies to it. In other words, // src -> ECHO_REQUEST -> dst // src <- ECHO_REQUEST <- dst // src -> ECHO_REPLY -> dst // src <- ECHO_REPLY <- dst void recvHandler(void *buf) { struct iphdr *header; unsigned int tmp; struct iovec iov; header = (struct iphdr *)buf; tmp = header->daddr; /* Swap the source and destination addresses */ header->daddr = header->saddr; header->saddr = tmp; iov.iov_base = buf; iov.iov_len = ntohs(header->tot_len); /* Send the packet to the router, let it figure out where it goes next */ CS461_SendIov(inet_addr("128.112.4.6"), &iov, 1); /* We are done with packet processing */ CS461_Free(buf); fprintf(stderr, "."); } // The main() function just initializes the callbacks and then loops // until the program is shut down. int main(void) { CS461_Initialize(IPPROTO_ICMP, recvHandler, clockHandler, 1000, 0); CS461_InterruptToggle(CS461_INTON); for (FOREVER) { CS461_Block(); } return 0; }