Annotation of libelwix/example/test_pack.c, revision 1.3.2.1
1.2 misho 1: #include <stdio.h>
2: #include <string.h>
3: #include <elwix.h>
4:
5:
6: int
7: main(int argc, char **argv)
8: {
9: rpack_t *rp;
10: register int i;
11: char n8 = '*';
12: short n16 = 0xdeba;
13: int n32 = 0xdeadbeef;
14: long long int n64 = 0x123456789abcdef0;
1.3.2.1 ! misho 15: char *str;
1.2 misho 16:
17: if (argc < 2)
18: return 1;
19:
20: rp = rpack_create(argv[1], strlen(argv[1]) + 1);
21: if (!rp) {
22: printf("#%d - %s\n", elwix_GetErrno(), elwix_GetError());
23: return 2;
24: } else
25: printf("create raw packet %p -> %s(%d)\n", rp, rp->r_buf, rp->r_len);
26:
1.3.2.1 ! misho 27: printf("test rpack_data::\n");
! 28: for (i = 0; i < RPACK_LEN(rp); i++) {
! 29: if (i == 4) {
! 30: str = rpack_data(rp, "F0ST4T4", 8);
! 31: str[7] = 0;
! 32: printf("\t%d) %s\n", i, str ? str : NULL);
! 33: i += 8;
! 34: } else {
! 35: str = rpack_data(rp, NULL, 1);
! 36: printf("\t%d) %c\n", i, str ? *str : 0xff);
! 37: }
! 38: e_free(str);
! 39: }
! 40: RPACK_REWIND(rp);
! 41: for (i = 0; i < RPACK_LEN(rp); i++) {
! 42: str = rpack_data(rp, NULL, 1);
! 43: printf("\t%d) %c\n", i, str ? *str : 0xff);
! 44: e_free(str);
! 45: }
! 46: RPACK_REWIND(rp);
! 47:
! 48:
1.2 misho 49: printf("test rpack_uint8::\n");
50: for (i = 0; i < RPACK_LEN(rp); i++)
51: if (i == 4)
52: printf("\t%d) %c\n", i, rpack_uint8(rp, (uint8_t*) &n8));
53: else
54: printf("\t%d) %c\n", i, rpack_uint8(rp, NULL));
55: RPACK_REWIND(rp);
56: for (i = 0; i < RPACK_LEN(rp); i++)
57: printf("\t%d) %c\n", i, rpack_uint8(rp, NULL));
58: RPACK_REWIND(rp);
59:
60: printf("test rpack_uint16::\n");
61: for (i = 0; i < RPACK_LEN(rp); i++)
62: if (i == 4)
1.3 misho 63: printf("\t%d) %x\n", i, rpack_uint16(rp, (uint16_t*) &n16, 0));
1.2 misho 64: else
1.3 misho 65: printf("\t%d) %x\n", i, rpack_uint16(rp, NULL, 0));
1.2 misho 66: RPACK_REWIND(rp);
67: for (i = 0; i < RPACK_LEN(rp); i++)
1.3 misho 68: printf("\t%d) %x\n", i, rpack_uint16(rp, NULL, 0));
1.2 misho 69: RPACK_REWIND(rp);
70:
71: printf("test rpack_uint24::\n");
72: for (i = 0; i < RPACK_LEN(rp); i++)
73: if (i == 4)
1.3 misho 74: printf("\t%d) %x\n", i, rpack_uint24(rp, (uint32_t*) &n32, 0));
1.2 misho 75: else
1.3 misho 76: printf("\t%d) %x\n", i, rpack_uint24(rp, NULL, 0));
1.2 misho 77: RPACK_REWIND(rp);
78: for (i = 0; i < RPACK_LEN(rp); i++)
1.3 misho 79: printf("\t%d) %x\n", i, rpack_uint24(rp, NULL, 0));
1.2 misho 80: RPACK_REWIND(rp);
81:
82: printf("test rpack_uint32::\n");
83: for (i = 0; i < RPACK_LEN(rp); i++)
84: if (i == 4)
1.3 misho 85: printf("\t%d) %x\n", i, rpack_uint32(rp, (uint32_t*) &n32, 0));
1.2 misho 86: else
1.3 misho 87: printf("\t%d) %x\n", i, rpack_uint32(rp, NULL, 0));
1.2 misho 88: RPACK_REWIND(rp);
89: for (i = 0; i < RPACK_LEN(rp); i++)
1.3 misho 90: printf("\t%d) %x\n", i, rpack_uint32(rp, NULL, 0));
1.2 misho 91: RPACK_REWIND(rp);
92:
93: printf("test rpack_uint64::\n");
94: for (i = 0; i < RPACK_LEN(rp); i++)
95: if (i == 4)
1.3 misho 96: printf("\t%d) %llx\n", i, rpack_uint64(rp, (uint64_t*) &n64, 0));
1.2 misho 97: else
1.3 misho 98: printf("\t%d) %llx\n", i, rpack_uint64(rp, NULL, 0));
1.2 misho 99: RPACK_REWIND(rp);
100: for (i = 0; i < RPACK_LEN(rp); i++)
1.3 misho 101: printf("\t%d) %llx\n", i, rpack_uint64(rp, NULL, 0));
1.2 misho 102: RPACK_REWIND(rp);
103:
104: rpack_destroy(&rp);
105: printf("destroy packet %p\n", rp);
106: return 0;
107: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>