C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 1st, 2002, 01:28 AM
OB_redemption's Avatar
OB_redemption OB_redemption is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 32 OB_redemption User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
implementing high-level checksum

what i'm trying to do is to implement a (very) high-level checksum for my TCP client app written in C...

here's the data format for the packets i'm sending out from the client:
packet1-1033452719-878475\

what i want to do is to do a sum of the ASCII values of each indivual character (using ord())...

so it would go something like this:
sum = ord('p') + ord('a') + ord('c') + ... + ord(5)

then after getting the checksum, i want to add it at the end of the packet too, like so:
packet1-1033452719-878475-checksum\

how would i go about doing this? most importantly is how i can iterate over each character of the character array "packet1-1033452719-878475\" and perform the summation

thanks!

Reply With Quote
  #2  
Old October 1st, 2002, 01:39 AM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,387 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 1 Day 21 h 39 m 3 sec
Reputation Power: 4080
How about some code like this:
Code:
unsigned char compute_checksum(unsigned char *buf) {
   unsigned char *ch, result = 0;

   /* buf is assumed to be null terminated */
   for (ch = buf; *ch; ch++)
      result += (*ch);

   return result;
}
....
unsigned char checksum;
....
....
checksum = compute_checksum(buffer);
/* add checksum to end of buffer */
buffer[len] = checksum;
buffer[len+1] = '\0'; /* buffer assumed to be at least len+1 chars */

Please note that I typed this code off the top of my head, so it may have a few syntax errors. This isn't even a very good checksum algorithm, it just adds the ascii value of the chars up. You'd probably want to do a standard 16 or 32 bit CRC algorithm to ensure more reliability. You can probably google for those Hope this helps!

Reply With Quote
  #3  
Old October 1st, 2002, 01:48 AM
OB_redemption's Avatar
OB_redemption OB_redemption is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 32 OB_redemption User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
that was fast... thanks man!

it looks good and now i'm gonna see if it's worthwhile to implement a checksum... i just realised that if i do the checksum computation, it may reduce my packet sending rate which i'm trying to get to be as accurate as possible

thanks again!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > implementing high-level checksum

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap