howto receive and *understand* via UDP

E

Ender

Hi,

I've been asked to write an app that connects to a program that I know
nothing about. The only information I have is that it's sending data to
a specific IP via UDP. The data is likely to be small, just some
numbers. I've seen how to connect() via UDP but ...

My questions is, how do I go about writing for something like this if I
know nothing about the data sizes and how the other app is sending
them, other than the above info? How do you parse such data?

Any help, suggestions, tips, etc... much appreciated.
 
D

dj3vande

Hi,

I've been asked to write an app that connects to a program that I know
nothing about. The only information I have is that it's sending data to
a specific IP via UDP. The data is likely to be small, just some
numbers. I've seen how to connect() via UDP but ...

My questions is, how do I go about writing for something like this if I
know nothing about the data sizes and how the other app is sending
them, other than the above info? How do you parse such data?

Step 0: Find out what the data actually looks like.

This, and anything else that happens up until after you've pulled the
data out of the socket and have it in memory, is not covered by the
definition of the C language and is therefore beyond the scope of
comp.lang.c.
Any help, suggestions, tips, etc... much appreciated.

comp.programming might be a better place for general questions about
how to extract the data you're interested in once you've figured out
what the datagrams look like, unless it's specific to what the C code
you write does.


dave
 
J

Jack Klein

Hi,

I've been asked to write an app that connects to a program that I know
nothing about. The only information I have is that it's sending data to
a specific IP via UDP. The data is likely to be small, just some
numbers. I've seen how to connect() via UDP but ...

How you connect via UDP, or any other protocol, is off-topic here,
since the C standard does not define any networking functions. If you
have issues with that, you need to ask in a group that supports your
compiler/OS combination, since it's platform specific.
My questions is, how do I go about writing for something like this if I
know nothing about the data sizes and how the other app is sending
them, other than the above info? How do you parse such data?

I don't see how it is possible at all, unless the values are in text
format and delimited in some manner. If it is in binary, I can't
think of any method at all to extract coherent data from a stream of
raw binary octets if you have no idea what they are supposed to
represent.
Any help, suggestions, tips, etc... much appreciated.

Suggestion? Find out about the program that you know nothing about.
If you can't, tell them you can't write the application.

If whoever asked you to write this application can't provide the
necessary information, tell them that you can try, at their expense,
and with no guarantee of success, to read lots of this data and try to
work out what it represents.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 
R

Rakesh UV

The following are very easy and generic
making a socket,(UDP,TCP)
connecting to a port
receving data

but the size and meaning of data is very specific.

The tool named ethereal would be very useful in understanding the flow
of data, if your application is running
The source code of ethereal is worth seeing, may be u can reuse some
of its code,

RUV
 
M

MisterE

Ender said:
Hi,

I've been asked to write an app that connects to a program that I know
nothing about. The only information I have is that it's sending data to a
specific IP via UDP. The data is likely to be small, just some numbers.
I've seen how to connect() via UDP but ...

My questions is, how do I go about writing for something like this if I
know nothing about the data sizes and how the other app is sending them,
other than the above info? How do you parse such data?

Any help, suggestions, tips, etc... much appreciated.

Google ethereal. If will allow you to capture UDP data.From there you should
be able to see how the packet exchange is working. I did almost this exact
same thing to figure out how to talk to sign posts at a call center.
 
K

karthikbalaguru

Hi,

I've been asked to write an app that connects to a program that I know
nothing about. The only information I have is that it's sending data to
a specific IP via UDP. The data is likely to be small, just some
numbers. I've seen how to connect() via UDP but ...

My questions is, how do I go about writing for something like this if I
know nothing about the data sizes and how the other app is sending
them, other than the above info? How do you parse such data?

Any help, suggestions, tips, etc... much appreciated.

Lot of tools are available to know about the format of data.
You can try etherpeek also. It will give you some good info
about the data that it is sending to a specific IP via UDP.
Once you understand the format of data, it is the usual
parsing w.r.t it combined with some socket programming to read
the data.

Karthik Balaguru
 
K

karthikbalaguru

Hi,

I've been asked to write an app that connects to a program that I know
nothing about. The only information I have is that it's sending data to
a specific IP via UDP. The data is likely to be small, just some
numbers. I've seen how to connect() via UDP but ...

My questions is, how do I go about writing for something like this if I
know nothing about the data sizes and how the other app is sending
them, other than the above info? How do you parse such data?

Any help, suggestions, tips, etc... much appreciated.

What is your development environment ?
Why do you start desiging without any specification ?

Karthik Balaguru
 
R

Richard Heathfield

Ender said:
Hi,

I've been asked to write an app that connects to a program that I know
nothing about. The only information I have is that it's sending data to
a specific IP via UDP. The data is likely to be small, just some
numbers. I've seen how to connect() via UDP but ...

My questions is, how do I go about writing for something like this if I
know nothing about the data sizes and how the other app is sending
them, other than the above info? How do you parse such data?

Start by looking for 8-character fields with the format 99-99-99 (where 9
represents any digit, and - is literal) - those will be the sort codes.
They are useful because they'll effectively give you the record length
(although they won't tell you where the record starts), because you can
measure the distance between successive occurrences.

Then look for 8-character fields with the format 99999999 (the actual bank
account numbers), and fields with the form A999999A (possibly spaced like
this: A 99 99 99 A), which are the NINOs (National Insurance Numbers) - A,
of course, stands for "upper case alphabetic character". You shouldn't
have any bother with the run-of-the-mill stuff like names and addresses,
although you should cater for the possibility that many of them will be
wrong.

You may find that the data has been password-protected, but we have it on
good authority that it has not been encrypted, so it turns out that
"password-protected" doesn't actually mean anything.

Technical aspects aside, though, do you really think you ought to be doing
this? Wouldn't it be better just to send a UDP reply back to the specific
IP address, saying something like "dear specific-IP-address, please do
everyone in Britain a favour by returning both CDs to the UK Government in
a plain brown envelope, and remember to destroy any copies of the data
that you've made".
 
D

Doug

I've been asked to write an app that connects to a program that I know
nothing about. The only information I have is that it's sending data to
a specific IP via UDP. The data is likely to be small, just some
numbers. I've seen how to connect() via UDP but ...
[/QUOTE][/QUOTE]

<snip>

Rakesh said:
The following are very easy and generic
making a socket,(UDP,TCP)
connecting to a port
receving data

but the size and meaning of data is very specific.

The tool named ethereal would be very useful in understanding the flow
of data, if your application is running
The source code of ethereal is worth seeing, may be u can reuse some
of its code,

RUV

This is all off-topic, I know, but since others are joining in...

Remember that the OP is discussing UDP; there are no size issues*
here; datagram messages are delivered singly and completely (or not at
all). (The size is given from the return code from recv/recvonly.)

* not quite true, you need to have provided a buffer big enough for
the incoming datagram; MTU size should be fine.

C-like code below, I'm in a rush so don't have time to compile this,
but if I finish this message in time and it appears then it took less
than 4 minutes and it shouldn't take you long to productise it.

<code for *nix>
/* note error checking omitted */

#include <what's needed!>

int main(void)
{
struct sockaddr_in laddr;
int socket;
char lbuf[your_mtu_size];
int lread;

lsocket = socket(AF_INET, SOCK_DGRAM, 0);
laddr.sin_family = AF_INET;
laddr.sin_addr.s_addr = htonl(INADDR_ANY);
laddr.sin_port = htons(the_port_number_you_want_to_listen_on);

bind(lsocket, (struct sockaddr *)&laddr, sizeof laddr);

for (;;)
{
lread = recvfrom(lsocket, lbuf, sizeof lbuf, 0, NULL, NULL);

/* do something with data */
}

close(lsocket);

return EXIT_SUCCESS;
}

</code>

Once you have the packet data in your hand you can do something with
it. It might be that you need to understand this data - perhaps run-
length-encoding it and writing it to file would be enough. (Perhaps
whoever asked you to write this simply intends you to be another link
in a comms chain somewhere...)

Have to go, hth

Doug
 
M

Mark McIntyre

Ender said:
Hi,

I've been asked to write an app that connects to a program that I know
nothing about. The only information I have is that it's sending data to
a specific IP via UDP. The data is likely to be small, just some
numbers. I've seen how to connect() via UDP but ...

My questions is, how do I go about writing for something like this if I
know nothing about the data sizes and how the other app is sending them,
other than the above info? How do you parse such data?

This is a cryptography problem - you essentially have a stream of data
which you know means *something*, but you have few clues as to what. I
recommend buying some good books on the subject.

You could also call up T Flowers and see if he has any spare Collossi.
 
D

dj3vande

Doug said:
This is all off-topic, I know, but since others are joining in...

Most of the others are giving pointers to better places to look for
information, not incorrect answers.

Remember that the OP is discussing UDP; there are no size issues*
here; datagram messages are delivered singly and completely (or not at
all). (The size is given from the return code from recv/recvonly.)

* not quite true, you need to have provided a buffer big enough for
the incoming datagram; MTU size should be fine.

There is at least one factual error in the preceding quoted material.
Had it been posted in an appropriate newsgroup, it would have been
topical to say what that error is and provide correct information, and
there would have been people with the relevant knowledge to do so (and
to correct any errors in the correction).


dave
 
D

Doug

Most of the others are giving pointers to better places to look for
information, not incorrect answers.

Fair enough.

I saw something interesting, but was in a rush (and a bit bored from
the this afternoon) and brain dumped without thinking. You're right,
it was in the wrong place. For that I apologise to the group.

Do you have to be so impolite about it, though? Oh well.
There is at least one factual error in the preceding quoted material.
Had it been posted in an appropriate newsgroup, it would have been
topical to say what that error is and provide correct information, and
there would have been people with the relevant knowledge to do so (and
to correct any errors in the correction).


dave

I'm interested to know what the error is. But I'm guessing you won't
tell me here. Fair enough; it's clear you're not at all actually
interested in helping anybody. You would be one of those net nannies.

Doug
 
D

dj3vande

Fair enough.

I saw something interesting, but was in a rush (and a bit bored from
the this afternoon) and brain dumped without thinking. You're right,
it was in the wrong place. For that I apologise to the group.

Do you have to be so impolite about it, though? Oh well.

"Impolite" is not the word you're looking for. "Blunt", perhaps.

And no, it wasn't strictly required, but neither was it inappropriate.

I'm interested to know what the error is. But I'm guessing you won't
tell me here.

You guess correctly, but:
Fair enough; it's clear you're not at all actually
interested in helping anybody. You would be one of those net nannies.

Your assumed reason is incorrect. I'm not a net nanny, merely a C
programmer with a fanatical obsession with correctness and a healthy
respect for the purpose behind topicality guidelines.

The reason why I won't say here is because I'm not exactly an expert
myself, and my conclusion that it was an error was a result of thinking
"that doesn't look right" followed by a few minutes of looking up
details. If I were to say what I thought about it here, nobody
(including me) would have any guarantee of either the correctness of my
statement or the kind of peer review that would result in corrections,
and therefore nobody would have any reason to give that any more weight
than they would give what you said.


dave
 
D

Doug

You guess correctly, but:


Your assumed reason is incorrect. I'm not a net nanny, merely a C
programmer with a fanatical obsession with correctness and a healthy
respect for the purpose behind topicality guidelines.

The reason why I won't say here is because I'm not exactly an expert
myself, and my conclusion that it was an error was a result of thinking
"that doesn't look right" followed by a few minutes of looking up
details. If I were to say what I thought about it here, nobody
(including me) would have any guarantee of either the correctness of my
statement or the kind of peer review that would result in corrections,
and therefore nobody would have any reason to give that any more weight
than they would give what you said.


dave

Again, fair enough. I'm really not interested in getting into
arguments.

All I'd say is that if you don't correct the error, some poor helpless
sod will come across my post and be lost forever!

Right, I'm off to the pub.
 
D

Doug

The reason why I won't say here is because I'm not exactly an expert
myself, and my conclusion that it was an error was a result of thinking
"that doesn't look right" followed by a few minutes of looking up
details. If I were to say what I thought about it here, nobody
(including me) would have any guarantee of either the correctness of my
statement or the kind of peer review that would result in corrections,
and therefore nobody would have any reason to give that any more weight
than they would give what you said.


dave

Oh, before I go, I should mention the two errors I've spotted on a re-
read - recvfrom instead of recvonly, and declaration of 'socket'
should be 'lsocket'.

I guess the error you mention would be saying mtu size would be fine
for incoming packets. Yeah, fair enough, my mistake. As I said, was
brain dumping. (In my crap defence, I've never used UDP with packets
mtu and i was thinking of the OP's needs - which were clearly stated
as small packets.)

But yes, this was the wrong venue.

The right venue is the pub, and I'm going there now.

Doug
 
C

CBFalconer

Rakesh said:
The following are very easy and generic
making a socket,(UDP,TCP)
connecting to a port
receving data

The tool named ethereal would be very useful in understanding the
flow of data, if your application is running. The source code of
ethereal is worth seeing, may be u can reuse some of its code,

'u' has not posted here for some time. At the same time this post
is pointless, both because it is off-topic and because is is
top-posted, thus losing all context.

Please do not top-post. Your answer belongs after (or intermixed
with) the quoted material to which you reply, after snipping all
irrelevant material. See the following links:

--
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/> (taming google)
<http://members.fortunecity.com/nnqweb/> (newusers)
 
K

Kenny McCormack

Fair enough.

I saw something interesting, but was in a rush (and a bit bored from
the this afternoon) and brain dumped without thinking. You're right,
it was in the wrong place. For that I apologise to the group.

Do you have to be so impolite about it, though? Oh well.

Heh heh. This is CLC. You got off easy.

In fact, the regulars are often proud of pointing this out - that is,
after they've just thrashed someone, they'll say "You call that
flaming?" and "I've haven't begun to flame...". Even though they've
just been seriously rude by the standards of most other groups (I would
say "all other groups", but that'd just get them busy on finding some
group that's even more rude than CLC).

Note also that the regs will often say that they are not being rude, but
merely being "correct", and/or "helpful". They've even got their
sycophants trained to accept the beatings (say things like "Thank you,
sir, for the correction") and to ask for more. It reads just like
something out of an S&M porn story. What master could ask for more?

You will see that the newbies who get accepted around here are precisely
those who play this game. They see it as the price to pay for getting
any help at all.

Further, the regs will see my post and say things like "We're not being
rude; we're just being correct". Well, its a little hard to analyze
this statement. Either they are lying or they really are just completely
socially inept. My sense is that the excuse of ineptitude only washes
so many times. They should work on their social skills a little more
(maybe letting their supposed C knowledge slip just a little if
necessary).
 
D

Doug

Heh heh. This is CLC. You got off easy.

Yes, clc is a pretty hostile environment. I try not to post here;
sometimes my boredom gets the better of me, but I always regret it,
every time. I don't mind being corrected, best way to learn is to
learn from your mishtakes; but the manner in which those corrections
are delivered here is, frankly, not useful.

Once you weed out the spam and the obvious homework and i = i++ + i++
questions, there's not much here. New posters seldom reply, and a
large portion that do are quickly chewed up. I can't help but feel
this place would be a lot more active and useful and people left their
egos at the door. Ahem, modem.

It annoys me that a useful resource is being misused in this way, but
I don't really see any way to fix it. I'll already be flamed to hell
and back for this post, and will, again, regret it in the morning
(along with the hangover).

Doug
 
G

Golden California Girls

Doug said:
Yes, clc is a pretty hostile environment. I try not to post here;
sometimes my boredom gets the better of me, but I always regret it,
every time. I don't mind being corrected, best way to learn is to
learn from your mishtakes; but the manner in which those corrections
are delivered here is, frankly, not useful.

Once you weed out the spam and the obvious homework and i = i++ + i++
questions, there's not much here. New posters seldom reply, and a
large portion that do are quickly chewed up. I can't help but feel
this place would be a lot more active and useful and people left their
egos at the door. Ahem, modem.

It annoys me that a useful resource is being misused in this way, but
I don't really see any way to fix it. I'll already be flamed to hell
and back for this post, and will, again, regret it in the morning
(along with the hangover).

Doug

Amen

Unfortunately it reflects society today in general.
 
C

CBFalconer

Doug said:
Yes, clc is a pretty hostile environment. I try not to post here;
sometimes my boredom gets the better of me, but I always regret it,
every time. I don't mind being corrected, best way to learn is to
learn from your mishtakes; but the manner in which those corrections
are delivered here is, frankly, not useful.

Don't forget, McCormack is a pure troll, usually PLONKed.
Corrections tend to be quite direct, but not impolite. Too many
people take directness as impolite.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top