metalsvm/drivers/net/util.c

55 lines
1.3 KiB
C
Raw Normal View History

2011-07-04 13:02:19 -07:00
/*
* Copyright 2011 Carl-Benedikt Krueger, Chair for Operating Systems,
* RWTH Aachen University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is part of MetalSVM.
*/
2011-06-04 09:27:30 +02:00
#include "util.h"
2011-06-27 12:52:23 +02:00
__inline int isprint(char e)
{
if (e < 0x30 || e > 0x80)
2011-06-27 12:52:36 +02:00
return 0;
2011-06-27 12:52:23 +02:00
}
2011-06-04 09:27:30 +02:00
// hex_dumb display network packets in a good way
void hex_dump(unsigned n, const unsigned char* buf)
{
2011-07-04 13:02:19 -07:00
int on_this_line = 0;
2011-06-04 09:27:30 +02:00
while (n-- > 0)
{
2011-06-27 12:47:25 +02:00
kprintf("%02X ", *buf++);
2011-06-04 09:27:30 +02:00
on_this_line += 1;
if (on_this_line == 16 || n == 0)
{
int i;
2011-06-27 12:47:25 +02:00
kputs(" ");
2011-06-04 09:27:30 +02:00
for (i = on_this_line; i < 16; i++)
2011-06-27 12:47:25 +02:00
kputs(" ");
2011-06-04 09:27:30 +02:00
for (i = on_this_line; i > 0; i--)
2011-06-27 12:53:26 +02:00
kputchar(isprint(buf[-i]) ? buf[-i] : '.');
2011-06-04 09:27:30 +02:00
2011-06-27 12:47:25 +02:00
kputs("\n");
2011-06-04 09:27:30 +02:00
on_this_line = 0;
}
}
2011-06-27 12:47:25 +02:00
}