MCPcopy Create free account
hub / github.com/F-Stack/f-stack / DumpAscii

Function DumpAscii

tools/ngctl/main.c:679–711  ·  view source on GitHub ↗

* Dump data in hex and ASCII form */

Source from the content-addressed store, hash-verified

677 * Dump data in hex and ASCII form
678 */
679void
680DumpAscii(const u_char *buf, int len)
681{
682 char ch, sbuf[100];
683 int k, count;
684
685 for (count = 0; count < len; count += DUMP_BYTES_PER_LINE) {
686 snprintf(sbuf, sizeof(sbuf), "%04x: ", count);
687 for (k = 0; k < DUMP_BYTES_PER_LINE; k++) {
688 if (count + k < len) {
689 snprintf(sbuf + strlen(sbuf),
690 sizeof(sbuf) - strlen(sbuf),
691 "%02x ", buf[count + k]);
692 } else {
693 snprintf(sbuf + strlen(sbuf),
694 sizeof(sbuf) - strlen(sbuf), " ");
695 }
696 }
697 snprintf(sbuf + strlen(sbuf), sizeof(sbuf) - strlen(sbuf), " ");
698 for (k = 0; k < DUMP_BYTES_PER_LINE; k++) {
699 if (count + k < len) {
700 ch = isprint(buf[count + k]) ?
701 buf[count + k] : '.';
702 snprintf(sbuf + strlen(sbuf),
703 sizeof(sbuf) - strlen(sbuf), "%c", ch);
704 } else {
705 snprintf(sbuf + strlen(sbuf),
706 sizeof(sbuf) - strlen(sbuf), " ");
707 }
708 }
709 printf("%s\n", sbuf);
710 }
711}
712
713/*
714 * Usage()

Callers 2

MsgReadFunction · 0.85
ReadSocketsFunction · 0.85

Calls 3

snprintfFunction · 0.85
isprintFunction · 0.85
printfFunction · 0.50

Tested by

no test coverage detected