PERFORCE change 82943 for review
soc-shteryana
soc-shteryana at FreeBSD.org
Wed Aug 31 21:33:16 GMT 2005
http://perforce.freebsd.org/chv.cgi?CH=82943
Change 82943 by soc-shteryana at syrinx on 2005/08/31 21:33:00
fixed tools' helptexts - removed unused option -V
fixed a crash in bsnmpset when passing octetsrting syntax for OID
- in parse_octetstring() - as first argument of memcpy was passed the
address of the pointer to destnation buffer instead of pointer itself
Affected files ...
.. //depot/projects/soc2005/bsnmp/lib/libbsnmp/libbsnmp/bsnmptools.c#2 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/tools/bsnmpget/bsnmpget.c#2 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/tools/bsnmpset/bsnmpset.c#2 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/tools/bsnmpset/bsnmpset.h#2 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/tools/bsnmpwalk/bsnmpwalk.c#2 edit
Differences ...
==== //depot/projects/soc2005/bsnmp/lib/libbsnmp/libbsnmp/bsnmptools.c#2 (text+ko) ====
@@ -46,15 +46,18 @@
#define DEBUG_ARG if(debug_on) fprintf
+/* parse common input options for client tools and fill in the snmp_client * structure -
+input options:
+[-hd] [-v version] [-r retries][-t timeout] [-f filename] [-b buffersize]
+[-s [trans::][community@][server][:port]] */
int snmp_parse_cmd_opts(int argc, char ** argv, struct snmp_client * client,const char * helptxt)
{
int opt = 0, optnum = 0, argnum = 0;
uint size = 0;
- while ((opt = getopt(argc, argv, "v:r:t:f:b:s:hVd")) != EOF) /*I:m: -shteryana - had ideas for these */
+ while ((opt = getopt(argc, argv, "v:r:t:f:b:s:hd")) != EOF)
{
- /* shteryana - add options for txbuff / rxbuff */
switch (opt)
{
case 'h':
@@ -184,8 +187,7 @@
/* parse the command-line provided string into an oid -
- alocate memory for for struct snmp_value and fills in whatever fields it can derive from
- the command line argument and/or the MIB files in /usr/share/snmp
+ alocate memory for for struct snmp_value and fills in fields
returns a pointer to allocated structure or NULL if parse failed
!!! caller must take care to free the allocated memory */
struct snmp_value * snmp_parse_in_oid(char * str)
@@ -245,7 +247,7 @@
return;
}
-/* shteryana - check a pdu received in responce to a SNMP_PDU_GET/SNMP_PDU_GETBULK request
+/* check a pdu received in responce to a SNMP_PDU_GET/SNMP_PDU_GETBULK request
but don't compare syntaxes - when sending a request pdu they must be null */
/* this is a (almost) complete copy of snmp_pdu_check() -
with matching syntaxes checks skipped and some other checks skiped :-/ */
@@ -354,6 +356,7 @@
}
return (buf);
}
+/* check syntax type and print it to stderr */
void snmp_output_val(struct snmp_value * val)
{
char buf[ASN_OIDSTRLEN];
@@ -370,70 +373,59 @@
asn_oid2str_r(&(val->var),buf);
fprintf(stderr, "%s =",buf);
- if (val->syntax == SNMP_SYNTAX_INTEGER)
+ switch(val->syntax)
{
- fprintf(stderr, "int:%d\n",val->v.integer);
- }
- else if(val->syntax == SNMP_SYNTAX_OCTETSTRING)
- {
- ptr = malloc (val->v.octetstring.len + 1);
-
- if(ptr)
- out = snmp_octstr2str(val->v.octetstring.len, val->v.octetstring.octets,ptr);
- if (out)
- fprintf(stderr, "oct:%s\n",out);
- if(ptr)
- free(ptr);
- }
- else if(val->syntax == SNMP_SYNTAX_OID) /* ??? */
- {
- ptr = asn_oid2str_r(&(val->v.oid),ptr);
- if (ptr)
- fprintf(stderr, "oid:%s\n",ptr);
- else
- fprintf(stderr, "oid is NULL\n");
- }
- else if(val->syntax == SNMP_SYNTAX_IPADDRESS)
- {
- fprintf(stderr, "ip:%u.%u.%u.%u\n",val->v.ipaddress[0],val->v.ipaddress[1],val->v.ipaddress[2],val->v.ipaddress[3]);
- }
- else if(val->syntax == SNMP_SYNTAX_COUNTER)
- {
- fprintf(stderr, "cnt32:%u\n",val->v.uint32);
- }
- else if(val->syntax == SNMP_SYNTAX_GAUGE)
- {
- fprintf(stderr, "gauge:%u\n",val->v.uint32);
- }
- else if (val->syntax == SNMP_SYNTAX_TIMETICKS)
- {
- fprintf(stderr, "ticks:%u\n",val->v.uint32);
- }
- else if (val->syntax == SNMP_SYNTAX_COUNTER64)
- {
- fprintf(stderr,"cnt64:%llu\n",val->v.counter64);
- }
- else if(val->syntax == SNMP_SYNTAX_NOSUCHOBJECT)
- {
- fprintf(stderr, "agent returned NOSUCHOBJECT\n");
- }
- else if(val->syntax == SNMP_SYNTAX_NOSUCHINSTANCE)
- {
- fprintf(stderr, "agent returned NOSUCHINSTANCE\n");
- }
- else if(val->syntax == SNMP_SYNTAX_ENDOFMIBVIEW)
- {
- fprintf(stderr, "agent returned ENDOFMIBVIEW\n");
- }
- else if(val->syntax == SNMP_SYNTAX_NULL)
- {
- /* if all is OK - should never come here */
- fprintf(stderr, "agent returned SYNTAX_NULL\n");
- }
- else
- {
- /* if here -then all went completely wrong :-( */
- fprintf(stderr, "agent returned unknown syntax\n");
+ case SNMP_SYNTAX_INTEGER:
+ fprintf(stderr, "int:%d\n",val->v.integer);
+ break;
+ case SNMP_SYNTAX_OCTETSTRING:
+ ptr = malloc (val->v.octetstring.len + 1);
+ if(ptr)
+ out = snmp_octstr2str(val->v.octetstring.len, val->v.octetstring.octets,ptr);
+ if (out)
+ fprintf(stderr, "oct:%s\n",out);
+ if(ptr)
+ free(ptr);
+ break;
+ case SNMP_SYNTAX_OID: /* ??? */
+ ptr = asn_oid2str_r(&(val->v.oid),ptr);
+ if (ptr)
+ fprintf(stderr, "oid:%s\n",ptr);
+ else
+ fprintf(stderr, "oid is NULL\n");
+ break;
+ case SNMP_SYNTAX_IPADDRESS:
+ fprintf(stderr, "ip:%u.%u.%u.%u\n",val->v.ipaddress[0],val->v.ipaddress[1],val->v.ipaddress[2],val->v.ipaddress[3]);
+ break;
+ case SNMP_SYNTAX_COUNTER:
+ fprintf(stderr, "cnt32:%u\n",val->v.uint32);
+ break;
+ case SNMP_SYNTAX_GAUGE:
+ fprintf(stderr, "gauge:%u\n",val->v.uint32);
+ break;
+ case SNMP_SYNTAX_TIMETICKS:
+ fprintf(stderr, "ticks:%u\n",val->v.uint32);
+ break;
+ case SNMP_SYNTAX_COUNTER64:
+ fprintf(stderr,"cnt64:%llu\n",val->v.counter64);
+ break;
+ case SNMP_SYNTAX_NOSUCHOBJECT:
+ fprintf(stderr, "agent returned NOSUCHOBJECT\n");
+ break;
+ case SNMP_SYNTAX_NOSUCHINSTANCE:
+ fprintf(stderr, "agent returned NOSUCHINSTANCE\n");
+ break;
+ case SNMP_SYNTAX_ENDOFMIBVIEW:
+ fprintf(stderr, "agent returned ENDOFMIBVIEW\n");
+ break;
+ case SNMP_SYNTAX_NULL:
+ /* if all is OK - should never come here */
+ fprintf(stderr, "agent returned SYNTAX_NULL\n");
+ break;
+ default:
+ /* if here -then all went completely wrong :-( */
+ fprintf(stderr, "agent returned unknown syntax\n");
+ break;
}
return;
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/tools/bsnmpget/bsnmpget.c#2 (text+ko) ====
@@ -41,10 +41,9 @@
static const char helptxt[] =\
"\
-bsnmpget [-hVd] [-v version] [-r retries][-t timeout] [-f filename] [-b buffersize] [-s [trans::][community@][server][:port]] OID [OID [OID [...]]]\n\
+bsnmpget [-hd] [-v version] [-r retries][-t timeout] [-f filename] [-b buffersize] [-s [trans::][community@][server][:port]] OID [OID [OID [...]]]\n\
options: \n\
-h help print this text\n\
- -V package version print package version\n\
-d debugging output print more information\n\
-v protocol version SNMP version to use : 1 | 2 (default: 2)\n\
-r retries number of retries when sending a request (default: 3)\n\
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/tools/bsnmpset/bsnmpset.c#2 (text+ko) ====
@@ -40,11 +40,10 @@
#include "bsnmpset.h"
static const char helptxt[] = " \
-bsnmpget [-hVd] [-v version] [-r retries][-t timeout] [-f filename] [-b buffersize] [-s [trans::][community@][server][:port]] \n\
+bsnmpget [-hd] [-v version] [-r retries][-t timeout] [-f filename] [-b buffersize] [-s [trans::][community@][server][:port]] \n\
OID=syntax(value) [OID=syntax:value [OID=syntax:value[...]]]\n\
options: \n\
-h help print this text\n\
- -V package version print package version\n\
-d debugging output print more information\n\
-v protocol version SNMP version to use : 1 | 2 (default: 2)\n\
-r retries number of retries when sending a request (default: 3)\n\
@@ -83,7 +82,7 @@
if (errno != 0)
{
DEBUG_SNMPSET(stderr,"Error parsing integer - %s - errno - %d\n",val,errno);
- fprintf(stderr, "Value not supported%s\n",val);
+ fprintf(stderr, "Value not supported %s\n",val);
errno = saved_errno;
return (-1);
}
@@ -98,7 +97,6 @@
return (0);
}
/* here syntax may be one of SNMP_SYNTAX_COUNTER, SNMP_SYNTAX_GAUGE, SNMP_SYNTAX_TIMETICKS - caller has to set it */
-/* shteryana - implement separate functions for setting the 4 different syntaxes */
int parse_uint(struct snmp_value * value, char * val)
{
char * endptr;
@@ -244,7 +242,7 @@
return (-1);
}
- memcpy(&(value->v.octetstring.octets),val,len);
+ memcpy(value->v.octetstring.octets,val,len);
value->syntax = SNMP_SYNTAX_OCTETSTRING;
return (0);
@@ -302,9 +300,9 @@
return (0);
}
-/* parse a cmd line arg of type OID=syntax(value) and fill in whatever fields it can derived from
+/* parse a cmd line arg of type OID=syntax:value and fill in whatever fields it can derived from
input into snmp_value structure - returns pointer to the structure , NULL -on failure
-!!! caller must take care to free returned pointer on exit */
+!!! caller must take care to FREE returned pointer on exit */
struct snmp_value * parse_pair_oid_val(char * str)
{
int cnt = 0, off = 0;
@@ -386,7 +384,9 @@
strlcpy(val,ptr,(size_t)(cnt + 1));
DEBUG_SNMPSET(stderr,"parse_pair_oid_val: Copied value - %s \n",val);
- /* here try parsing the oids and syntaxes and then check values - have to know syntax to check value boundaries */
+
+ /* here try parsing the oids and syntaxes and then check values -
+ have to know syntax to check value boundaries */
if ((snmp_val = snmp_parse_in_oid(oid_str)) == NULL)
{
@@ -424,8 +424,8 @@
return;
}
-/* allocates memory of src->v.octetstring.len bytes - caller has to FREE it when
-no longer needed */
+/* allocates memory of src->v.octetstring.len bytes -
+!!!caller has to FREE it when no longer needed */
int add_octstring_syntax(struct snmp_value * dst,struct snmp_value * src)
{
char * ptr;
@@ -451,8 +451,9 @@
return(0);
}
-/* shteryana - fix this syntaxes must not be null */
-/* check syntaxes - if syntax is one of SNMP_SYNTAX_NULL,SNMP_SYNTAX_NOSUCHOBJECT, SNMP_SYNTAX_NOSUCHINSTANCE, SNMP_SYNTAX_ENDOFMIBVIEW return error */
+
+/* check syntaxes - if syntax is one of SNMP_SYNTAX_NULL,SNMP_SYNTAX_NOSUCHOBJECT,
+SNMP_SYNTAX_NOSUCHINSTANCE, SNMP_SYNTAX_ENDOFMIBVIEW or anything not known - return error */
int snmp_add_syntax_values(struct snmp_value * dst,struct snmp_value * src)
{
if (dst == NULL)
@@ -460,51 +461,45 @@
if (src == NULL)
return (-1);
- if(src->syntax == SNMP_SYNTAX_INTEGER)
+ switch(src->syntax)
{
- dst->v.integer = src->v.integer;
- dst->syntax = SNMP_SYNTAX_INTEGER;
- DEBUG_SNMPSET(stderr,"snmp_add_syntax_values: added SNMP_SYNTAX_INTEGER = %d\n",dst->v.integer);
- }
- else if(src->syntax == SNMP_SYNTAX_TIMETICKS)
- {
- dst->v.uint32 = src->v.uint32;
- dst->syntax = SNMP_SYNTAX_TIMETICKS;
- DEBUG_SNMPSET(stderr,"snmp_add_syntax_values: added SNMP_SYNTAX_TIMETICKS syntax = %u\n",dst->v.uint32);
- }
- else if(src->syntax == SNMP_SYNTAX_GAUGE)
- {
- dst->v.uint32 = src->v.uint32;
- dst->syntax = SNMP_SYNTAX_GAUGE;
- DEBUG_SNMPSET(stderr,"snmp_add_syntax_values: added SNMP_SYNTAX_GAUGE syntax = %u\n",dst->v.uint32);
- }
- else if(src->syntax == SNMP_SYNTAX_COUNTER)
- {
- dst->v.uint32 = src->v.uint32;
- dst->syntax = SNMP_SYNTAX_COUNTER;
- DEBUG_SNMPSET(stderr,"snmp_add_syntax_values: added SNMP_SYNTAX_COUNTER syntax = %u\n",dst->v.uint32);
+ case SNMP_SYNTAX_INTEGER:
+ dst->v.integer = src->v.integer;
+ dst->syntax = SNMP_SYNTAX_INTEGER;
+ DEBUG_SNMPSET(stderr,"snmp_add_syntax_values: added SNMP_SYNTAX_INTEGER = %d\n",dst->v.integer);
+ break;
+ case SNMP_SYNTAX_TIMETICKS:
+ dst->v.uint32 = src->v.uint32;
+ dst->syntax = SNMP_SYNTAX_TIMETICKS;
+ DEBUG_SNMPSET(stderr,"snmp_add_syntax_values: added SNMP_SYNTAX_TIMETICKS syntax = %u\n",dst->v.uint32);
+ break;
+ case SNMP_SYNTAX_GAUGE:
+ dst->v.uint32 = src->v.uint32;
+ dst->syntax = SNMP_SYNTAX_GAUGE;
+ DEBUG_SNMPSET(stderr,"snmp_add_syntax_values: added SNMP_SYNTAX_GAUGE syntax = %u\n",dst->v.uint32);
+ break;
+ case SNMP_SYNTAX_COUNTER:
+ dst->v.uint32 = src->v.uint32;
+ dst->syntax = SNMP_SYNTAX_COUNTER;
+ DEBUG_SNMPSET(stderr,"snmp_add_syntax_values: added SNMP_SYNTAX_COUNTER syntax = %u\n",dst->v.uint32);
+ break;
+ case SNMP_SYNTAX_COUNTER64:
+ dst->syntax = SNMP_SYNTAX_COUNTER64;
+ dst->v.counter64 = src->v.counter64;
+ DEBUG_SNMPSET(stderr,"snmp_add_syntax_values: added SNMP_SYNTAX_COUNTER64 = %llu\n",dst->v.counter64);
+ break;
+ case SNMP_SYNTAX_IPADDRESS:
+ add_ip_syntax(dst,src);
+ DEBUG_SNMPSET(stderr,"snmp_add_syntax_values: added SNMP_SYNTAX_IPADDRESS\n");
+ break;
+ case SNMP_SYNTAX_OCTETSTRING:
+ add_octstring_syntax(dst,src);
+ DEBUG_SNMPSET(stderr,"snmp_add_syntax_values: added SNMP_SYNTAX_OCTETSTRING\n");
+ break;
+ default:
+ DEBUG_SNMPSET(stderr,"snmp_add_syntax_values: unknown syntax %d - return (-1)\n",src->syntax);
+ return (-1);
}
- else if(src->syntax == SNMP_SYNTAX_COUNTER64)
- {
- dst->syntax = SNMP_SYNTAX_COUNTER64;
- dst->v.counter64 = src->v.counter64;
- DEBUG_SNMPSET(stderr,"snmp_add_syntax_values: added SNMP_SYNTAX_COUNTER64 = %llu\n",dst->v.counter64);
- }
- else if(src->syntax == SNMP_SYNTAX_IPADDRESS)
- {
- add_ip_syntax(dst,src);
- DEBUG_SNMPSET(stderr,"snmp_add_syntax_values: added SNMP_SYNTAX_IPADDRESS\n");
- }
- else if(src->syntax == SNMP_SYNTAX_OCTETSTRING)
- {
- add_octstring_syntax(dst,src);
- DEBUG_SNMPSET(stderr,"snmp_add_syntax_values: added SNMP_SYNTAX_OCTETSTRING\n");
- }
- else
- {
- DEBUG_SNMPSET(stderr,"snmp_add_syntax_values: unknown syntax - return (-1)\n");
- return (-1);
- }
snmp_add_value_oid(dst,src);
DEBUG_SNMPSET(stderr,"snmp_add_syntax_values: copied oid\n");
@@ -536,7 +531,7 @@
oid_cnt = argc - i - 1;
- oid_cnt = argc - i - 1; /* forgot to exclude the program name from argc */
+ oid_cnt = argc - i - 1;
DEBUG_SNMPSET(stderr,"oid input count is %d \n",oid_cnt);
@@ -553,8 +548,6 @@
}
/* parse the input OIDs vice versa */
- /* OK, I'm stupid and I can't handle all those indexes
- :-( - that's why I have all those redundant ints */
for(last_oid = argc - 1, cnt = 0; cnt < oid_cnt; cnt++)
{
DEBUG_SNMPSET(stderr,"parsing next %u oid - argv[idx = %d]=%s\n",cnt,last_oid - cnt,argv[last_oid - cnt]);
@@ -569,7 +562,7 @@
snmp_pdu_create(&req,SNMP_PDU_SET);
- /* fill in the oids in the request pdu */
+ /* fill in the oids in the request pdu */
for(i = 0; i < oid_cnt; i++)
{
if(snmp_add_syntax_values((&(req.bindings[i])),in_oids[i]) < 0)
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/tools/bsnmpset/bsnmpset.h#2 (text+ko) ====
@@ -31,17 +31,29 @@
#define _BSNMP_SET_H_
int parse_int(struct snmp_value * value, char * val);
+
int parse_uint(struct snmp_value * value, char * val);
+
int parse_ticks(struct snmp_value * value, char * val);
+
int parse_gauge(struct snmp_value * value, char * val);
+
int parse_counter(struct snmp_value * value, char * val);
+
int parse_uint64(struct snmp_value * value, char * val);
+
int parse_ip(struct snmp_value * value, char * val);
+
int parse_octetstring(struct snmp_value * value,char * val);
+
int parse_syntax_val(struct snmp_value * value, char * syntax, char * val);
+
struct snmp_value * parse_pair_oid_val(char * str);
+
void add_ip_syntax(struct snmp_value * dst,struct snmp_value * src);
+
int add_octstring_syntax(struct snmp_value * dst,struct snmp_value * src);
+
int snmp_add_syntax_values(struct snmp_value * dst,struct snmp_value * src);
#endif /* _BSNMP_SET_H_ */
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/tools/bsnmpwalk/bsnmpwalk.c#2 (text+ko) ====
@@ -40,15 +40,17 @@
#include "bsnmptools.h"
struct snmp_value * snmp_add_dfl_oid(void);
+
void snmp_oid2value(struct snmp_value * dst_oid, struct asn_oid * src_oid);
+
void snmp_value2oid(struct asn_oid * dst_oid, struct snmp_value * src_oid);
+
void snmp_copy_value(struct snmp_value * dst_oid,struct snmp_value * src_oid);
static const char helptxt[] ="\
-bsnmpwalk [-hVd] [-v version] [-r retries][-t timeout] [-f filename] [-b buffersize] [-s [trans::][community@][server][:port]] [OID]\n\
+bsnmpwalk [-hd] [-v version] [-r retries][-t timeout] [-f filename] [-b buffersize] [-s [trans::][community@][server][:port]] [OID]\n\
options: \n\
-h help print this text\n\
- -V package version print package version\n\
-d debugging output print more information\n\
-v protocol version SNMP version to use : 1 | 2 (default: 2)\n\
-r retries number of retries when sending a request (default: 3)\n\
More information about the p4-projects
mailing list