Skip to contentSkip to conversation

strcut casts unsigned long

DISCUSSION hong zhang 3 participants 5 messages Aug 13, 2010

lore
Share & tools
lore

hong zhang

author
#0 lore raw

List,

I have C question on skbuff.h.
skb->_skb_dst is defined as unsigned long and dst_entry is struct.

Why strct dst_entry casts unsigned long skb->_skb_dst?

See below

static inline struct dst_entry *skb_dst(const struct sk_buff *skb)

{
	return (struct dst_entry *)skb->_skb_dst;
}

Appreciate any answer!

--henry

#1 lore raw
Quoted 9 lines · hong zhang

List,

I have C question on skbuff.h.
skb->_skb_dst is defined as unsigned long and dst_entry is struct.

Why strct dst_entry casts unsigned long skb->_skb_dst?

See below

Quoted 8 lines

static inline struct dst_entry *skb_dst(const struct sk_buff *skb) {
       return (struct dst_entry *)skb->_skb_dst;
}

Appreciate any answer!

--henry

skb->_skb_dst can be a pointer to both destination cache or routing table . We could type cast to any of those .

-Ratheesh

\\> --

Quoted 4 lines

To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 4 lines
Quoted 4 lines

I have C question on skbuff.h.
skb->_skb_dst is defined as unsigned long and dst_entry is struct.

Quoted 8 lines
Quoted 8 lines

Why strct dst_entry casts unsigned long skb->_skb_dst?

See below

static inline struct dst_entry *skb_dst(const struct sk_buff *skb) {
       return (struct dst_entry *)skb->_skb_dst;
}

In the kernel, logical addresses are stored in variables of type unsigned long or void *. Thats why _skb_dst is of type unsigned long.

Quoted 11 lines
Quoted 4 lines

Appreciate any answer!

--henry

skb->_skb_dst can be a pointer to both destination cache or  routing table . We could type cast to any of those .

-Ratheesh

As Ratheesh said _skb_dst could be a pointer to two diferent data structures, that is why _skb_dst is not defined as a struct type.

Best regards,

-----------------------------------------
Javier Martínez Canillas
+595 981 88 66 58
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#3 lore raw
In reply to ratheesh k

Ratheesh,

Thanks for reply.

But does skb->_skb_dst allocate memory any where? It is unsigned long. This is hard part for me to understand. Any explain why unsigned long _skb_dst can be that?

---henry

Quoted 46 lines · ratheesh k

From: ratheesh k <[email protected]>
Subject: Re: strcut casts unsigned long
To: "hong zhang" <[email protected]>
Cc: [email protected]
Date: Friday, August 13, 2010, 1:44 AM

Quoted 4 lines · hong zhang

List,

I have C question on skbuff.h.
skb->_skb_dst is defined as unsigned long and

dst_entry is struct.

Quoted 2 lines

Why strct dst_entry casts unsigned long

skb->_skb_dst?

Quoted 4 lines

See below

static inline struct dst_entry *skb_dst(const struct

sk_buff *skb)

Quoted 2 lines

{
       return (struct dst_entry

*)skb->_skb_dst;

Quoted 5 lines

}

Appreciate any answer!

--henry

skb->_skb_dst can be a pointer to both destination cache or  routing
table . We could type cast to any of those .

-Ratheesh

Quoted 7 lines

\\> --

Quoted 1 line

To unsubscribe from this list: send the line

"unsubscribe linux-c-programming" in

Quoted 3 lines

the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 4 lines

But does skb->_skb_dst allocate memory any where? It is unsigned long. This is hard part for me to understand. Any explain why unsigned long _skb_dst can be that?

skb->_skb_dst is a pointer. A pointer is nothing else that a variable that stores a memory value (i.e: 0x0012ff5C). This value represent a memory address. Usually pointers are defined as * type, so the compiler can make type checking when analizing language expressions. But you could represent as a generic void * pointer. In the kernel, memoryaddresses are usually represented as variables of types unsigned long.

To make an analogy, char and int variables are integers, but you usually use char variables to represent ASCII codes. You can cast a char to an int, even when int is meant to represent integers. The same way you could store a memory address either in a void * or unsigned long variable.

I don't know why it is use unsigned long, but I guess that the GNU C standard says that unsigned long it is the same size that the cpu word size in all architechtures.

Best regards,

-----------------------------------------
Javier Martínez Canillas
+595 981 88 66 58
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html