Re: Parsing a Section of Binary String Data!



zoltan wrote:
Hi,
The scenario is like this :


struct ns_rr {

const u_char* rdata;
};

What is u_char?
I'll assume it's a struct with (possibly among others) these members:

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?

I have absolutely no idea. If they are, you can use standard string
handling functions to mess with them; if they are not you should take
extra care when dealing with those members.

Here's a short program that tries to put together the information you
provided and uses the individual members of `rdata`.


#include <stdio.h>

struct u_char { /* bad choice of name */
char * flags;
char * services;
char * regexp;
char * replacement;
};

struct ns_rr {
const struct u_char * rdata;
};

int main(void) {
struct u_char dummy = {"flags", "services", "regexp", "replacement"};
struct ns_rr x;

x.rdata = &dummy;
printf("x.rdata->flags is '%s'.\n", x.rdata->flags);
printf("x.rdata->services is '%s'.\n", x.rdata->services);
printf("x.rdata->regexp is '%s'.\n", x.rdata->regexp);
printf("x.rdata->replacement is '%s'.\n", x.rdata->replacement);

return 0;
}


--
If you're posting through Google read <http://cfaj.freeshell.org/google>
.



Relevant Pages

  • Re: Why "const rect& rhs" is used here?
    ... declared as const, as far as i can see, i also ... char pcStudentFirstName; ... // Example where struct is copied. ... void SetStudentName ...
    (microsoft.public.vc.language)
  • Re: Parsing a Section of Binary String Data!
    ... The rdata field contains some fields such as: ... char * flags; ... char * services; ... struct NAPTR ...
    (comp.lang.c)
  • Re: Parsing a Section of Binary String Data!
    ... typedef struct __ns_rr { ... the rdata part can have several fields depending on the specific ... port (all of unsigned int type) and a target string (the ... flags, services, regexp and replacement (all of type char *). ...
    (comp.lang.c)
  • Re: Parsing a Section of Binary String Data!
    ... typedef struct __ns_rr { ... the rdata part can have several fields depending on the specific ... port (all of unsigned int type) and a target string (the ... flags, services, regexp and replacement (all of type char *). ...
    (comp.lang.c)
  • Re: Parsing a Section of Binary String Data!
    ... typedef struct __ns_rr { ... the rdata part can have several fields depending on the specific ... port (all of unsigned int type) and a target string (the ... flags, services, regexp and replacement (all of type char *). ...
    (comp.lang.c)