LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieving data from octet string

How do I retrieve data from an Octet String datatype. I am receiving a string from MIB that is of type Octet String string but I am not sure how to deal with it. Do I have to define an array (or some variable) that expects char or int? Any ideas? Below is the function that I am trying to write and the variable 'val' expects something and takes the value that the pointer 'Value' points to (which in my case is the Octet String). OID is the Object ID in MIB.
 
int getVersion ()
{
  char OID[1024];
  int status;
  int  val;
   
  void *Value=NULL;
  unsigned char Type;
  if(uutSession)
  {
    sprintf(OID, "%s.8.2", gOID);
    status = SNMP_Get (uutSession, OID, &Value, &Type);
   
  }
  if(Value)
  
   val = *(int *)Value;
       
 
  return val;
}
 
 
0 Kudos
Message 1 of 2
(3,773 Views)
Although I do not have the SNMP API that you are using, I will attempt to provide some ideas.
 
An octet string should simply be referred to as a char* just as any other string.  Typically, no matter if the string is of hexadecimal type or decimal type or octet type, it should be referred to in terms of a pointer to a series of characters.  In this way, char* should refer to the string in the appropriate manner.
 
That being said, I have seen some instances of network protocol API's that return structs that contain the data.  I know that Winsock works in this manner.  Within the libraries, a special struct is defined and used as the return type on many functions. 
 
I was able to find one example of a struct return type using SNMP.
 
typedef struct {
      OSUINT32 numocts;
      OSOCTET  data[<len>];
} <name>;
 
This is just one example.  Most likely, however, the return type is simply a char*.  I would recommend searching on the internet and, more importantly, looking into the API specifications or the documentation for the functions that you are calling as to how the octet string is returned.
 
Thanks,
Andy McRorie
Applications Engineer
National Instruments
Thanks,

Andy McRorie
NI R&D
0 Kudos
Message 2 of 2
(3,748 Views)