Beispiel #1
0
/*------------------------------------------------------------------------
 * sat_get - do a get on a variable in the Address Translation Table
 *------------------------------------------------------------------------
 */
int
sat_get(struct snbentry *bindl, int numifaces)
{
	int 	iface, entry, field;



	if (sat_match(bindl, &iface, &entry, &field, numifaces) == SYSERR)
		return SERR_NO_SUCH;
	switch(field) {
	case 1:		/* atIfIndex */
		SVTYPE(bindl) = ASN1_INT;
		SVINT(bindl) = iface;
		return SNMP_OK;
	case 2:		/* atPhysAddress */
		SVTYPE(bindl) = ASN1_OCTSTR;
		SVSTR(bindl) = (char *) getmem(EP_ALEN);
		memcpy(SVSTR(bindl), arptable[entry].ae_hwa,
			EP_ALEN);
		SVSTRLEN(bindl) = EP_ALEN;
		return SNMP_OK;
	case 3:		/* atNetAddress */
		SVTYPE(bindl) = ASN1_IPADDR;
		memcpy(&SVIPADDR(bindl), arptable[entry].ae_pra,
			IP_ALEN);
		return SNMP_OK;
	default:
		break;
	}
	return SERR_NO_SUCH;
}
/*------------------------------------------------------------------------
 * sud_get - perform a get on a variable in the UDP listener table
 *------------------------------------------------------------------------
 */
int
sud_get(struct snbentry *bindl, int numifaces)
{
	int 	field, udpn;


	if (sud_match(bindl, &field, &udpn) == SYSERR)
		return SERR_NO_SUCH;
	switch (field) {
	case 1:		/* udpLocalAddress */
		{
	  	IPaddr ip_allzero = 0;
		SVTYPE(bindl) = ASN1_IPADDR;
		SVIPADDR(bindl)=ip_allzero;  /* accept any, rfc 1213 */
		}
		break;
	case 2:		/* udpLocalPort */
		SVTYPE(bindl) = ASN1_INT;
		SVINT(bindl) = upqs[udpn].up_port; 
		break;
	default:
		return SERR_NO_SUCH;
	}
	return SNMP_OK;
}
Beispiel #3
0
/*------------------------------------------------------------------------
 * parsevalue - parse the type and value of variable to set
 *------------------------------------------------------------------------
 */
LOCAL int
parsevalue(char **word, struct snbentry *bl)
{
	if (strequ(*word, "int"))
		SVTYPE(bl) = ASN1_INT;
	else if (strequ(*word, "counter")) 
		SVTYPE(bl) = ASN1_COUNTER;
	else if (strequ(*word, "gauge")) 
		SVTYPE(bl) = ASN1_GAUGE;
	else if (strequ(*word, "timeticks")) 
		SVTYPE(bl) = ASN1_TIMETICKS;
	else if (strequ(*word, "str")) 
		SVTYPE(bl) = ASN1_OCTSTR;
	else if (strequ(*word, "objid")) 
		SVTYPE(bl) = ASN1_OBJID;
	else if (strequ(*word, "ipaddr")) 
		SVTYPE(bl) = ASN1_IPADDR;
	else
		return SYSERR;

	getword(word);
	if (**word == NULLCH)
		return SYSERR;

	switch (SVTYPE(bl)) {
	case ASN1_INT:
	case ASN1_COUNTER:
	case ASN1_GAUGE:
	case ASN1_TIMETICKS:
		SVINT(bl) = atoi(*word);
		break;
	case ASN1_OCTSTR:
		SVSTRLEN(bl) = strlen(*word);
		SVSTR(bl) = (char *) getmem(SVSTRLEN(bl));
		memcpy(SVSTR(bl), *word, SVSTRLEN(bl));
		break;
	case ASN1_OBJID:
		SVOIDLEN(bl) = dot2oid(SVOID(bl), *word);
		break;
	case ASN1_IPADDR:
		SVIPADDR(bl) = dot2ip(*word);
		break;
	default:
		return SYSERR;
	}
	return OK;
}
Beispiel #4
0
/*------------------------------------------------------------------------
 * a1writeval - convert the value of a variable into ASN.1 equivalent.
 *------------------------------------------------------------------------
 */
int
a1writeval(struct snbentry *bl, u_char *bp)
{
	u_char	*origbp;

	origbp = bp;
	*bp++ = SVTYPE(bl);
	
	switch(SVTYPE(bl)) {
	case ASN1_INT:
	case ASN1_COUNTER:
	case ASN1_GAUGE:
	case ASN1_TIMETICKS:
		bp += a1writeint(SVINT(bl), bp, SVTYPE(bl));
		break;
	case ASN1_NULL:
		*bp++ = (u_char) 0;
		break;
	case ASN1_OCTSTR:
		bp += a1writelen(bp, SVSTRLEN(bl));
		memcpy(bp, SVSTR(bl), SVSTRLEN(bl));
		bp += SVSTRLEN(bl);
		freemem(SVSTR(bl), SVSTRLEN(bl));
		break;
	case ASN1_IPADDR:
		*bp++ = IP_ALEN;
		memcpy(bp, &SVIPADDR(bl), IP_ALEN);
		bp += IP_ALEN;
		break;
	case ASN1_OBJID:
		bp += a1writeoid(bp, &bl->sb_val.sv_val.sv_oid);
		break;
	default:
		break;
	}
	
	return bp - origbp;
}
/*------------------------------------------------------------------------
 * snm_get - do a get on a variable in the IP NetToMedia Table
 *------------------------------------------------------------------------
 */
int
snm_get(struct snbentry *bindl, int numifaces)
{
	int 	iface, entry, field;



	if (snm_match(bindl, &iface, &entry, &field, numifaces) == SYSERR)
		return SERR_NO_SUCH;
	switch(field) {
	case 1:		/* ipNetToMediaIfIndex */
		SVTYPE(bindl) = ASN1_INT;
		SVINT(bindl) = iface;
		return SNMP_OK;
	case 2:		/* ipNetToMediaPhysAddress */
		SVTYPE(bindl) = ASN1_OCTSTR;
		SVSTR(bindl) = (char *) getmem(EP_ALEN);
		memcpy(SVSTR(bindl), arptable[entry].ae_hwa,
			EP_ALEN);
		SVSTRLEN(bindl) = EP_ALEN;
		return SNMP_OK;
	case 3:		/* ipNetToMediaNetAddress */
		SVTYPE(bindl) = ASN1_IPADDR;
		memcpy(&SVIPADDR(bindl), arptable[entry].ae_pra,
			IP_ALEN);
		return SNMP_OK;
	case 4:		/* ipNetToMediaType */
		SVTYPE(bindl) = ASN1_INT;
		if (arptable[entry].ae_state == AS_FREE)
		    SVINT(bindl) = 2;  /* invalid(2) */
		else
		    SVINT(bindl) = 3;  /* dynamic(3) */
		return SNMP_OK;
	default:
		break;
	}
	return SERR_NO_SUCH;
}