aboutsummaryrefslogtreecommitdiff
path: root/src/dns
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-07 00:33:55 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-07 00:33:55 +0000
commit00cad61e45eb0b5ace71795d370b194317c99eee (patch)
treeec0fe47118ee7d81c53aa36536c4e78b8f6ee23e /src/dns
parent222e534eed64a24d843e0ee676579ea9b6264bbc (diff)
downloadgnunet-00cad61e45eb0b5ace71795d370b194317c99eee.tar.gz
gnunet-00cad61e45eb0b5ace71795d370b194317c99eee.zip
draft hex2bin, bin2hex
Diffstat (limited to 'src/dns')
-rw-r--r--src/dns/dnsparser.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/dns/dnsparser.c b/src/dns/dnsparser.c
index 97f47333b..2be34fc15 100644
--- a/src/dns/dnsparser.c
+++ b/src/dns/dnsparser.c
@@ -1241,8 +1241,17 @@ char *
1241GNUNET_DNSPARSER_bin_to_hex (const void *data, 1241GNUNET_DNSPARSER_bin_to_hex (const void *data,
1242 size_t data_size) 1242 size_t data_size)
1243{ 1243{
1244 GNUNET_break (0); // FIXME: not implemented 1244 char *ret;
1245 return NULL; 1245 size_t off;
1246 const uint8_t *idata;
1247
1248 idata = data;
1249 ret = GNUNET_malloc (data_size * 2 + 1);
1250 for (off = 0; off < data_size; off++)
1251 sprintf (&ret[off * 2],
1252 "%x",
1253 idata[off]);
1254 return ret;
1246} 1255}
1247 1256
1248 1257
@@ -1258,10 +1267,25 @@ size_t
1258GNUNET_DNSPARSER_hex_to_bin (const char *hex, 1267GNUNET_DNSPARSER_hex_to_bin (const char *hex,
1259 void *data) 1268 void *data)
1260{ 1269{
1261 GNUNET_break (0); // FIXME: not implemented 1270 size_t data_size;
1262 return 0; 1271 size_t off;
1272 uint8_t *idata;
1273 unsigned int h;
1274 char in[3];
1275
1276 data_size = strlen (hex) / 2;
1277 idata = data;
1278 in[2] = '\0';
1279 for (off = 0; off < data_size; off++)
1280 {
1281 in[0] = tolower ((int) hex[off * 2]);
1282 in[1] = tolower ((int) hex[off * 2 + 1]);
1283 if (1 != sscanf (in, "%x", &h))
1284 return off;
1285 idata[off] = (uint8_t) h;
1286 }
1287 return off;
1263} 1288}
1264 1289
1265 1290
1266
1267/* end of dnsparser.c */ 1291/* end of dnsparser.c */