1
I’m studying the use of raw sockets and its functioning in the C language, but I was left with a doubt:
When I send echo, I need to give value to the checksum of my icmp header that will send the same, I need to create this function for my algorithm to work properly "summation", someone has an idea?
Send below the code of the icmp header 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 the 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);
I don’t know much about this area yet, but I think this may help you https://blogs.oracle.com/ksplice/entry/learning_by_doing_writing_your is in python but a notion of the steps. You can also look at the traceroute source code itself and see how it is implemented.
– Adir Kuhn
How do I look at traceroute source code?
– Nicolas Bontempo
http://web.cecs.pdx.edu/~jrb/tcpip/Misc.src/traceroute. c
– Adir Kuhn
apple http://www.opensource.apple.com/source/network_cmds/network_cmds-307.0.1/traceroute.tproj/traceroute.c
– Adir Kuhn