Created
July 22, 2017 11:10
-
-
Save Xhendos/17b914e93a539d3c4d55b367bd3a693c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
*A header with all includes. | |
*/ | |
#include "program.h" | |
int main() | |
{ | |
struct sockaddr_in socketaddress_in; | |
struct icmphdr *icmp_header; | |
char response[2048]; | |
int length = 2048; | |
int socket_descriptor = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); | |
printf("[ICMP] socket descriptor is %i\n", socket_descriptor); | |
/* | |
* Filling socketaddress_in (sockaddr_in) structure with information. | |
*/ | |
socketaddress_in.sin_family = AF_INET; | |
socketaddress_in.sin_addr.s_addr = inet_addr("192.168.42.1"); | |
socketaddress_in.sin_port = 0; | |
/* | |
* Filling icmp_header (icmphdr) structure with information. | |
*/ | |
icmp_header = (struct icmphdr *)response; | |
icmp_header->type = ICMP_ECHO; | |
icmp_header->code = 0; | |
icmp_header->un.echo.id = getpid(); | |
icmp_header->checksum = 0; | |
int status_code = sendto(socket_descriptor, response, length, 0, (struct sockaddr *)&socketaddress_in, sizeof(struct sockaddr_in)); | |
printf("[ICMP] sendto() has send %i bytes succesfull.\n", status_code); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment