FreeBSD/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c
/*
 * Parse a command line argument of type OID=syntax:value and fill in whatever 
 * fields can be derived from the input into snmp_value structure. Reads numeric
 * OIDs.
 */
Parse a command line argument of type OID=syntax:value and fill in whatever
fields can be derived from the input into snmp_value structure.
Parse a command line argument of type OID = syntax : value and fill in whatever fields can be derived from the input into snmp_value structure .
static int32_t
parse_pair_numoid_val(char *str, struct snmp_value *snmp_val)
{
	int32_t cnt;
	char *ptr;
	enum snmp_syntax syntax;
	char oid_str[ASN_OIDSTRLEN];
	ptr = str;
	for (cnt = 0; cnt < ASN_OIDSTRLEN; cnt++)
		if (ptr[cnt] == '=')
			break;
	if (cnt >= ASN_OIDSTRLEN) {
		warnx("OID too long - %s", str);
		return (-1);
	}
	strlcpy(oid_str, ptr, (size_t) (cnt + 1));
	ptr = str + cnt + 1;
	for (cnt = 0; cnt < MAX_CMD_SYNTAX_LEN; cnt++)
		if(ptr[cnt] == ':')
			break;
	if (cnt >= MAX_CMD_SYNTAX_LEN) {
		warnx("Unknown syntax in OID - %s", str);
		return (-1);
	}
	if ((syntax = parse_syntax(ptr)) <= SNMP_SYNTAX_NULL) {
		warnx("Unknown syntax in OID - %s", ptr);
		return (-1);
	}
	ptr = ptr + cnt + 1;
	for (cnt = 0; cnt < MAX_OCTSTRING_LEN; cnt++)
		if (ptr[cnt] == '\0')
			break;
	if (ptr[cnt] != '\0') {
		warnx("Value string too long - %s",ptr);
		return (-1);
	}
	if (snmp_parse_numoid(oid_str, &(snmp_val->var)) < 0) {
		warnx("Error parsing OID %s",oid_str);
		return (-1);
	}
	if (parse_syntax_val(snmp_val, syntax, ptr) < 0)
		return (-1);
	return (1);
}
static int32_t parse_pair_numoid_val ( char * str , struct snmp_value * snmp_val ) { int32_t cnt ; char * ptr ; enum snmp_syntax syntax ; char oid_str [ ASN_OIDSTRLEN ] ; ptr = str ; for ( cnt = 0 ; cnt < ASN_OIDSTRLEN ; cnt ++ ) if ( ptr [ cnt ] == ' ' ) break ; if ( cnt >= ASN_OIDSTRLEN ) { warnx ( " " , str ) ; return ( -1 ) ; } strlcpy ( oid_str , ptr , ( size_t ) ( cnt + 1 ) ) ; ptr = str + cnt + 1 ; for ( cnt = 0 ; cnt < MAX_CMD_SYNTAX_LEN ; cnt ++ ) if ( ptr [ cnt ] == ' ' ) break ; if ( cnt >= MAX_CMD_SYNTAX_LEN ) { warnx ( " " , str ) ; return ( -1 ) ; } if ( ( syntax = parse_syntax ( ptr ) ) <= SNMP_SYNTAX_NULL ) { warnx ( " " , ptr ) ; return ( -1 ) ; } ptr = ptr + cnt + 1 ; for ( cnt = 0 ; cnt < MAX_OCTSTRING_LEN ; cnt ++ ) if ( ptr [ cnt ] == ' \0 ' ) break ; if ( ptr [ cnt ] != ' \0 ' ) { warnx ( " " , ptr ) ; return ( -1 ) ; } if ( snmp_parse_numoid ( oid_str , & ( snmp_val -> var ) ) < 0 ) { warnx ( " " , oid_str ) ; return ( -1 ) ; } if ( parse_syntax_val ( snmp_val , syntax , ptr ) < 0 ) return ( -1 ) ; return ( 1 ) ; }
Parse a command line argument of type OID=syntax:value and fill in whatever
 fields can be derived from the input into snmp_value structure.
Parse a command line argument of type OID = syntax : value and fill in whatever fields can be derived from the input into snmp_value structure .
/*
	 * Here try parsing the OIDs and syntaxes and then check values - have
	 * to know syntax to check value boundaries.
	 */