No, the rdata member (not field) is a pointer; it doesn't contain
anything. Are you talking about something that rdata points to?
> 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 want to parse the rdata section of what? Is this coming from a
file? Are we supposed to know what an "rdata section" is? A Google
search indicates that there is such a thing (or perhaps more than one
such things), but it's not part of the C programming language.

--
Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

I realize that my assumption that u_char is a typedef for unsigned
char may have been unwarranted. If u_char is a typedef for a struct
type that contains the flags, services, regexp, and replacement
members, the question makes a bit more sense. (Though the name
"u_char" certainly doesn't point in that direction.)

But it would still be very helful to show us the actual declarations
and a better idea of what you want to do with them.

--
Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

"zoltan" <> writes:
> Keith Thompson wrote:
[...]
>> You want to parse the rdata section of what? Is this coming from a
>> file? Are we supposed to know what an "rdata section" is? A Google
>> search indicates that there is such a thing (or perhaps more than one
>> such things), but it's not part of the C programming language.
>
> ns_rr is a structure which defines the type of the Resource Record (RR)
> as used for DNS Queries. The structure is defined in <arpa/nameser.h> .

You need to ask in a system-specific newsgroup, (perhaps
comp.unix.programmer).

--
Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

<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.

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 :

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 :

zoltan wrote:
> Nick Keighley wrote:
>> zoltan wrote:
>>> 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.
>>
>>
>> --
>> Nick Keighley
>
> 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!

Can't say that I've really seen anything other than people trying to help
you here - and asking you to clarify what it is that's the problem.

I suppose u are referring to the fact that I havent' mentioned anything
about the Domain Name, class etc.

The structure of the NAPTR record acc to RFC 2915 is :

Domain TTL Type Class Order Preference Flags Services Regexp
Replacement. The ns_rr structure defined is <arpa/nameser.h> actually
has separate fields for Domain, TTL, Type and Class. These are
considered as the Header. The remaining fields form the rdata portion.

I just require to extract the fields in the rdata section, so I wrote
this simple program. How is the RDATA section not the same as the one
in the example?

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!