C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
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:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #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: 7
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 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,432 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 22 h 29 m 51 sec
Reputation Power: 784
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: 7
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


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway