/*
This file is part of GNUnet
- (C) 2010-2013 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2010-2014 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
return NULL;
}
memcpy (&dcert, &udp_payload[*off], sizeof (struct GNUNET_TUN_DnsCertRecord));
- (*off) += sizeof (sizeof (struct GNUNET_TUN_DnsCertRecord));
+ (*off) += sizeof (struct GNUNET_TUN_DnsCertRecord);
cert = GNUNET_new (struct GNUNET_DNSPARSER_CertRecord);
cert->cert_type = ntohs (dcert.cert_type);
cert->cert_tag = ntohs (dcert.cert_tag);
return GNUNET_OK;
}
+
+/**
+ * Convert a block of binary data to HEX.
+ *
+ * @param data binary data to convert
+ * @param data_size number of bytes in @a data
+ * @return HEX string (lower case)
+ */
+char *
+GNUNET_DNSPARSER_bin_to_hex (const void *data,
+ size_t data_size)
+{
+ char *ret;
+ size_t off;
+ const uint8_t *idata;
+
+ idata = data;
+ ret = GNUNET_malloc (data_size * 2 + 1);
+ for (off = 0; off < data_size; off++)
+ sprintf (&ret[off * 2],
+ "%02x",
+ idata[off]);
+ return ret;
+}
+
+
+/**
+ * Convert a HEX string to block of binary data.
+ *
+ * @param hex HEX string to convert (may contain mixed case)
+ * @param data where to write result, must be
+ * at least `strlen(hex)/2` bytes long
+ * @return number of bytes written to data
+ */
+size_t
+GNUNET_DNSPARSER_hex_to_bin (const char *hex,
+ void *data)
+{
+ size_t data_size;
+ size_t off;
+ uint8_t *idata;
+ unsigned int h;
+ char in[3];
+
+ data_size = strlen (hex) / 2;
+ idata = data;
+ in[2] = '\0';
+ for (off = 0; off < data_size; off++)
+ {
+ in[0] = tolower ((int) hex[off * 2]);
+ in[1] = tolower ((int) hex[off * 2 + 1]);
+ if (1 != sscanf (in, "%x", &h))
+ return off;
+ idata[off] = (uint8_t) h;
+ }
+ return off;
+}
+
+
/* end of dnsparser.c */