I am studying the use of raw sockets and their operation in C language, but I was left with a doubt:
When I send the echo, I need to give value to the checksum of my icmp header that will send the same, I need to create this function so that my algorithm works correctly "SummationSum", does anyone have an idea?
I submit below the icmp header code below:
icmp.h
#ifndef __ICMP_H__
#define __ICMP_H__
struct icmphdr {
uint8_t type;
uint8_t code;
uint16_t checksum;
uint16_t id;
uint16_t seqNum;
uint32_t data[ ];
} __attribute__((__packed__));
#endif
Completing icmp
icmphdr = (struct icmphdr *)buffer; //zera o icmphdr a partir do buffer
icmphdr->type = ECHO_REQ; //seta o tipo de pacote
icmphdr->id = htons(getpid() & 0xffff); //seta o id do pacote
icmphdr->seqNum = htons(sequencia++); //seta o numero de sequencia requisitado
setsockopt(descritorArquivoSocket, IPPROTO_IP, IP_TTL, &ttl, tamanhoEndereco);
icmphdr->checksum = somaParaVerificacao(buffer, tamanhoEndereco);