Permalink
Browse files

Move main() to the bottom of the file to make it easier to find.

  • Loading branch information...
nelhage committed Aug 12, 2011
1 parent 76ec118 commit 9dd3c52825df25ae9772702ec4296b8a709e0faa
Showing with 32 additions and 35 deletions.
  1. +32 −35 virtunoid.c
View
@@ -416,7 +416,38 @@ void wait_rtc(void) {
outb(0xF0, 0x71);
}
-u_short in_cksum(const u_short *addr, register int len, u_short csum);
+/* Taken from iputils ping.c */
+u_short
+in_cksum(const u_short *addr, register int len, u_short csum)
+{
+ register int nleft = len;
+ const u_short *w = addr;
+ register u_short answer;
+ register int sum = csum;
+
+ /*
+ * Our algorithm is simple, using a 32 bit accumulator (sum),
+ * we add sequential 16 bit words to it, and at the end, fold
+ * back all the carry bits from the top 16 bits into the lower
+ * 16 bits.
+ */
+ while (nleft > 1) {
+ sum += *w++;
+ nleft -= 2;
+ }
+
+ /* mop up an odd byte, if necessary */
+ if (nleft == 1)
+ sum += htons(*(u_char *)w << 8);
+
+ /*
+ * add back carry outs from top 16 bits to low 16 bits
+ */
+ sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
+ sum += (sum >> 16); /* add carry */
+ answer = ~sum; /* truncate to 16 bits */
+ return (answer);
+}
int main(void) {
int fd;
@@ -506,37 +537,3 @@ int main(void) {
return 0;
}
-
-
-/* Taken from iputils ping.c */
-u_short
-in_cksum(const u_short *addr, register int len, u_short csum)
-{
- register int nleft = len;
- const u_short *w = addr;
- register u_short answer;
- register int sum = csum;
-
- /*
- * Our algorithm is simple, using a 32 bit accumulator (sum),
- * we add sequential 16 bit words to it, and at the end, fold
- * back all the carry bits from the top 16 bits into the lower
- * 16 bits.
- */
- while (nleft > 1) {
- sum += *w++;
- nleft -= 2;
- }
-
- /* mop up an odd byte, if necessary */
- if (nleft == 1)
- sum += htons(*(u_char *)w << 8);
-
- /*
- * add back carry outs from top 16 bits to low 16 bits
- */
- sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
- sum += (sum >> 16); /* add carry */
- answer = ~sum; /* truncate to 16 bits */
- return (answer);
-}

0 comments on commit 9dd3c52

Please sign in to comment.