/* CS 555 * Programming Assignment #2 * * Simple routines to generate consistent output logs, printed to stdout. * */ #include #include void ForwardUnicastPacket (int timestamp, int destination, int nexthop) { printf ("FU %d %d %d\n", timestamp, destination, nexthop); } void DropUnicastPacket (int timestamp, int destAddr) { printf ("DUP %d %d\n", timestamp, destAddr); } void DropMulticastPacket (int timestamp, int destAddr, int source) { printf ("DMP %d %d %d\n", timestamp, destAddr, source); } /* Comparison function used by qsort (). */ int intcmp (const void *x, const void *y) { int lop = * ((int *) x); int rop = * ((int *) y); if (lop < rop) return -1; else if (lop == rop) return 0; else return 1; } void ForwardMulticastPacket (int timestamp, int destAddr, int *ListOfNextHops, int listlen) { int i = 0; /* First, sort the list (to provide consistent output across programs). */ qsort ((void *)ListOfNextHops, listlen, sizeof(int), intcmp); /* Then print the list of forwarded packets. */ for (i = 0; i < listlen; i ++) { printf ("FMP %d %d %d\n", timestamp, destAddr, ListOfNextHops[i]); } }