Esempio n. 1
0
void check_cache(struct cache_item* pFirstItem)
{
    time_t time_stamp;
    time(&time_stamp);
    int current_time_stamp = ((int)(time_stamp));

    struct cache_item* ptr = pFirstItem;

    while(ptr != NULL)
    {
        if (ptr->next_item == NULL)
        {
            break;
        }

        if (current_time_stamp - ptr->next_item->time_stamp >= 15)
        {
            in_addr ip_addr;
            ip_addr.s_addr = ptr->next_item->ip;
            Debug("\n\n**** Removing cache entry, [%s, ", inet_ntoa(ip_addr));
            DebugMAC(ptr->next_item->mac);
            Debug("] *****\n\n");

            remove_cache_item(ptr);

        }

        ptr = ptr->next_item;
    }
}
Esempio n. 2
0
int sr_handle_hwinfo(struct sr_instance* sr, c_hwinfo* hwinfo)
{
    int num_entries;
    int i = 0;

    /* REQUIRES */
    assert(sr);
    assert(hwinfo);

    num_entries = (ntohl(hwinfo->mLen) - (2*sizeof(uint32_t)))/sizeof(c_hw_entry);

    /* Debug("Received Hardware Info with %d entries\n",num_entries); */

    for ( i=0; i<num_entries; i++ )
    {
        switch( ntohl(hwinfo->mHWInfo[i].mKey))
        {
            case HWFIXEDIP:
                Debug("Fixed IP: %s\n",inet_ntoa(
                            *((struct in_addr*)(hwinfo->mHWInfo[i].value))));
                break;    
            case HWINTERFACE:    
                Debug("INTERFACE: %s\n",hwinfo->mHWInfo[i].value);
                sr_add_interface(sr,hwinfo->mHWInfo[i].value);
                break;
            case HWSPEED:    
                Debug("Speed: %d\n",
                        ntohl(*((unsigned int*)hwinfo->mHWInfo[i].value))); 
                break;
            case HWSUBNET:
                Debug("Subnet: %s\n",inet_ntoa(
                            *((struct in_addr*)(hwinfo->mHWInfo[i].value))));
                break;
            case HWMASK:
                Debug("Mask: %s\n",inet_ntoa(
                            *((struct in_addr*)(hwinfo->mHWInfo[i].value)))); 
                break;
            case HWETHIP:    
                Debug("IP: %s\n",inet_ntoa(
                            *((struct in_addr*)(hwinfo->mHWInfo[i].value))));
                sr_set_ether_ip(sr,*((uint32_t*)hwinfo->mHWInfo[i].value));
                break;
            case HWETHER:
                Debug("\tHardware Address: ");
                DebugMAC(hwinfo->mHWInfo[i].value);
                Debug("\n"); 
                sr_set_ether_addr(sr,(unsigned char*)hwinfo->mHWInfo[i].value);
                break;
            default:
                printf (" %d \n",ntohl(hwinfo->mHWInfo[i].mKey));
        } /* -- switch -- */
    } /* -- for -- */

    printf("Router interfaces:\n");
    sr_print_if_list(sr);

    return num_entries;
} /* -- sr_handle_hwinfo -- */
Esempio n. 3
0
/*******************************************************************
*   Prints single ARP Cache Entry.
*******************************************************************/
void print_cache_entry(struct arp_cache_entry * ent)
{
	struct in_addr ip_addr;
	assert(ent);
	ip_addr.s_addr = ent->ip_add;
	printf("IP: %s MAC: ", inet_ntoa(ip_addr));
	DebugMAC(ent->mac); 
	printf(" Time when Invalid: %lu\n",(long)ent->timenotvalid);
}
void sr_print_if(struct sr_if* iface)
{
    struct in_addr ip_addr;
    unsigned char * addr;
    /* -- REQUIRES --*/
    assert(iface);
    assert(iface->name);
    addr = (unsigned char *) &iface->addr;
    ip_addr.s_addr = iface->ip;

    Debug("%s\tHWaddr ",iface->name);
    DebugMAC(addr);
    Debug("\n\tinet addr %s\n",inet_ntoa(ip_addr));
} /* -- sr_print_if -- */
Esempio n. 5
0
void sr_print_if(struct sr_vns_if* iface)
{
    struct in_addr ip_addr;

    /* -- REQUIRES --*/
    assert(iface);
    assert(iface->name);

    ip_addr.s_addr = iface->ip;

    Debug("%s\tHWaddr",iface->name);
    DebugMAC(iface->addr);
    Debug("\n");
    Debug("\tinet addr %s\n",inet_ntoa(ip_addr));
} /* -- sr_print_if -- */
Esempio n. 6
0
int sr_handle_hwinfo(struct sr_instance* sr, c_hwinfo* hwinfo)
{
    int num_entries;
    int i = 0;
    struct sr_vns_if vns_if;

    /* REQUIRES */
    assert(sr);
    assert(hwinfo);

    num_entries = (ntohl(hwinfo->mLen) - (2*sizeof(uint32_t)))/sizeof(c_hw_entry);
    Debug("Received Hardware Info with %d entries\n",num_entries);

    vns_if.name[0] = 0;

    for ( i=0; i<num_entries; i++ )
    {
        switch( ntohl(hwinfo->mHWInfo[i].mKey))
        {
            case HWFIXEDIP:
                Debug("Fixed IP: %s\n",inet_ntoa(
                            *((struct in_addr*)(hwinfo->mHWInfo[i].value))));
                break;
            case HWINTERFACE:
                Debug("Interface: %s\n",hwinfo->mHWInfo[i].value);
                if (vns_if.name[0])
                { sr_integ_add_interface(sr, &vns_if); vns_if.name[0] = 0; }
                strncpy(vns_if.name, hwinfo->mHWInfo[i].value, SR_NAMELEN);
                break;
            case HWSPEED:
                Debug("Speed: %d\n",
                        ntohl(*((unsigned int*)hwinfo->mHWInfo[i].value)));
                vns_if.speed =
                    ntohl(*((unsigned int*)hwinfo->mHWInfo[i].value));
                break;
            case HWSUBNET:
                Debug("Subnet: %s\n",inet_ntoa(
                            *((struct in_addr*)(hwinfo->mHWInfo[i].value))));
                break;
            case HWMASK:
                Debug("Mask: %s\n",inet_ntoa(
                            *((struct in_addr*)(hwinfo->mHWInfo[i].value))));
                vns_if.mask = *((uint32_t*)hwinfo->mHWInfo[i].value);
                break;
            case HWETHIP:
                Debug("Ethernet IP: %s\n",inet_ntoa(
                            *((struct in_addr*)(hwinfo->mHWInfo[i].value))));
                vns_if.ip = *((uint32_t*)hwinfo->mHWInfo[i].value);
                break;
            case HWETHER:
                Debug("Hardware Address: ");
                DebugMAC(hwinfo->mHWInfo[i].value);
                Debug("\n");
                memcpy(vns_if.addr,
                        (unsigned char*)hwinfo->mHWInfo[i].value, 6);
                break;
            default:
                printf (" %d \n",ntohl(hwinfo->mHWInfo[i].mKey));
        } /* -- switch -- */
    } /* -- for -- */

    if (vns_if.name[0])
    { sr_integ_add_interface(sr, &vns_if); vns_if.name[0] = 0; }

    /* flag that hardware has been initialized */
    sr->hw_init = 1;

    /* let subsystem know all the hardware has been set up */
    sr_integ_hw_setup(sr);

    return num_entries;
} /* -- sr_handle_hwinfo -- */