From ae33cc6557790a502a01b380b0926944ca2f3cfa Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 26 Sep 2018 10:22:37 +0200 Subject: ntp and udp --- net/icmp.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'net/icmp.c') diff --git a/net/icmp.c b/net/icmp.c index 6f5f14f..20ac203 100644 --- a/net/icmp.c +++ b/net/icmp.c @@ -2,9 +2,42 @@ #include "icmp.h" #include "ipv4.h" #include "log.h" +#include "kmalloc.h" #include "lib/string/string.h" +uint32_t icmp_generic(struct netdev *dev, uint32_t ip, uint8_t type, uint8_t* pos,uint8_t *end) +{ + pos-=4; //we need 32 bytes + struct icmp_v4 *icmp=pos; + + icmp->type=type; + icmp->code=0; + icmp->csum=0; + icmp->csum=checksum(icmp,end-pos); + + return ipv4_generic(dev,ip,IPV4_P_ICMP,pos,end); +} + +uint32_t icmp_ping(struct netdev *dev, uint32_t ip, uint16_t* pos,uint32_t *end) +{ + // payload + for(int i=0;i<64;i++) + { + pos--; + *pos=0xbeef; + } + + // id and sequence number + pos-=2; // we need 32 bytes + struct icmp_v4_echo *ping=pos; + ping->id=htons(0xabcd); // some random number + ping->seq=htons(0); // we just send one single ping with id 1 for now + + return icmp_generic(dev,ip,ICMP_ECHO_REQUEST,pos,end); +} + + bool icmp_reply(struct netdev *dev,struct eth_hdr *hdr) { unsigned char tmp[6]; -- cgit v1.2.3