diff options
Diffstat (limited to 'net/icmp.c')
| -rw-r--r-- | net/icmp.c | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -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]; |
