libdht
utils.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 naturalpolice
3  * SPDX-License-Identifier: MIT
4  *
5  * Licensed under the MIT License (see LICENSE).
6  */
7 
13 #ifndef DHT_UTILS_H_
14 #define DHT_UTILS_H_
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 #ifdef _WIN32
21 typedef int socklen_t;
22 #include <winsock2.h>
23 #include <ws2ipdef.h>
24 #else
25 #include <sys/socket.h>
26 #include <arpa/inet.h>
27 #endif
28 
39 const char *hex(const unsigned char id[20]);
49 int from_hex(const char *s, unsigned char id[20]);
50 
63 const char *sockaddr_fmt(const struct sockaddr *sa, socklen_t addrlen);
64 
72 int sockaddr_cmp(const struct sockaddr *s1, const struct sockaddr *s2);
73 
87 const char *compactaddr_fmt(const unsigned char *ip, size_t len);
88 
89 #ifdef __cplusplus
90 }
91 #endif
92 
93 #endif /* DHT_UTILS_H_ */
const char * compactaddr_fmt(const unsigned char *ip, size_t len)
Format compact address information.
int from_hex(const char *s, unsigned char id[20])
Convert a hexadecimal representation string to a 160-bit value.
size_t len
length of the string
Definition: bencode.h:55
int sockaddr_cmp(const struct sockaddr *s1, const struct sockaddr *s2)
Compare two socket addresses.
const char * sockaddr_fmt(const struct sockaddr *sa, socklen_t addrlen)
Format socket address.
const char * hex(const unsigned char id[20])
Return the hexadecimal representation of a 160-bit value.
struct bvalue::@1::@3 s
String value.