strcut casts unsigned long
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
Quoted 9 lines · hong zhang
List,
I have C question on
skbuff.h.skb->_skb_dstis defined as unsigned long anddst_entryis struct.Why strct
dst_entrycasts unsigned longskb->_skb_dst?See below
Quoted 8 lines
static inline struct
dst_entry*skb_dst(const structsk_buff*skb) {
return (structdst_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
Quoted 4 lines
Quoted 4 lines
I have C question on
skbuff.h.skb->_skb_dstis defined as unsigned long anddst_entryis struct.
Quoted 8 lines
Quoted 8 lines
Why strct
dst_entrycasts unsigned longskb->_skb_dst?See below
static inline struct
dst_entry*skb_dst(const structsk_buff*skb) {
return (structdst_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_dstcan 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
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 AMQuoted 4 lines · hong zhang
List,
I have C question on
skbuff.h.skb->_skb_dstis defined as unsigned long and
dst_entryis struct.Quoted 2 lines
Why strct
dst_entrycasts 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 (structdst_entry*)skb->_skb_dst;
Quoted 5 lines
}
Appreciate any answer!
--henry
skb->_skb_dstcan 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
Quoted 4 lines
But does
skb->_skb_dstallocate memory any where? It is unsigned long. This is hard part for me to understand. Any explain why unsigned long_skb_dstcan 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