Changeset 11627


Ignore:
Timestamp:
02/17/09 19:17:17 (4 years ago)
Author:
BrainSlayer
Message:

some upnp updates for wan ip detection

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/router/upnp/src/linux/linux_osl.c

    r11612 r11627  
    573573upnp_osl_wan_ip(struct in_addr *inaddr) 
    574574{ 
    575         char tmp[32]; 
     575        inaddr->s_addr = 0; 
     576        char *wanface = get_wan_face(); 
    576577        int status = 0; 
    577  
    578         inaddr->s_addr = 0; 
    579  
    580         if (strcasecmp(nvram_safe_get(igd_pri_wan_var(tmp, sizeof(tmp), "proto")), 
    581                 "disabled") != 0) { 
    582                 if (upnp_osl_ifaddr(nvram_safe_get(igd_pri_wan_var(tmp, 
    583                         sizeof(tmp), "ifname")), inaddr) == 0) { 
    584                         if (inaddr->s_addr != 0) { 
    585                                 status = 1; 
    586                         } 
     578        if (upnp_osl_ifaddr(wanface, inaddr) == 0) { 
     579                if (inaddr->s_addr != 0) { 
     580                        status = 1; 
    587581                } 
    588582        } 
    589  
    590583        return status; 
    591584} 
     
    594587upnp_osl_wan_isup() 
    595588{ 
    596         struct in_addr inaddr = {0}; 
    597589        int  status = 0; 
    598         char tmp[100]; 
    599  
    600         if (strcasecmp(nvram_safe_get(igd_pri_wan_var(tmp, sizeof(tmp), "proto")), 
    601                 "disabled") != 0) { 
    602                 if (upnp_osl_ifaddr(nvram_safe_get(igd_pri_wan_var(tmp, 
    603                         sizeof(tmp), "ifname")), &inaddr) == 0) { 
    604                         if (inaddr.s_addr != 0) { 
    605                                 status = 1; 
    606                         } 
    607                 } 
    608         } 
    609  
     590        int link =  check_wan_link(0); 
     591        if (link) 
     592            status=1; 
    610593        return status; 
    611594} 
     
    614597upnp_osl_wan_uptime() 
    615598{ 
    616         FILE *fp; 
    617         long int second1, second2; 
    618  
    619         fp = fopen("/proc/uptime", "r"); 
    620         if (!fp) { 
    621                 fprintf(stderr, "can't open \"uptime\" !\n"); 
    622                 return -1; 
    623         } 
    624  
    625         fscanf(fp, "%ld.%ld", &second1, &second2); 
    626         fclose(fp); 
    627  
    628         return second1; 
     599    FILE *fp; 
     600    if( nvram_match( "wan_proto", "disabled" ) ) 
     601        return -1; 
     602    if( nvram_match( "wan_ipaddr", "0.0.0.0" ) ) 
     603    { 
     604        return -1; 
     605    } 
     606    if( !( fp = fopen( "/tmp/.wanuptime", "r" ) ) ) 
     607    { 
     608        return -1; 
     609    } 
     610    float uptime; 
     611    if( !feof( fp ) && fscanf( fp, "%f", &uptime ) == 1 ) 
     612    { 
     613        float sys_uptime; 
     614        FILE *fp2 = fopen( "/proc/uptime", "r" ); 
     615        fscanf( fp2, "%f", &sys_uptime ); 
     616        fclose( fp2 ); 
     617        uptime = sys_uptime - uptime; 
     618        return (int)uptime; 
     619    } 
     620    return -1; 
    629621} 
    630622 
     
    650642        } 
    651643 
     644        /* We want to match destination ip address */ 
     645        if(nvram_match("wan_proto","pptp")) 
     646        { 
     647            inet_aton(nvram_safe_get("pptp_get_ip"), &nat.match.dst.ipaddr); 
     648        } 
     649        else if(nvram_match("wan_proto","l2tp")) 
     650        { 
     651            inet_aton(nvram_safe_get("l2tp_get_ip"), &nat.match.dst.ipaddr); 
     652        } 
     653        else 
     654        { 
     655            inet_aton(nvram_safe_get("wan_ipaddr"), &nat.match.dst.ipaddr); 
     656        } 
     657        nat.match.dst.netmask.s_addr = htonl(0xffffffff); 
    652658        /* Set up LAN side match */ 
    653659        memset(&filter, 0, sizeof(filter)); 
     
    687693        } 
    688694 
     695 
    689696        /* Set up LAN side match */ 
    690697        memset(&filter, 0, sizeof(filter)); 
Note: See TracChangeset for help on using the changeset viewer.