#ifndef lint
static char rcsid[] =
    "@(#) $Header: /usr/staff/martinh/tcpview/RCS/hd.c,v 1.1 1993/04/22 20:23:07 martinh Exp $ (UW)";
#endif

#include <stdio.h>
#include <sys/types.h>

#define LS 16

char   *oname = 0;
static char     hex[] = "0123456789abcdef";
/* char    bhex[] = " 123456789abcdef"; */

void hd( buffer, data, len ) 
u_char *buffer, *data;
int len;
{
  u_char *in, *out; 
  char a[LS+1], tmp[10];
  int     i,j;
  u_int   c;
  int     pos = 0;
  
  in = data;
  out = buffer;
  while (len) {
    sprintf (tmp, "%04lx  ", pos++ * LS);
    for (j = 0; tmp[j]; ++j)
      *out++ = tmp[j];
    for (i = 0; i < LS && len ; ++i) {
      c = *in++;
      len--;
      *out++ = hex[c >> 4];
      *out++ = hex[c & 15];
      *out++ = ' ';
      a[i] = (c >= ' ' && c <= 126 ? c : '.');
    }
    a[i] = 0;
    for(j=i;j<LS;j++) {
      *out++ = ' ';
      *out++ = ' ';
      *out++ = ' ';
    }
    *out++ = ' ';
    *out++ = ' ';
    *out++ = '|';
    *out++ = ' ';
    *out++ = ' ';
    for (j = 0; a[j]; ++j)
      *out++ = a[j];
    *out++ = '\n';
  }
  *out++ = '\0';
}



syntax highlighted by Code2HTML, v. 0.9.1