tutil.c - libeech - bittorrent library
(HTM) git clone git://z3bra.org/libeech.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
tutil.c (638B)
---
1 /* See LICENSE file for copyright and license details. */
2 #include <netdb.h>
3 #include <string.h>
4
5 char *
6 tohex(char *in, char *out, size_t len)
7 {
8 size_t i, j;
9 char hex[] = "0123456789abcdef";
10
11 memset(out, 0, len*2 + 1);
12 for (i=0, j=0; i<len; i++, j++) {
13 out[j] = hex[(unsigned char)in[i] >> 4];
14 out[++j] = hex[(unsigned char)in[i] & 15];
15 }
16
17 return out;
18 }
19
20 struct in_addr *
21 getinetaddr(char *hostname)
22 {
23 struct hostent *he;
24
25 if (!(he = gethostbyname(hostname))) {
26 herror(hostname);
27 return NULL;
28 }
29
30 return ((struct in_addr **)he->h_addr_list)[0];
31 }
32