⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ip.c

📁 eCos/RedBoot for勤研ARM AnywhereII(4510) 含全部源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
#endif
            + ipstat.ips_toolong
                ) -
            ipstat.ips_cantforward;
        if ( 0 > long_ret )
            long_ret = 0;
        return (unsigned char *) &long_ret;

    case IPINDELIVERS:
        long_ret = ipstat.ips_delivered;
        return (unsigned char *) &long_ret;

    case IPOUTREQUESTS:
        long_ret = ipstat.ips_localout;
        return (unsigned char *) &long_ret;

    case IPOUTDISCARDS:
        long_ret = ipstat.ips_odropped;
        return (unsigned char *) &long_ret;

    case IPOUTNOROUTES:
        long_ret = ipstat.ips_noroute;
        return (unsigned char *) &long_ret;

    case IPREASMTIMEOUT:
        long_ret = 0; //FIXME
        return (unsigned char *) &long_ret;

    case IPREASMREQDS:
        long_ret = ipstat.ips_fragments;
        return (unsigned char *) &long_ret;

    case IPREASMOKS:
        long_ret = ipstat.ips_reassembled;
        return (unsigned char *) &long_ret;

    case IPREASMFAILS:
        long_ret = ipstat.ips_fragments - 
            (ipstat.ips_fragdropped + ipstat.ips_fragtimeout);
        return (unsigned char *) &long_ret;

    case IPFRAGOKS:
        long_ret = ipstat.ips_fragmented;
        return (unsigned char *) &long_ret;

    case IPFRAGFAILS:
        long_ret = ipstat.ips_cantfrag;
        return (unsigned char *) &long_ret;

    case IPFRAGCREATES:
        long_ret = ipstat.ips_ofragments;
        return (unsigned char *) &long_ret;

    case IPROUTINGDISCARDS:
        long_ret = ipstat.ips_noroute;
        return (unsigned char *) &long_ret;

    default:
      ERROR_MSG("");
  }
  return NULL;
}


/*
 * var_ipAddrTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_ipAddrTable above.
 */
unsigned char *
var_ipAddrTable(struct variable *vp,
                oid     *name,
                size_t  *length,
                int     exact,
                size_t  *var_len,
                WriteMethod **write_method)
{
    /*
     * object identifier is of form:
     * 1.3.6.1.2.1.4.20.1.?.A.B.C.D,  where A.B.C.D is IP address.
     * IPADDR starts at offset 10.
     */
    oid			    lowest[14];
    oid			    current[14], *op;
    u_char		    *cp;

    static long long_ret;
    static unsigned char string[SPRINT_MAX_LEN];

    register struct in_ifaddr *ia;
    register struct in_ifaddr *low_ia = NULL;

    register struct ifnet *ifp;
    int interface_count = 1;

    /* fill in object part of name for current (less sizeof instance part) */
    memcpy( (char *)current,(char *)vp->name, (int)vp->namelen * sizeof(oid));

    for (
#ifdef CYGPKG_NET_OPENBSD_STACK
	 ia = in_ifaddr.tqh_first; ia; 
	 ia = ia->ia_list.tqe_next
#endif
#ifdef CYGPKG_NET_FREEBSD_STACK
	 ia = in_ifaddrhead.tqh_first; ia; 
	 ia = ia->ia_link.tqe_next
#endif
	 ) {
	cp = (u_char *)&(ia->ia_addr.sin_addr.s_addr);

	op = current + 10;
	*op++ = *cp++;
	*op++ = *cp++;
	*op++ = *cp++;
	*op++ = *cp++;
	if (exact){
	    if (snmp_oid_compare(current, 14, name, *length) == 0) {
		memcpy( (char *)lowest,(char *)current, 14 * sizeof(oid));
		low_ia = ia;
                break;	/* no need to search further */
	    }
	} else {
	    if ((snmp_oid_compare(current, 14, name, *length) > 0) &&
                (!low_ia || (snmp_oid_compare(current, 14, lowest, 14) < 0))) {
		/*
		 * if new one is greater than input and closer to input than
		 * previous lowest, save this one as the "next" one.
		 */
		memcpy( (char *)lowest,(char *)current, 14 * sizeof(oid));
		low_ia = ia;
	    }
	}
    }

    if ( ! low_ia )
        return NULL;

    memcpy( (char *)name,(char *)lowest, 14 * sizeof(oid));
    *length = 14;
    *write_method = 0;
    *var_len = sizeof(long_return);

    /* 
     * this is where we do the value assignments for the mib results.
     */
    switch(vp->magic) {

    case IPADENTADDR:
        cp = (u_char *)&(low_ia->ia_addr.sin_addr.s_addr);
        string[0] = *cp++;
        string[1] = *cp++;
        string[2] = *cp++;
        string[3] = *cp++;
        *var_len = 4;
        return (unsigned char *) string;

    case IPADENTIFINDEX:
        ifp =  ifnet.tqh_first;
        while (ifp && ifp->if_index != low_ia->ia_ifa.ifa_ifp->if_index) {
            interface_count++;
            ifp = ifp->if_list.tqe_next;
        }
        if (!ifp) {
            return NULL;
        }
        long_ret = interface_count;
        return (unsigned char *) &long_ret;

    case IPADENTNETMASK:
        cp = (u_char *)&(low_ia->ia_subnetmask);
        string[0] = *cp++;
        string[1] = *cp++;
        string[2] = *cp++;
        string[3] = *cp++;
        *var_len = 4;
        return (unsigned char *) string;

    case IPADENTBCASTADDR:
        long_ret = 1;
        return (unsigned char *) &long_ret;

    case IPADENTREASMMAXSIZE:
        long_ret = IP_MAXPACKET;
        return (unsigned char *) &long_ret;

    default:
      ERROR_MSG("");
    }
    return NULL;
}




/*
 * var_ipNetToMediaTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_ip above.
 */

// According to sections 6.1.5 (ip) and 6.1.4 (at) pp.130-138 of the book
// by William Stallings, this lists *our* interfaces only, not the ARP
// table.  The MIBs are rather ambiguous, as is Mark A. Miller's book also.
// 
// Specifically, the indexing by interface Id suggests there should only be
// one entry per interface.

unsigned char *
var_ipNetToMediaTable(struct variable *vp,
    	    oid     *name,
    	    size_t  *length,
    	    int     exact,
    	    size_t  *var_len,
    	    WriteMethod **write_method)
{
    static long long_ret;
    static unsigned char string[SPRINT_MAX_LEN];
    /*
     * IP Net to Media table object identifier is of form:
     * 1.3.6.1.2.1.4.22.1.?.interface.A.B.C.D,  where A.B.C.D is IP address.
     * Interface is at offset 10,
     * IPADDR starts at offset 11.
     */
    u_char		    *cp;
    oid			    *op;
    oid			    lowest[16];
    oid			    current[16];

    register struct in_ifaddr *ia;
    register struct in_ifaddr *low_ia = NULL;

    /* fill in object part of name for current (less sizeof instance part) */
    memcpy((char *)current, (char *)vp->name, (int)vp->namelen * sizeof(oid));

    for (
#ifdef CYGPKG_NET_OPENBSD_STACK
	 ia = in_ifaddr.tqh_first; ia; 
	 ia = ia->ia_list.tqe_next
#endif
#ifdef CYGPKG_NET_FREEBSD_STACK	 
	   ia = in_ifaddrhead.tqh_first; ia; 
	 ia = ia->ia_link.tqe_next
#endif
	 ) {
        // interface number
        current[10] = ia->ia_ifa.ifa_ifp->if_index;
        // IP address
	cp = (u_char *)&(ia->ia_addr.sin_addr.s_addr);
	op = current + 11;
	*op++ = *cp++;
	*op++ = *cp++;
	*op++ = *cp++;
	*op++ = *cp++;
        
	if (exact){
	    if (snmp_oid_compare(current, 15, name, *length) == 0){
		memcpy( (char *)lowest,(char *)current, 15 * sizeof(oid));
		low_ia = ia;
		break;	/* no need to search further */
	    }
	} else {
	    if ((snmp_oid_compare(current, 15, name, *length) > 0) &&
                ((!low_ia) || (snmp_oid_compare(current, 15, lowest, 15) < 0))) {
		/*
		 * if new one is greater than input and closer to input than
		 * previous lowest, save this one as the "next" one.
		 */
		memcpy( (char *)lowest,(char *)current, 15 * sizeof(oid));
		low_ia = ia;
	    }
	}
    }
    if ( ! low_ia )
	return(NULL);

    memcpy( (char *)name,(char *)lowest, 15 * sizeof(oid));
    *length = 15;
    *write_method = 0;
    *var_len = sizeof(long_return);

    /* 
     * this is where we do the value assignments for the mib results.
     */
    switch(vp->magic) {
    case IPNETTOMEDIAIFINDEX:
        //NOTSUPPORTED: *write_method = write_ipNetToMediaIfIndex;
        long_ret = low_ia->ia_ifa.ifa_ifp->if_index;
        return (unsigned char *) &long_ret;

    case IPNETTOMEDIAPHYSADDRESS: {
        struct eth_drv_sc *sc = low_ia->ia_ifa.ifa_ifp->if_softc;
        if (!sc) {
            // No hardware associated with this device.
            return(NULL);
        }
        bcopy(&sc->sc_arpcom.ac_enaddr, string, ETHER_ADDR_LEN);
        *var_len = ETHER_ADDR_LEN;
        //NOTSUPPORTED: *write_method = write_ipNetToMediaPhysAddress;
        return (unsigned char *) string;
    }
    case IPNETTOMEDIANETADDRESS:
        //NOTSUPPORTED: *write_method = write_ipNetToMediaNetAddress;
	cp = (u_char *)&(low_ia->ia_addr.sin_addr.s_addr);
        string[0] = *cp++;
        string[1] = *cp++;
        string[2] = *cp++;
        string[3] = *cp++;
        *var_len = 4;
        return (unsigned char *) string;

    case IPNETTOMEDIATYPE:
        //NOTSUPPORTED: *write_method = write_ipNetToMediaType;
        long_ret = 4; // Static mapping
        return (unsigned char *) &long_ret;

    default:
        ERROR_MSG("");
    }
    return NULL;
}




int
write_ipForwarding(int      action,
            u_char   *var_val,
            u_char   var_val_type,
            size_t   var_val_len,
            u_char   *statP,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -