summaryrefslogtreecommitdiff
path: root/net/ipv4.c
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-09-26 10:22:37 +0200
committerMiguel <m.i@gmx.at>2018-09-26 10:22:37 +0200
commitae33cc6557790a502a01b380b0926944ca2f3cfa (patch)
treee72632052d1c6f6830c40d10d26c04b73aac74c6 /net/ipv4.c
parentdaf374435560861681c3e4d14a2d44141aa11abc (diff)
ntp and udp
Diffstat (limited to 'net/ipv4.c')
-rw-r--r--net/ipv4.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/net/ipv4.c b/net/ipv4.c
index b7e6a53..b090a7b 100644
--- a/net/ipv4.c
+++ b/net/ipv4.c
@@ -11,6 +11,7 @@ bool ipv4_incoming(struct netdev *dev,struct eth_hdr *hdr)
ipv4->csum=0;
klog("expected checksum: 0x%04X",checksum(ipv4,ntohs(ipv4->len)));
klog("ipv4 header len=%d",ipv4->ihl);
+
if(ipv4->proto==IPV4_P_ICMP)
{
icmp_incoming(dev,hdr);
@@ -18,3 +19,31 @@ bool ipv4_incoming(struct netdev *dev,struct eth_hdr *hdr)
return true;
}
+
+uint32_t ipv4_generic(struct netdev *dev, uint32_t ip, uint8_t type, uint8_t* pos,uint8_t *end)
+{
+
+ pos-=20; // we need 20 bytes for the ipv4 header.
+ struct ipv4_hdr *ipv4=pos;
+ ipv4->ihl=5; // 20 bytes
+ ipv4->version=4; // ipv 4
+
+ ipv4->tos=0; // type of service?
+ ipv4->len=htons(end-pos); // total length of ip datagramm in bytes
+ ipv4->id=0; // index of datagram for fragmentation
+
+ //ipv4->flags=0x2; // various control flags 0x20 do not fragment
+ //ipv4->frag_offset=0; // fragment offset 0 - first
+ ipv4->flags_and_offset=0; // TODO! 0x2?
+
+ ipv4->ttl=64; // time to live - countdown decreased by each receiver
+ ipv4->proto=type; // payload protocol / 1-icmp, 16 - udp , 6 -tcp
+ ipv4->csum=0; // header checksum
+ ipv4->saddr=dev->ip; // source ip address
+ ipv4->daddr=ip; // destination ip address
+
+ //ipv4->csum=checksum(ipv4,ntohs(ipv4->len));
+ ipv4->csum=checksum(ipv4,20);
+
+ return eth_generic(dev,ip,ETH_P_IPV4,pos,end);
+}