0

I am playing ebpf code and got a sample like so:

int tc_ingress(struct __sk_buff *skb)
{
    void *data = (void *)(long)skb->data;
    struct ethhdr *eth = data, eth_copy; # what is this line doing? 
}

AS I am new to C and kernel, got stuck on many smaller things. Can some tell me what is this line mean?

struct ethhdr *eth = data, eth_copy;
pchaigno
  • 9,623
  • 2
  • 24
  • 47
Omar Faroque Anik
  • 2,403
  • 27
  • 38
  • 2
    How "new" are you to C exactly? That is just a cast from `void *` to a variable of type `struct ethhdr *`. Are you sure you don't want to read [a good C book](https://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list) first before diving into complex kernel code? – Marco Bonelli Feb 08 '22 at 04:34

1 Answers1

1
struct ethhdr *eth = data, eth_copy;

Is nothing special, it is a more compact version of

struct ethhdr *eth = data; 
struct ethhdr *eth_copy;

So we declare two variables of the same type, but we initialize just the first one.

Dylan Reimerink
  • 3,435
  • 2
  • 13
  • 17