Hi,
--- Quote Start ---
If from->sin_addr is a long (or pointer) type, it can assume it is aligned correctly, Thus the compiled code might be correct.
--- Quote End ---
Yes, you are right. And I think this source will not consider the machines that can not do unaligned-access.
--- Quote Start ---
If it is not, I would give memcpy the correct alignment. e.g.: memcpy ((char*)&from -> sin_addr, (char*)&ip -> ip_src, 4);
--- Quote End ---
Maybe, it's OK. And sorry, I made a mistake for the copy direction.
{ int i;
//unsigned char *pd = &ip -> ip_src, *ps = &from -> sin_addr;
unsigned char *ps = &ip -> ip_src, *pd = &from -> sin_addr;
for (i = 0; i < 4; i++)
*pd++ = *ps++;
}
Kazu