source:
asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/net/genfcstab.c
Last change on this file was 352, checked in by , 6 years ago | |
---|---|
|
|
File size: 710 bytes |
Line | |
---|---|
1 | /* |
2 | * Generate a FCS table for the HDLC FCS (RFC1171). |
3 | * |
4 | * Drew D. Perkins at Carnegie Mellon University. |
5 | * |
6 | * Code liberally borrowed from Mohsen Banan and D. Hugh Redelmeier. |
7 | */ |
8 | |
9 | #include <stdio.h> |
10 | |
11 | /* The HDLC polynomail: X**0 + X**5 + X**12 + X**16 (0x8408) */ |
12 | |
13 | #define Polynomial 0x8408 |
14 | |
15 | int |
16 | main (int argc, char *argv[]) |
17 | { |
18 | unsigned int count, octet; |
19 | int bit; |
20 | |
21 | printf("%s = {\n", argv[1]); |
22 | for (count = 0; count < 256; count ++) { |
23 | octet = count; |
24 | for (bit = 8; bit-- > 0; ) |
25 | octet = (octet & 0x01) ? ((octet >> 1) ^ Polynomial) : (octet >> 1); |
26 | printf("%c0x%04x,", count % 8 ? ' ' : '\t', octet & 0xffff); |
27 | if (count % 8 == 7) |
28 | putchar('\n'); |
29 | } |
30 | fputs("\t};\n", stdout); |
31 | return 0; |
32 | } |
Note:
See TracBrowser
for help on using the repository browser.