/******************************************************************* * Prints all of ARP Cache. *******************************************************************/ void print_cache(struct sr_instance* sr) { printf("---ARP CACHE---\n"); struct arp_cache_entry* cache_walker=0; if(sr->arp_cache==0) { printf(" ARP Cache is Empty.\n"); return; } cache_walker=sr->arp_cache; while(cache_walker) { print_cache_entry(cache_walker); cache_walker=cache_walker->next; } }
/** * Get and display an entry from the cache * * @param argv key to search an entry of * @return 0 on success, otherwise failure **/ static int net_cache_get(int argc, const char **argv) { const char* keystr = argv[0]; char* valuestr; time_t timeout; if (argc < 1) { d_printf("\nUsage: net cache get <key>\n"); return -1; } if (gencache_get(keystr, &valuestr, &timeout)) { print_cache_entry(keystr, valuestr, timeout, NULL); return 0; } d_fprintf(stderr, "Failed to find entry\n"); return -1; }
/** * Get and display an entry from the cache * * @param c A net_context structure * @param argv key to search an entry of * @return 0 on success, otherwise failure **/ static int net_cache_get(struct net_context *c, int argc, const char **argv) { const char* keystr = argv[0]; char* valuestr = NULL; time_t timeout; if (argc < 1 || c->display_usage) { d_printf("\nUsage: net cache get <key>\n"); return -1; } if (gencache_get(keystr, &valuestr, &timeout)) { print_cache_entry(keystr, valuestr, timeout, NULL); SAFE_FREE(valuestr); return 0; } d_fprintf(stderr, "Failed to find entry\n"); return -1; }