xref: /illumos-gate/usr/src/cmd/smbsrv/test-msgbuf/test_main.c (revision da90d5b8133e037164268f8957ab823e806a7bfb)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
14  * Copyright 2019 Joyent, Inc.
15  */
16 
17 /*
18  * Test & debug program for smb_msgbuf.c and smb_mbuf_marshaling.c
19  */
20 
21 #include <sys/types.h>
22 #include <sys/debug.h>
23 
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <strings.h>
28 #include <unistd.h>
29 
30 #include "test_defs.h"
31 
32 
33 int
main(int argc,char * argv[])34 main(int argc, char *argv[])
35 {
36 
37 	test_conv();
38 	test_mbmarshal();
39 	test_msgbuf();
40 
41 	return (0);
42 }
43 
44 void
hexdump(const uchar_t * buf,int len)45 hexdump(const uchar_t *buf, int len)
46 {
47 	int idx;
48 	char ascii[24];
49 	char *pa = ascii;
50 
51 	memset(ascii, '\0', sizeof (ascii));
52 
53 	idx = 0;
54 	while (len--) {
55 		if ((idx & 15) == 0) {
56 			printf("%04X: ", idx);
57 			pa = ascii;
58 		}
59 		if (*buf > ' ' && *buf <= '~')
60 			*pa++ = *buf;
61 		else
62 			*pa++ = '.';
63 		printf("%02x ", *buf++);
64 
65 		idx++;
66 		if ((idx & 3) == 0) {
67 			*pa++ = ' ';
68 			(void) putchar(' ');
69 		}
70 		if ((idx & 15) == 0) {
71 			*pa = '\0';
72 			printf("%s\n", ascii);
73 		}
74 	}
75 
76 	if ((idx & 15) != 0) {
77 		*pa = '\0';
78 		/* column align the last ascii row */
79 		while ((idx & 15) != 0) {
80 			if ((idx & 3) == 0)
81 				(void) putchar(' ');
82 			printf("   ");
83 			idx++;
84 		}
85 		printf("%s\n", ascii);
86 	}
87 }
88