示例#1
0
文件: iptcrdr.c 项目: shawnl/miniupnp
/* add_redirect_rule2() */
int
add_redirect_rule2(const char * ifname,
                   const char * rhost, unsigned short eport,
                   const char * iaddr, unsigned short iport, int proto,
                   const char * desc, unsigned int timestamp)
{
    int r = addnatrule(proto, eport, iaddr, iport, rhost);
    if(r >= 0)
        add_redirect_desc(eport, proto, desc, timestamp);
    return r;
}
示例#2
0
/* add_redirect_rule2() */
int
add_redirect_rule2(const char * ifname, unsigned short eport,
                   const char * iaddr, unsigned short iport, int proto,
				   const char * desc,
				   const char * eaddr) /* Chun add: for CD_ROUTER */
{
	/* Chun modify: for CD_ROUTER */
	//int r = addnatrule(proto, eport, iaddr, iport);
	int r = addnatrule(proto, eport, iaddr, iport, eaddr); 
	if(r >= 0)
		add_redirect_desc(eport, proto, desc);
	return r;
}
示例#3
0
/* BEGIN 2032802867 zhoujianchun 203875 2012.04.03 added */
int
add_redirect_rule2(const char * rhost, unsigned short eport,
                   const char * iaddr, unsigned short iport, int proto,
                   const char * desc, int enabled)
{
    NP_UPNP_INFO("enter add_redirect_rule2, enabled arg is %d\n", enabled);
    char eaddr[16] = {0};
    /*BEGIN 3082010042 y00248130 2013-8-22 added/modified*/
    int r = -1;     
    /* END  3082010042 y00248130 2013-8-22 added/modified*/
    char rule[256]={0};

    /*if (getifaddr(ifname, eaddr, 16) != 0) return -1;
    sprintf(rule, "rdr %s %s port %d -> %s port %d %s", 
        ifname, eaddr, eport, iaddr, iport, 
        (proto == IPPROTO_TCP)? "tcp":"udp");
    */

    /* this line cause warning:
     * missing initializer(near initialization for 'portmap_info.portmap_enabled')
     */
    //NAT_PORTMAP_INFO_ST portmap_info = {0};
    
    NAT_PORTMAP_INFO_ST portmap_info;
    memset(&portmap_info, 0, sizeof(portmap_info));
    portmap_info.portmap_index = 0;
    portmap_info.portmap_enabled = ENABLE_FEATURE;
    if(NULL != desc)
    {
        strncpy((char *)portmap_info.portmap_name, desc, NAME_LEN_MAX);
    }
    if(NULL != rhost)
    {
        strncpy((char *)portmap_info.remote_host_addr, rhost, IPV4_ADDRESS_LEN);
    }

    if(NULL != iaddr)
    {
        strncpy((char *)portmap_info.internal_client_addr, iaddr, IPV4_ADDRESS_LEN);
    }
    else
    {
        NP_UPNP_DEBUG("internal addr is null, return without rule adding.\n");
        return -1;

    }
    strncpy((char *)portmap_info.protocol, ((IPPROTO_TCP == proto) ? "tcp" : "udp"), IP_PROTO_LEN);
    portmap_info.external_port = eport;
    portmap_info.external_port_end = eport;
    portmap_info.internal_port = iport;
    
    if(1 == enabled)
    {
        r = AddUPnPPortMapRule(&portmap_info);
    }

    /*BEGIN 3082010042 y00248130 2013-8-22 added/modified*/
    if (0 == r)
    {   
        char none[16] = "none";
        NP_UPNP_DEBUG("AddUPnPPortMapRule success.\n");
        add_redirect_desc(eport, proto, eaddr, iaddr, iport, 
                (char *)none, 
                (char *)desc, enabled);
    }
    else
    {
        NP_UPNP_ERROR("AddUPnPPortMapRule fail!\n");
    }
    /* END  3082010042 y00248130 2013-8-22 added/modified*/
    return r;
}