By default packets sent include the TCP/UDP/ICMP header but not the IP header. Packets received include TCP/UDP/ICMP/IP header.
To include IP header in sent packets (after socket is bound)
int tmp = 1;
setsockopt(sock, 0, IP_HDRINCL, & tmp, sizeof(tmp));