473,326 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

union field length mismatch

Hello,
In linux kernel there is a struct skbuff that used to store packets. It
has many fields defined in it. thers a union
union
{
struct iphdr *iph;
struct ipv6hdr *ipv6h;
struct arphdr *arph;
struct ipxhdr *ipxh;
unsigned char *raw;
} nh;

I want to ask once IP header is added to skbuff structure all pointers
in union carry same information. We know IP header is 20 bytes long.
Then i try to send raw variable to my function in kernel module.
processip(sb->nh.raw) where sb is of typr struct skbuff
Then why strlen on (sb->nh.raw) doesnot give 20 bytes as result instead
its giving 1.
I want my function to take ip header as unsigned char and print its
strlen as 20 and want to process on it further.

Nov 14 '05 #1
3 1450
li*************@gmail.com wrote:
Hello,
In linux kernel there is a struct skbuff that used to store packets. It
has many fields defined in it. thers a union
union
{
struct iphdr *iph;
struct ipv6hdr *ipv6h;
struct arphdr *arph;
struct ipxhdr *ipxh;
unsigned char *raw;
} nh;

I want to ask once IP header is added to skbuff structure all pointers
in union carry same information. We know IP header is 20 bytes long.
Then i try to send raw variable to my function in kernel module.
processip(sb->nh.raw) where sb is of typr struct skbuff
Then why strlen on (sb->nh.raw) doesnot give 20 bytes as result instead
its giving 1.
I want my function to take ip header as unsigned char and print its
strlen as 20 and want to process on it further.


Can't see anything here which wolud be related to Standrad C. You should
look in an newsgroup about unix linux programming instead.

But here are some remarks:

Not every [unsigned] char* points to a string here it is used as pointer to
a memoryblock which may contain one of the four headers (I think) which
differ in size sizeof(struct ipv6h) > sizeof(struct(iph) == 20.

I think you should find some type tag in the sk_buff struct which will tell
you something about the contents of nh. And if you are lucky you will find
size information too.

--
Michael Knaup
Nov 14 '05 #2
# union
# {
# struct iphdr *iph;
# struct ipv6hdr *ipv6h;
# struct arphdr *arph;
# struct ipxhdr *ipxh;
# unsigned char *raw;
# } nh;
#
# I want to ask once IP header is added to skbuff structure all pointers
# in union carry same information. We know IP header is 20 bytes long.
# Then i try to send raw variable to my function in kernel module.
# processip(sb->nh.raw) where sb is of typr struct skbuff
# Then why strlen on (sb->nh.raw) doesnot give 20 bytes as result instead
# its giving 1.

strlen(s) is the number of nonzero chars starting from s until the first zero
char. It is a runtime determined value. The raw packet header is not a C string
(with respect to <string.h>) but a byte array of a specific length which is
allowed to have zero bytes intermingled with nonzero bytes. You will have to
determine the size some other way, perhaps an enum or #define which has the
size, or the sizeof the struct. Note that sizeof(nh.raw) will likely return
4 or 8, the size of data pointer, not the size of the byte array it points to.

# I want my function to take ip header as unsigned char and print its
# strlen as 20 and want to process on it further.

You can't get there from here.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Death is the worry of the living. The dead, like myself,
only worry about decay and necrophiliacs.
Nov 14 '05 #3
li*************@gmail.com writes:
Hello,
In linux kernel there is a struct skbuff that used to store packets. It
has many fields defined in it. thers a union
union
{
struct iphdr *iph;
struct ipv6hdr *ipv6h;
struct arphdr *arph;
struct ipxhdr *ipxh;
unsigned char *raw;
} nh;

I want to ask once IP header is added to skbuff structure all pointers
in union carry same information. We know IP header is 20 bytes long.
Then i try to send raw variable to my function in kernel module.
processip(sb->nh.raw) where sb is of typr struct skbuff
Then why strlen on (sb->nh.raw) doesnot give 20 bytes as result instead
its giving 1.
I want my function to take ip header as unsigned char and print its
strlen as 20 and want to process on it further.


You got three responses to this query (that I saw) the first time you
asked it. Why have you asked again?
--
Joseph J. Pfeiffer, Jr., Ph.D. Phone -- (505) 646-1605
Department of Computer Science FAX -- (505) 646-1002
New Mexico State University http://www.cs.nmsu.edu/~pfeiffer
Nov 14 '05 #4

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

Similar topics

0
by: s_gregory | last post by:
The mdb is considerable size 70 +- mb. A complex union query was working well, but when an additional union select... was added into the query, selecting identical fields from a different source,...
13
by: Razmig K | last post by:
Dear mates, This is an another survey for the common (and uncommon) nontrivial uses of the aforementioned C construct. It's posted by the same average C programmer who's made a similar survey...
15
by: Ken Allen | last post by:
I have some code from C/C++ that I am attempting to port to C#. I have come across an interesting problem that is quite common in complex C/C++ code: the us of UNION in structure definitions to...
3
by: imtmub | last post by:
Hi All, I am facing some problem in the field data(Description field in Item table). In that table one field(Description field)data legth is 255 and type: nvarchar. In some operation this field data...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.