From d2ebcf6f6ddd513cfde2b164227af0f93c2c7194 Mon Sep 17 00:00:00 2001 From: wangyu- Date: Mon, 28 Aug 2017 17:41:31 -0500 Subject: [PATCH] added a unit test and a comment --- common.cpp | 3 ++- main.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/common.cpp b/common.cpp index 083f9ad..acd071d 100644 --- a/common.cpp +++ b/common.cpp @@ -302,7 +302,7 @@ void setnonblocking(int sock) { /* Generic checksum calculation function */ -unsigned short csum(const unsigned short *ptr,int nbytes) { +unsigned short csum(const unsigned short *ptr,int nbytes) {//works both for big and little endian register long sum; unsigned short oddbyte; register short answer; @@ -325,6 +325,7 @@ unsigned short csum(const unsigned short *ptr,int nbytes) { return(answer); } + int set_buf_size(int fd) { if(setsockopt(fd, SOL_SOCKET, SO_SNDBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0) diff --git a/main.cpp b/main.cpp index f1a2ee4..6f2ac0e 100755 --- a/main.cpp +++ b/main.cpp @@ -2628,6 +2628,17 @@ int unit_test() } printf("\n"); } + + char s1[]={1,2,3,4,5}; + + char s2[]={1}; + + short c1=csum((unsigned short*)s1,5); + short c2=csum((unsigned short*)s2,1); + //c2=0; + + printf("%x %x\n",(int)c1,(int)c2); + return 0; }