I am creating three structures:
struct ethernet {
uint16_t dest_mac;
};
struct ip {
uint16_t src_ip;
uint16_t dest_ip;
};
struct udp {
uint16_t porten I
};
then I am creating the instances oh the structures and copying then in a char buffer.
memcpy(buffer , eth , sizeof(struct ethernet));
memcpy(buffer + sizeof(struct ethernet) , ipe , sizeof(struct ip));
memcpy((buffer + sizeof(struct ethernet) + sizeof(struct ip)) , udpe , sizeof(struct udp));
Now I define another structure:
struct pattern {
uint64_t pttn;
};
now I typecasting the memory pointed by char buffer defined above to struct pattern.
struct pattern *pat = NULL;
pat = (struct pattern *)buffer;
When I am doing this opertaion the value for pat->pttn is not coming as expected.
Example:
when I am passing values: dest_mac = 1 , src_ip = 2 , dest_ip = 3 , port = 4. The value of pat->pttn is coming out to be 131073 . According to me the value should come is : 281483566841860