Nick said:
zoltan wrote:
(e-mail address removed) wrote:
zoltan wrote:
The scenario is like this :
struct ns_rr {
const u_char* rdata;
};
The rdata field contains some fields such as :
char * flags;
char * services;
char * regexp;
char * replacement;
I want to parse the rdata section and obtain the individual string
fields as shown above. Can anyone suggest an efficient method? Are
these strings terminiated by '\0' within the rdata section?
you tell me.
<snip>
The problem is this :
ns_rr is the Standard type which is used to store the data.
I know that the various fields ( flag, services etc) are in the rdata
member. So to extract them, I define my own structure like this :
struct NAPTR
{
char * flags;
char * services;
char * regexp;
char * replacement;
};
So the compiler has no idea that there is a field called "flags" inside
the rdata member!!! That is the trouble... Any ideas?
I've read your posts and I still havn't a clue what you're talking
about.
Could you post a small, complete, compilable example. If it doesn't do
what you want then explain what you expected it to do and what it
actually does. Please include definitions of all data structures used.
Okay, Here are the actual structures :
I am supposed to implement a DNS Query. The Information to be processed
resides in RRs ( Resource Records). The header <arpa/nameser.h>
contains the following structure to store the data of these RRs as :
typedef struct __ns_rr {
char name[NS_MAXDNAME];
uint16_t type;
uint16_t rr_class;
uint32_t ttl;
uint16_t rdlength;
const uchar_t *rdata;
} ns_rr;
Now, the rdata part can have several fields depending on the specific
type of Record.
For instance, the SRV type has only the following fields : priority,
weight, port ( all of unsigned int type) and a target string ( the
hostname).
For my requirement, I have to use the data stored in a NAPTR record.
The "rdata" contains the following fields for this type of record :
order, preference ( unsigned int) and
flags, services, regexp and replacement ( all of type char *).
Now, because the definition of the rdata in the ns_rr structure is
generic, I have defined ( as I need to ) a structure as follows, to
store the actual data :
struct NAPTR
{
unsigned int order;
unsigned int preference;
char * flags;
char * services;
char * regexp;
char * replacement;
};
So my question is this : How can I extract the string fields from the
rdata portion of the ns_rr structure and store them into the respective
fields in my user-defined structure?
The integer fields ( order and preference ) are easy enough, being of
fixed size. What about the strings which can be of variable size?
I hope that is clear enough to elicit a suggestion or a positive
response in the least!