linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* strcut casts unsigned long
@ 2010-08-13  2:17 hong zhang
  2010-08-13  6:44 ` ratheesh k
  0 siblings, 1 reply; 5+ messages in thread
From: hong zhang @ 2010-08-13  2:17 UTC (permalink / raw)
  To: linux-c-programming

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


      

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: strcut casts unsigned long
  2010-08-13  2:17 strcut casts unsigned long hong zhang
@ 2010-08-13  6:44 ` ratheesh k
  2010-08-13 13:23   ` Javier Martinez Canillas
  2010-08-13 21:25   ` hong zhang
  0 siblings, 2 replies; 5+ messages in thread
From: ratheesh k @ 2010-08-13  6:44 UTC (permalink / raw)
  To: hong zhang; +Cc: linux-c-programming

On Fri, Aug 13, 2010 at 7:47 AM, hong zhang <henryzhang62@yahoo.com> wrote:
> 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

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

-Ratheesh











\\> --
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> 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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: strcut casts unsigned long
  2010-08-13  6:44 ` ratheesh k
@ 2010-08-13 13:23   ` Javier Martinez Canillas
  2010-08-13 21:25   ` hong zhang
  1 sibling, 0 replies; 5+ messages in thread
From: Javier Martinez Canillas @ 2010-08-13 13:23 UTC (permalink / raw)
  To: linux-c-programming

>>
>> 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;
>> }

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

>>
>> 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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: strcut casts unsigned long
  2010-08-13  6:44 ` ratheesh k
  2010-08-13 13:23   ` Javier Martinez Canillas
@ 2010-08-13 21:25   ` hong zhang
  2010-08-13 21:49     ` Javier Martinez Canillas
  1 sibling, 1 reply; 5+ messages in thread
From: hong zhang @ 2010-08-13 21:25 UTC (permalink / raw)
  To: ratheesh k; +Cc: linux-c-programming

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

--- On Fri, 8/13/10, ratheesh k <ratheesh.ksz@gmail.com> wrote:

> From: ratheesh k <ratheesh.ksz@gmail.com>
> Subject: Re: strcut casts unsigned long
> To: "hong zhang" <henryzhang62@yahoo.com>
> Cc: linux-c-programming@vger.kernel.org
> Date: Friday, August 13, 2010, 1:44 AM
> On Fri, Aug 13, 2010 at 7:47 AM, hong
> zhang <henryzhang62@yahoo.com>
> wrote:
> > 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
> 
> skb->_skb_dst can be a pointer to both destination cache
> or  routing
> table . We could type cast to any of those .
> 
> -Ratheesh
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> \\> --
> > To unsubscribe from this list: send the line
> "unsubscribe linux-c-programming" in
> > the body of a message to majordomo@vger.kernel.org
> > 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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: strcut casts unsigned long
  2010-08-13 21:25   ` hong zhang
@ 2010-08-13 21:49     ` Javier Martinez Canillas
  0 siblings, 0 replies; 5+ messages in thread
From: Javier Martinez Canillas @ 2010-08-13 21:49 UTC (permalink / raw)
  To: linux-c-programming

>
> 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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-08-13 21:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-13  2:17 strcut casts unsigned long hong zhang
2010-08-13  6:44 ` ratheesh k
2010-08-13 13:23   ` Javier Martinez Canillas
2010-08-13 21:25   ` hong zhang
2010-08-13 21:49     ` Javier Martinez Canillas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).