1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2008-2011 New Dream Network
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #include "common/hex.h"
17 void hex2str(const char *s, int len, char *buf, int dest_len)
20 for (int i=0; i<len && pos<dest_len; i++) {
22 pos += snprintf(&buf[pos], dest_len-pos, " ");
24 pos += snprintf(&buf[pos], dest_len-pos, "\n");
25 pos += snprintf(&buf[pos], dest_len-pos, "%.2x ", (int)(unsigned char)s[i]);
29 std::string hexdump(std::string msg, const char *s, int len)
33 hex2str(s, len, buf, buf_len);