0

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

Love Bisaria
  • 167
  • 13

1 Answers1

0

The value of a 64bit [unsigned] Integer, being composed from 4 neighboring 16bit integers is system architecture dependent, and depends on the "endianness" of the architecture.

Ron Pinkas
  • 357
  • 2
  • 10