I’m sending a ICMP packet through a socket in iOS:
struct sockaddr hostAddress;
self->hostAddress.sa_family = AF_INET;
inet_pton(AF_INET, "173.194.67.93", &self->hostAddress.sa_data);
Then, I open the socket and I send the packet:
bytesSent = sendto(
CFSocketGetNative(self->_socket),
[packet bytes],
[packet length],
0,
&self->hostAddress,
sizeof(self->hostAddress)
);
When I see the packet in WireShark, it’s being sent to “67.93.0.0”, instead to “173.194.67.93”.
Where could be the problem?
should take a
struct in_addras the 3rd argument (see docs).You’re giving it
sa_data, fromwhich is really treated as:
So, the first 16 bits are going in the port, the second 16 bits of the IPV4 address are actually making it into
sin_addr, and the rest appears to be zero-initialized.You should be doing this (I’ll put loads of casts in for clarity)