summaryrefslogtreecommitdiff
path: root/udp.c
diff options
context:
space:
mode:
authorroot <root@phone01.(none)>2010-09-26 02:00:11 +0200
committerroot <root@phone01.(none)>2010-09-26 02:00:11 +0200
commitf7cfcdb6b1fcfaf149dce2195181f3d8707306b6 (patch)
tree5683251a01700de51c5581da0bee6d7427c44d67 /udp.c
parent10a51f687aab0673ff6be875b3b3e0dfe304e2b2 (diff)
downloadMAC-Telnet-f7cfcdb6b1fcfaf149dce2195181f3d8707306b6.tar.gz
MAC-Telnet-f7cfcdb6b1fcfaf149dce2195181f3d8707306b6.zip
Connection working, auth received, control packets parsed. TODO: Cleanup/filesplit and create login + terminal code.
Diffstat (limited to 'udp.c')
-rw-r--r--udp.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/udp.c b/udp.c
index b4bfb34..96fd906 100644
--- a/udp.c
+++ b/udp.c
@@ -10,6 +10,51 @@
#include <linux/if_arp.h>
#include <stdio.h>
+unsigned short udp_sum_calc(unsigned short len_udp, unsigned char src_addr[],unsigned char dest_addr[], unsigned char buff[]) {
+ unsigned short prot_udp=17;
+ unsigned short padd=0;
+ unsigned short word16;
+ unsigned long sum;
+ int i;
+
+ // Find out if the length of data is even or odd number. If odd,
+ // add a padding byte = 0 at the end of packet
+ if (len_udp % 2 == 1){
+ padd=1;
+ buff[len_udp]=0;
+ }
+
+ //initialize sum to zero
+ sum=0;
+
+ // make 16 bit words out of every two adjacent 8 bit words and
+ // calculate the sum of all 16 vit words
+ for (i=0;i<len_udp+padd;i=i+2){
+ word16 =((buff[i]<<8)&0xFF00)+(buff[i+1]&0xFF);
+ sum = sum + (unsigned long)word16;
+ }
+ // add the UDP pseudo header which contains the IP source and destinationn addresses
+ for (i=0;i<4;i=i+2){
+ word16 =((src_addr[i]<<8)&0xFF00)+(src_addr[i+1]&0xFF);
+ sum=sum+word16;
+ }
+ for (i=0;i<4;i=i+2){
+ word16 =((dest_addr[i]<<8)&0xFF00)+(dest_addr[i+1]&0xFF);
+ sum=sum+word16;
+ }
+ // the protocol number and the length of the UDP packet
+ sum = sum + prot_udp + len_udp;
+
+ // keep only the last 16 bits of the 32 bit calculated sum and add the carries
+ while (sum>>16)
+ sum = (sum & 0xFFFF)+(sum >> 16);
+
+ // Take the one's complement of sum
+ sum = ~sum;
+
+ return ((unsigned short) sum);
+}
+
//#define ETH_FRAME_LEN 1518
unsigned short in_cksum(unsigned short *addr, int len)
{
@@ -114,7 +159,9 @@ int sendCustomUDP(const int socket, const char *sourcemac, const char *destmac,
// UDP Header
udp->source = htons(20561);
udp->dest = htons(20561);
+ udp->check = 0;
udp->len = htons(sizeof(struct udphdr) + datalen);
+ //udp->check = udp_sum_calc(datalen+8, (unsigned char *)&(ip->saddr), (unsigned char *)&(ip->daddr), (unsigned char *)udp);
memcpy(resten, data, datalen);