greetings,
i am completely new to c# and i'm looking to write a littel util to
extract snmp information from cisco hardware for starters. i have found
some sample code helping me along my way but i'm now looking at a piece
of code which extract the usefull stuff from the responds and cuts away
the useless. this code i don't understand, could someone please tell me
how it works, short and very simple :) ?
here's the code:
-snip-
int commlength, miblength, datatype, datalength, datastart;
int uptime = 0;
string output;
SNMP conn = new SNMP();
byte[] response = new byte[1024];
response = conn.get("get", argv[0], argv[1], "1.3.6.1.2.1.1.5.0");
commlength = Convert.ToInt16(response[6]);
miblength = Convert.ToInt16(response[23 + commlength]);
datatype = Convert.ToInt16(response[24 + commlength + miblength]);
datalength = Convert.ToInt16(response[25 + commlength + miblength]);
datastart = 26 + commlength + miblength;
output = Encoding.ASCII.GetString(response, datastart, datalength);
Console.WriteLine(" sysName - Datatype: {0}, Value:
{1}",datatype,output);
-/snip-
this will extract the hostname from the cisco, the part i don't get is this:
-snip-
commlength = Convert.ToInt16(response[6]);
miblength = Convert.ToInt16(response[23 + commlength]);
datatype = Convert.ToInt16(response[24 + commlength + miblength]);
datalength = Convert.ToInt16(response[25 + commlength + miblength]);
datastart = 26 + commlength + miblength;
output = Encoding.ASCII.GetString(response, datastart, datalength);
Console.WriteLine(" sysName - Datatype: {0}, Value:
{1}",datatype,output);
-/snip-
here output is edited in a way to only return the actual hostname, info
like my snmp community, which is included in the response, gets removed,
but i don't quite understand what's happening there :(
this is probably a very lame question and i'd understand any sort of
RTFM reply, but i'd really really appreciate it if someone could take
the time and help me out :)
thanks for reading and any possible responses,
regards,
milan