|
Home > Archive > Unix Programming > March 2005 > UDP example
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Hi group,
I am trying to write a udp multicast program. Program sends a packet
(can be veriable length and very big, bigger than MTU). Right now I am
doing it on TCP and since it is reliable, I dont have to worry about
missing pieces. i start each send with a specific string and the size
of the data, and read the string at the receiver end, to find the
start of data and its size. Once I know the size, I receive the exact
amount of data to get one exact packet worth of data. I want to convert
this to UDP multicast. Reliability is not of great importance to me. I
have few questions.
How reliable are IP and UDP checksum. Can I assume, the data i receive
in my application is not garbled.
If I send say 1 MB packet, will I (at application level) receive a 1MB
packet or can I be receiving a bunch of smaller size packets (assuming
no transmission errors).
If there is a transmission error, does UDP discard all the data (i.e.
If I send a 1 MB packet and there is an error somewhere could I end up
receiving 900KB of corrrect data and the last 100KB are dropped?)
Any example program that handles similar situations. Thank you
--MSR
| |
| Gordon Burditt 2005-03-16, 6:02 pm |
| > I am trying to write a udp multicast program. Program sends a packet
>(can be veriable length and very big, bigger than MTU). Right now I am
>doing it on TCP and since it is reliable, I dont have to worry about
>missing pieces. i start each send with a specific string and the size
>of the data, and read the string at the receiver end, to find the
>start of data and its size. Once I know the size, I receive the exact
>amount of data to get one exact packet worth of data. I want to convert
>this to UDP multicast. Reliability is not of great importance to me. I
>have few questions.
>
>How reliable are IP and UDP checksum. Can I assume, the data i receive
>in my application is not garbled.
A 16-bit checksum is not a very reliable way to verify 1MB of data.
Consider an end-to-end check on the whole file (say, md5) which
also has a high probability of detecting missing pieces, out-of-order
pieces, and garbled pieces.
>If I send say 1 MB packet, will I (at application level) receive a 1MB
>packet or can I be receiving a bunch of smaller size packets (assuming
>no transmission errors).
At the network level, it's going to be split up. Ethernet MTUs are
typically 1500, and fiber is somewhere around 4300. Gigabit ethernet
may be able to handle "jumbograms" larger than 64k but I still
doubt it will be anywhere near 1MB any time soon.
>If there is a transmission error, does UDP discard all the data (i.e.
>If I send a 1 MB packet and there is an error somewhere could I end up
>receiving 900KB of corrrect data and the last 100KB are dropped?)
With no (hardware) errors, you could receive packets 8, 3, 15, 1, 6, 10,
etc. in that order, with some missing due to buffer availability rather
than hardware-level errors.
>
>Any example program that handles similar situations. Thank you
Gordon L. Burditt
| |
| David Schwartz 2005-03-16, 6:02 pm |
|
"MSR" <msreddy999@indiatimes.com> wrote in message
news:1111003153.079946.210350@g14g2000cwa.googlegroups.com...
> I am trying to write a udp multicast program. Program sends a packet
> (can be veriable length and very big, bigger than MTU).
Do not call it a packet. Call it a message.
> Right now I am
> doing it on TCP and since it is reliable, I dont have to worry about
> missing pieces. i start each send with a specific string and the size
> of the data, and read the string at the receiver end, to find the
> start of data and its size. Once I know the size, I receive the exact
> amount of data to get one exact packet worth of data. I want to convert
> this to UDP multicast. Reliability is not of great importance to me. I
> have few questions.
Okay.
> How reliable are IP and UDP checksum. Can I assume, the data i receive
> in my application is not garbled.
They're reliable against accidental corruption but worthless against
deliberate tampering.
> If I send say 1 MB packet, will I (at application level) receive a 1MB
> packet or can I be receiving a bunch of smaller size packets (assuming
> no transmission errors).
With UDP, you send datagrams, not packets. The maximum datagram size is
65,536 bytes.
> If there is a transmission error, does UDP discard all the data (i.e.
> If I send a 1 MB packet and there is an error somewhere could I end up
> receiving 900KB of corrrect data and the last 100KB are dropped?)
If the datagram is split over multiple packets, and a packet is lost,
the whole datagram will be lost. There is no such things as a "1MB packet",
the packet size is limited by the MTU.
Read this over a few times until you get it: UDP applications send and
receive datagrams. The maximum datagram size is 65,536 bytes. If a datagram
is larger than the MTU for a link, it will be split into as many packets as
are needed. UDP data will be received by the application at the other end
only if a complete datagram can be assembled. UDP is not reliable --
datagrams may be dropped, duplicated, or received out of order.
DS
| |
|
|
"David Schwartz" <davids@webmaster.com> wrote in message
news:d1a8t5$1pn$1@nntp.webmaster.com...
>
> "MSR" <msreddy999@indiatimes.com> wrote in message
> news:1111003153.079946.210350@g14g2000cwa.googlegroups.com...
>
>
> Do not call it a packet. Call it a message.
>
>
> Okay.
>
>
> They're reliable against accidental corruption but worthless against
> deliberate tampering.
>
>
> With UDP, you send datagrams, not packets. The maximum datagram size is
> 65,536 bytes.
>
>
> If the datagram is split over multiple packets, and a packet is lost,
> the whole datagram will be lost. There is no such things as a "1MB
> packet", the packet size is limited by the MTU.
>
> Read this over a few times until you get it: UDP applications send and
> receive datagrams. The maximum datagram size is 65,536 bytes. If a
> datagram is larger than the MTU for a link, it will be split into as many
> packets as are needed. UDP data will be received by the application at the
> other end only if a complete datagram can be assembled. UDP is not
> reliable -- datagrams may be dropped, duplicated, or received out of
> order.
I did read it many times. If I understand it correctly, if My application
has a message that is larger than 65,536 bytes, then the application has to
split that message into datargrams of size <= 65,535 before calling
sendto(). Application can not call sendto() with more than 65,536 bytes of
data. UDP does not split big messages in smaller datagrams before
transmitting. Am I correct.
Thanks for the help
--MSR
>
> DS
>
>
| |
| Barry Margolin 2005-03-16, 8:47 pm |
| In article <IrydndGG7pusQ6XfRVn-jw@comcast.com>,
"MSR" <msreddy123@comcast.net> wrote:
> Application can not call sendto() with more than 65,536 bytes of
> data. UDP does not split big messages in smaller datagrams before
> transmitting. Am I correct.
Correct. IP will fragment UDP datagrams into packets appropriate to the
network media, but UDP does not have any similar mechanism. It was not
designed with the intent of carrying enormous messages.
For messages of the size you're talking about, a stream transport like
TCP is usually much more appropriate.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
| |
| David Schwartz 2005-03-16, 8:47 pm |
|
"MSR" <msreddy123@comcast.net> wrote in message
news:IrydndGG7pusQ6XfRVn-jw@comcast.com...
> I did read it many times. If I understand it correctly, if My application
> has a message that is larger than 65,536 bytes, then the application has
> to split that message into datargrams of size <= 65,535 before calling
> sendto(). Application can not call sendto() with more than 65,536 bytes of
> data. UDP does not split big messages in smaller datagrams before
> transmitting. Am I correct.
Correct. UDP sends datagrams, period. If you need to split messages into
multiple datagrams, then you must do that. UDP will not do it for you.
> Thanks for the help
You are welcome.
DS
| |
| Malte Starostik 2005-03-17, 3:18 am |
| David Schwartz schrieb:[vbcol=seagreen]
> "MSR" <msreddy123@comcast.net> wrote in message
> news:IrydndGG7pusQ6XfRVn-jw@comcast.com...
>
>
(replying to David as MSR's message didn't arrive here yet)
Actually, the limit is slightly less than 64k, because the complete
datagram including the UDP header (not sure about the IP header) needs
to fit into 64k.
Plus, sendto() will most likely fail with large datagrams unless you
increase the send buffer size before, see SO_SNDBUF in socket(7) for
details.
Cheers,
Malte
| |
|
|
"Barry Margolin" <barmar@alum.mit.edu> wrote in message
news:barmar-38631D.21012616032005@comcast.dca.giganews.com...
> In article <IrydndGG7pusQ6XfRVn-jw@comcast.com>,
> "MSR" <msreddy123@comcast.net> wrote:
>
>
> Correct. IP will fragment UDP datagrams into packets appropriate to the
> network media, but UDP does not have any similar mechanism. It was not
> designed with the intent of carrying enormous messages.
>
> For messages of the size you're talking about, a stream transport like
> TCP is usually much more appropriate.
I already tcp implementation. Need UDP because I want to do multicasting.
>
> --
> Barry Margolin, barmar@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
| |
| Rainer Temme 2005-03-17, 3:18 am |
| MSR wrote:
> How reliable are IP and UDP checksum. Can I assume, the data i receive
> in my application is not garbled.
Hi MSR,
just another remark, since you've got that many good answers, that
nearly everything is covered.
Regarding the checksums ... dont forget that ...
.... the IP-checksum only covers the IP-header (not the payload)
.... the UDP-checksum is not mandatory as the tcp-checksum.
so implementations are free to ignore this field.
and again ... as already pointed out ...
these checksums where designed to protect against
typical errors that happen on transport (and are
not detected by lower layer checksums, if there are any)
not against an attacker modifying your datagrams.
If you want to check integrity of your data, you need
a stronger hash-function (MD5, SHA1)...if you want
to be prepared to detect modifications, use
a HMAC-derivate of one of the above hashes.
Regards ... Rainer
| |
| Barry Margolin 2005-03-17, 8:48 pm |
| In article <d1bfub$sch$1@news.mch.sbs.de>,
Rainer Temme <Rainer.Temme@NoSpam.Siemens.Com> wrote:
> ... the UDP-checksum is not mandatory as the tcp-checksum.
> so implementations are free to ignore this field.
No they aren't. Sending it is optional, but if it's sent they must
check it, unless the application specifically disables this. RFC 1122
says:
If a UDP datagram is received with a checksum that is non-
zero and invalid, UDP MUST silently discard the datagram.
An application MAY optionally be able to control whether UDP
datagrams without checksums should be discarded or passed to
the application.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
| |
| Rainer Temme 2005-03-18, 7:51 am |
| Barry Margolin wrote:
> Rainer Temme <Rainer.Temme@NoSpam.Siemens.Com> wrote:
>
>
>
> No they aren't. Sending it is optional, but if it's sent they must
> check it, unless the application specifically disables this. RFC 1122
> says:
>
> If a UDP datagram is received with a checksum that is non-
> zero and invalid, UDP MUST silently discard the datagram.
> An application MAY optionally be able to control whether UDP
> datagrams without checksums should be discarded or passed to
> the application.
Ah, that our Barry ... always able to cite the correct part of the
correct RFC (wish I'd be able to do that all the time) ... ;-)
Yes Barry, that is of corse correct (as nearly always) ... but that
still wouldn't make me feel better about the use of udp-checksums
only, to verify that data is intakt.
And even the RFC says, that the checksum can be left uncalculated
on the _sending_ side (as opposed to what I said: can be left
unchecked on the _receiving_ side) ... so there is a chance of
exchanging packets without a checksum in place anyhow.
Regards ... Rainer
| |
| Barry Margolin 2005-03-18, 8:48 pm |
| In article <d1e69b$lcm$1@news.mch.sbs.de>,
Rainer Temme <Rainer.Temme@NoSpam.Siemens.Com> wrote:
> Barry Margolin wrote:
>
> Ah, that our Barry ... always able to cite the correct part of the
> correct RFC (wish I'd be able to do that all the time) ... ;-)
>
> Yes Barry, that is of corse correct (as nearly always) ... but that
> still wouldn't make me feel better about the use of udp-checksums
> only, to verify that data is intakt.
> And even the RFC says, that the checksum can be left uncalculated
> on the _sending_ side (as opposed to what I said: can be left
> unchecked on the _receiving_ side) ... so there is a chance of
> exchanging packets without a checksum in place anyhow.
But since we're programming the device that sends the packets, we have
control over that end.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
|
|
|
|
|