RE: How to convert BITS data into OCTET String

Abhishek Mishra <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
Thanks JP. Functions you have provided are very useful.

-Abhishek

On Tue, 2007-06-26 at 12:30, Jayaprakasha Guddenahalli Naganna wrote:
> Treat BITS as just OCTET STRING.
> Example API's for processing bits from char* variable,
> Call this function by passing *val* from set_handler,
> /*
>  * bits	-- set val
>  * pos	-- which bit you want to read from set val
>  */
> int bit_get(const unsigned char *bits, int pos) {
>     unsigned int    mask;
>     int             i;
> 
>     mask = 0x80;ple API's for processing bits from char* variable,
>     for (i=0; i < (pos % 8); i++)
>         mask = mask >> 1;
> 
>     return (((mask & bits[(int)(pos / 8)]) == mask) ? 1 : 0);
> }
> 
> Call this function by passing *ret_val* from get_handler,
> /*
>  * bits 	-- ret value from get_handler from function
>  * pos	-- which bit you want to set 
>  */ 
> void bit_set(unsigned char *bits, int pos) {
>     unsigned char      mask;
>     int                i;
> 
>     mask = 0x80;
>     for (i = 0; i < (pos % 8); i++)
>         mask = mask >> 1;
> 
>     bits[pos / 8] = bits[pos / 8] | mask;
>     return;
> } 
> Example snmpset command,
> Snmpset column.<index> x 28
> OR
> snmpset column.<index> b proxyServer,registrarServer
> 
> >> I suppose that numbering would be:
> >> 8 7 6 5 4 3 2 1
> >> - - X - X - - -
> >> If these bits would be set then index 0 of the octet string should be
> 
> >> equal to: 0x28.
> >> Is that correct?
> [JP] yes
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of
> Abhishek Mishra
> Sent: Tuesday, June 26, 2007 11:51 AM
> To: [email protected]
> Cc: Abhishek Mishra
> Subject: How to convert BITS data into OCTET String
> 
> Hi,
> 
> We have a column in the table that have datatype of BITS. After
> compilation of the MIB file, it is converted into a character array. I
> found some information in the RFC# 3416/3417 regarding the conversion
> but could not understand well how to convert BITS field into the octet
> string. Following is the BITS field we are using:
> 
> SYNTAX      BITS {
>                   other(0),
>                   userAgent(1),
>                   proxyServer(2),
>                   redirectServer(3),
>                   registrarServer(4)
>                 }
> 
> Now, I have to set bit 2 (proxyServer) and 4 (registrarServer) into the
> octet string.
> Please guide me how the conversion would actually take place.
> 
> I suppose that numbering would be:
> 8 7 6 5 4 3 2 1
> - - X - X - - -
> 
> If these bits would be set then index 0 of the octet string should be
> equal to: 0x28.
> Is that correct?
> 
> Kind Regards,
> -Abhishek
> 
> ------------------------------------------------------------------------
> -
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Net-snmp-users mailing list
> [email protected]
> Please see the following page to unsubscribe or change other options:
> https://lists.sourceforge.net/lists/listinfo/net-snmp-users
> 

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.