Re: Using IBM i built-in SNMP-Client support: Accessing a union member within a (nested) struct

Patrik Schindler <[email protected]> Thu, 30 Dec 2021 13:41:49 +0100
Newsgroups gmane.comp.lang.as400.c
Message-ID <[email protected]>
Hello,

after some fiddling, I have new insights and the central question is way more easy.


Am 28.12.2021 um 00:11 schrieb Patrik Schindler <[email protected]>:

> typedef struct {
>   unsigned char pdu_type;
>   int     error_status;
>   int     error_index;
>   varBind * varbind;
> } snmppdu;
> 
> typedef struct _varBind{
>   struct _varBind * next;
>   char   *oid;             /* NULL terminated    */
>   unsigned char asn_type;
>   int    val_len;
>   union {
>      int  * int_val;
>      char * str_val;
>   } val;
> };
> 
> typedef struct _varBind varBind;

When I run the program with different OIDs, pdu->varbind->val_len apparently has the correct size for the returned data. The remaining question is: How to correctly access the data in that union?

Code:

Qp0zLprintf("Result has %d bytes and is: %s\n", pdu->varbind->val_len, pdu->varbind->val.str_val);

This is the only variant of dots and -> which does compile without error.

Thanks!

(I deliberately leave out the conversion from EBCDIC to ASCII for the sake of simplifying my question.)

:wq! PoC

-- 
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list
To post a message email: [email protected]
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/c400-l
or email: [email protected]
Before posting, please take a moment to review the archives
at https://archive.midrange.com/c400-l.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com