/* * 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. */ #include #include "util.h" inline int isprint(unsigned char e) { if ((e < 0x30) || (e > 0x80)) return 0; return 1; } // hex_dumb display network packets in a good way void hex_dump(unsigned n, const unsigned char *buf) { int on_this_line = 0; while (n-- > 0) { kprintf("%02X ", *buf++); on_this_line += 1; if (on_this_line == 16 || n == 0) { int i; kputs(" "); for (i = on_this_line; i < 16; i++) kputs(" "); for (i = on_this_line; i > 0; i--) kputchar(isprint(buf[-i]) ? buf[-i] : '.'); kputs("\n"); on_this_line = 0; } } }