473,545 Members | 4,914 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parsing a Section of Binary String Data!

Hi,
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?
Thanks and Regards,

Timmy Jose.

Mar 22 '06 #1
29 4227
"zoltan" <zo*********@gm ail.com> writes:
Hi,
The scenario is like this :
struct ns_rr {

const u_char* rdata;
};
Is u_char a typedef for unsigned char? (If so, just using "unsigned
char" would be a lot clearer.)
The rdata field contains some fields such as :

char * flags;
char * services;
char * regexp;
char * replacement;
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_Keit h) ks***@mib.org <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.
Mar 22 '06 #2

zoltan wrote:
Hi,
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?
Thanks and Regards,

Timmy Jose.


look at this:
struct ns_rr * a;
puts(a->rdata->flags);

Mar 22 '06 #3
Keith Thompson <ks***@mib.or g> writes:
"zoltan" <zo*********@gm ail.com> writes:
Hi,
The scenario is like this :
struct ns_rr {

const u_char* rdata;
};


Is u_char a typedef for unsigned char? (If so, just using "unsigned
char" would be a lot clearer.)
The rdata field contains some fields such as :

char * flags;
char * services;
char * regexp;
char * replacement;


No, the rdata member (not field) is a pointer; it doesn't contain
anything. Are you talking about something that rdata points to?

[...]

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_Keit h) ks***@mib.org <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.
Mar 22 '06 #4

Keith Thompson wrote:
"zoltan" <zo*********@gm ail.com> writes:
Hi,
The scenario is like this :
struct ns_rr {

const u_char* rdata;
};


Is u_char a typedef for unsigned char? (If so, just using "unsigned
char" would be a lot clearer.)
The rdata field contains some fields such as :

char * flags;
char * services;
char * regexp;
char * replacement;


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_Keit h) ks***@mib.org <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.

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

The rdata "member" points to memory where the various mentioned fields
are stored. This is because the contents of rdata depend on the type of
Resource Record.

So suppose I have a structure of this type ns_rr, how can I extract the
individual fields of the rdata member? Simple query.

Mar 22 '06 #5

do*********@126 .com wrote:
zoltan wrote:
Hi,
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?
Thanks and Regards,

Timmy Jose.

look at this:
struct ns_rr * a;
puts(a->rdata->flags);


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?

Mar 22 '06 #6
"zoltan" <zo*********@gm ail.com> 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.progr ammer).

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <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.
Mar 22 '06 #7
zoltan wrote:
do*********@126 .com 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

Mar 22 '06 #8
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", "replacemen t"};
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>
Mar 22 '06 #9

Nick Keighley wrote:
zoltan wrote:
do*********@126 .com 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!

Regards,

Timmy Jose.

Mar 22 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
11401
by: Hemang Shah | last post by:
Hello fellow Coders! ok, I"m trying to write a very simple application in C#. (Yes its my first program) What I want to do is : 1) Open a binary file 2) Search this file for a particular string. 3) Close the file
9
11335
by: Stargate4004 | last post by:
Hi, I have am converting a VB6 application to VB.net and have run into a problem. The application connects to a TCP port on a Linux box and receives a data buffer. The data buffer contains various fields, some of which are two and four byte integers. In VB6 I used the Mid function to pull data out of the buffer so I could decrypt it (do...
3
1985
by: rh0dium | last post by:
Hi all, I have a file which I need to parse and I need to be able to break it down by sections. I know it's possible but I can't seem to figure this out. The sections are broken by <> with one or more keywords in the <>. What I want to do is to be able to pars a particular section of the file. So for example I need to be able to look...
9
4046
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics" portions of Babe Ruth page (http://www.baseballprospectus.com/dt/ruthba01.shtml) and store that info in a CSV file. Also, I would like to do this for...
3
17267
by: Cuong.Tong | last post by:
Greeting, I am writing my own web server and having some problme parsing the the mulitpart/form-data stream that is sent from the browsers. I have a form looks something like this <form action="process.dll>
3
4364
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in the file) with the location. And for a particular section I parse only that section. The file is something like, .... DATAS
9
1973
by: Paulers | last post by:
Hello, I have a log file that contains many multi-line messages. What is the best approach to take for extracting data out of each message and populating object properties to be stored in an ArrayList? I have tried looping through the logfile using regex, if statements and flags to find the start and end of each message but I do not see a...
3
4495
by: GazK | last post by:
I have been using an xml parsing script to parse a number of rss feeds and return relevant results to a database. The script has worked well for a couple of years, despite having very crude error-trapping (if it finds an error in one of the xml files, the script stops). Recently, the script has stopped working because one of the xml files is...
6
3374
by: i_robot73 | last post by:
I have a file, containing hex values for dates (MMDDYYYY)<status code><??such as: 303530313230303102003035303232303031020030353033323030310200303530343230303102003035303732303031020030353038323030310200 breaking that down: 30353031323030310200 30353032323030310200 30353033323030310200
0
7464
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7805
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7751
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5323
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4943
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3449
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3440
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
700
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.