I am passing char *
pointer from main to a function abc
which is uninitialized pointer. And I am composing a network packet so like what allocated in the function I want it to be the representation of a packet. So This is my passing of uninitialized pointer in function call inside main
char *pay;
abc(&pay);
in the function I have as signature of a function like following
void abc(char **c)
this is the full function
void abc(char **c)
{
*c=(char *) malloc(sizeof(struct ethhdr)+sizeof(struct iphdr)+sizeof(struct tcphdr)+1000/*1000=payload*/);
struct ethhdr *eth=(struct ethhdr *)&*c;
struct iphdr *ip=(struct iphdr *)(&*eth+sizeof(struct ethhdr));
struct tcphdr *tcp=(struct tcphdr *)(&*ip+sizeof(struct iphdr));
//populate eth
//...
//populate ip
//...
//populate tcp
tcp->source=80;
printf("%d\n",tcp->source);
int *x=(int *)*c;
//x=10;
}
I like to know how can I cast second line in abc
function
I am doing like this
struct ethhdr *eth=(struct ethhdr *)&*c;
second line inside
abc
function.
But at line containing this instruction tcp->source=80;
its causing segFault.
So my question is how can I cast the c
double pointer in function and to assign it tostruct ethhdr *
,struct iphd *
and struct tcphdr *
pointers
And how to assign the values to members of struct ethhdr
, struct iphdr
and struct tcphdr
I tried like
tcp->source=80;
But causing segFault