Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-05-2005, 08:17 PM   #1
Registered: Jan 2003
Posts: 76

Rep: Reputation: 15
How to read udp datagram length?


Here's the code that I have figured out.

#include udp.h


struct udphdr *udp;

??? i = ??? udp->len;

The problem is that in the udp header file, it is declared as:

_u16 len;

Which data type should I use in ??? in order to print out the number of bytes in this UDP datagram?

Please assist.
Old 01-05-2005, 08:22 PM   #2
LQ Guru
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
You'd probably be safe just using an unsigned int, and assigning the value, like so:

unsigned int udpLength = udp->len
I'm not sure, but I'd guess that the __u16 type is defined in the compiler as a 16-bit unsigned integer, so assigning it to another int should be no problem.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read UDP packet payload ? sceadu Programming 2 02-07-2006 09:00 PM
Password length ust Linux - Distributions 1 04-06-2005 05:18 AM
RFC 868 udp 37 time-udp gpl SUSE / openSUSE 2 03-31-2005 10:07 AM
How to receive UDP and ICMP packets, by one UDP socket(PMTUD) myself_rajat Linux - Networking 0 05-28-2004 05:43 AM
sound length mihman Linux - Software 0 08-21-2003 05:21 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:51 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration