#include "inet.h" #include "icmp.h" #include "kmalloc.h" #include "udp.h" #include "ntp.h" uint16_t ntohs(uint16_t val) { return val<<8|val>>8; } uint16_t htons(uint16_t val) { return val<<8|val>>8; } uint16_t checksum(void *addr, int count) { /* Compute Internet Checksum for "count" bytes * beginning at location "addr". * Taken from https://tools.ietf.org/html/rfc1071 */ register uint32_t sum = 0; uint16_t * ptr = addr; while( count > 1 ) { /* This is the inner loop */ //sum += ntohs(* ptr++); sum += *ptr++; count -= 2; } /* Add left-over byte, if any */ if( count > 0 ) sum += * (uint8_t *) ptr; /* Fold 32-bit sum to 16 bits */ while (sum>>16) sum = (sum & 0xffff) + (sum >> 16); return ~sum; } bool net_packet(struct netdev *dev) { uint32_t packet=kballoc(1)+4096; // we start one byte after the end; // uint32_t addr=(144)+(76<<8)+(106<<16)+(46<<24); uint32_t google_time=216+(239<<8)+(35<<16)+(0<<24); // this should of course be filled dynamically! //uint32_t pos=icmp_ping(dev,addr,packet,packet); // create ping packet and get new position; //uint32_t pos=udp_generic(dev, addr, 666, 123, packet,packet); uint32_t pos=ntp_generic(dev, google_time, 6666, 123, packet,packet); // dev->transmit(pos,(packet-pos)); kbfree(packet-4096); // TODO: take care it is not overwritten before transmitted! return true; }