diff options
| author | Miguel <m.i@gmx.at> | 2018-09-26 10:22:37 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-09-26 10:22:37 +0200 |
| commit | ae33cc6557790a502a01b380b0926944ca2f3cfa (patch) | |
| tree | e72632052d1c6f6830c40d10d26c04b73aac74c6 /net/icmp.c | |
| parent | daf374435560861681c3e4d14a2d44141aa11abc (diff) | |
ntp and udp
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]; |
