* sizeof pointer vs sizeof struct
@ 2024-03-01 1:20 Logan B
2024-03-01 2:10 ` Jay Vosburgh
0 siblings, 1 reply; 3+ messages in thread
From: Logan B @ 2024-03-01 1:20 UTC (permalink / raw)
To: xdp-newbies
Hello,
I was recently working through the xdp tutorial and in the
packet01-parsing lesson the sizeof a pointer to the ethernet header
struct is used, not the sizeof the struct itself[0]. I peeked and the
solution for this section also still uses the sizeof a pointer and not
the struct so this isn't part of the tutorial and I was wondering what
is going on? I don't think the verifier is re-writing these addresses,
only those for the memory access into the packet data.
#include <stdio.h>
#include <linux/if_ether.h>
int main(void)
{
struct ethhdr normal = {0};
struct ethhdr *eth_hdr_ptr;
printf("Size of struct %lu\n",sizeof(normal)); // prints 14
printf("Size of struct pointer %lu\n",sizeof(eth_hdr_ptr)); //
prints 8
return 0;
}
[0]https://github.com/xdp-project/xdp-tutorial/blob/master/packet01-parsing/xdp_prog_kern.c#L34
--
Logan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: sizeof pointer vs sizeof struct
2024-03-01 1:20 sizeof pointer vs sizeof struct Logan B
@ 2024-03-01 2:10 ` Jay Vosburgh
2024-03-01 2:30 ` Logan B
0 siblings, 1 reply; 3+ messages in thread
From: Jay Vosburgh @ 2024-03-01 2:10 UTC (permalink / raw)
To: mr.bo.jangles3; +Cc: xdp-newbies
Logan B <mrbojangles3@gmail.com> wrote:
>Hello,
>I was recently working through the xdp tutorial and in the
>packet01-parsing lesson the sizeof a pointer to the ethernet header
>struct is used, not the sizeof the struct itself[0]. I peeked and the
>solution for this section also still uses the sizeof a pointer and not
>the struct so this isn't part of the tutorial and I was wondering what
>is going on? I don't think the verifier is re-writing these addresses,
>only those for the memory access into the packet data.
The referenced code at [0] is:
struct ethhdr *eth = nh->pos;
int hdrsize = sizeof(*eth);
"*eth" means "what eth points to," so this is indeed taking the
sizeof struct ethhdr.
I suspect you missed the "*" in your reading of the code; in
this context, "*" is the indirection operator, per K&R 2, (The C
Programming Language, 2nd Edition), Appendix A 7.4.3.
-J
>
>#include <stdio.h>
>#include <linux/if_ether.h>
>
>int main(void)
>
> {
>
> struct ethhdr normal = {0};
> struct ethhdr *eth_hdr_ptr;
>
> printf("Size of struct %lu\n",sizeof(normal)); // prints 14
> printf("Size of struct pointer %lu\n",sizeof(eth_hdr_ptr)); //
>prints 8
> return 0;
>}
>
>
>[0]https://github.com/xdp-project/xdp-tutorial/blob/master/packet01-parsing/xdp_prog_kern.c#L34
>--
>Logan
>
---
-Jay Vosburgh, jay.vosburgh@canonical.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: sizeof pointer vs sizeof struct
2024-03-01 2:10 ` Jay Vosburgh
@ 2024-03-01 2:30 ` Logan B
0 siblings, 0 replies; 3+ messages in thread
From: Logan B @ 2024-03-01 2:30 UTC (permalink / raw)
To: Jay Vosburgh; +Cc: xdp-newbies
On Thu, Feb 29, 2024 at 9:10 PM Jay Vosburgh <jay.vosburgh@canonical.com> wrote:
>
> Logan B <mrbojangles3@gmail.com> wrote:
>
> >Hello,
> >I was recently working through the xdp tutorial and in the
> >packet01-parsing lesson the sizeof a pointer to the ethernet header
> >struct is used, not the sizeof the struct itself[0]. I peeked and the
> >solution for this section also still uses the sizeof a pointer and not
> >the struct so this isn't part of the tutorial and I was wondering what
> >is going on? I don't think the verifier is re-writing these addresses,
> >only those for the memory access into the packet data.
>
> The referenced code at [0] is:
>
> struct ethhdr *eth = nh->pos;
> int hdrsize = sizeof(*eth);
>
> "*eth" means "what eth points to," so this is indeed taking the
> sizeof struct ethhdr.
>
> I suspect you missed the "*" in your reading of the code; in
> this context, "*" is the indirection operator, per K&R 2, (The C
> Programming Language, 2nd Edition), Appendix A 7.4.3.
>
> -J
>
I did miss that. Thank you
Logan
> >
> >#include <stdio.h>
> >#include <linux/if_ether.h>
> >
> >int main(void)
> >
> > {
> >
> > struct ethhdr normal = {0};
> > struct ethhdr *eth_hdr_ptr;
> >
> > printf("Size of struct %lu\n",sizeof(normal)); // prints 14
> > printf("Size of struct pointer %lu\n",sizeof(eth_hdr_ptr)); //
> >prints 8
> > return 0;
> >}
> >
> >
> >[0]https://github.com/xdp-project/xdp-tutorial/blob/master/packet01-parsing/xdp_prog_kern.c#L34
> >--
> >Logan
> >
>
> ---
> -Jay Vosburgh, jay.vosburgh@canonical.com
--
Logan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-01 2:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-01 1:20 sizeof pointer vs sizeof struct Logan B
2024-03-01 2:10 ` Jay Vosburgh
2024-03-01 2:30 ` Logan B
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.