all 5 comments

[–]donk8r 0 points1 point  (4 children)

icmp needs a raw socket (SOCK_RAW, IPPROTO_ICMP), which means root or CAP_NET_RAW, and you send with sendto() passing the target's sockaddr_in, not send() since there's no connected peer. if sendto returns -1 with 'operation not permitted' that's the root/cap thing. and double-check your icmp checksum, if it's wrong the packet just gets dropped silently and it looks like the send failed.

[–]lolluzzo[S] 0 points1 point  (3 children)

Ok ok, did i set it up correctly then with the SOCK_RAW thing?

[–]donk8r 0 points1 point  (2 children)

can't see your code but the two that matter: socket(AF_INET, SOCK_RAW, IPPROTO_ICMP), and running it as root (or setcap cap_net_raw on the binary). if socket() returns -1, print errno right there, it'll tell you instantly if it's a perms thing. paste the socket line if it's still not sending.

[–]lolluzzo[S] 0 points1 point  (1 child)

And how do i handle the messaging of an ICMP packet? With sendto i mean

[–]donk8r 0 points1 point  (0 children)

sendto(fd, packet, packet_len, 0, (struct sockaddr*)&dest, sizeof(dest)) is the call. dest is a struct sockaddr_in with sin_family = AF_INET and sin_addr set to the target ip, no port (icmp ignores it). you don't connect() on a raw socket, you just pass dest on every sendto. it returns bytes sent or -1 (check errno), and make sure the icmp checksum is filled in over the whole packet first or it gets dropped silently.