libdht
|
DHT utilities. More...
#include <sys/socket.h>
#include <arpa/inet.h>
Go to the source code of this file.
Functions | |
const char * | hex (const unsigned char id[20]) |
Return the hexadecimal representation of a 160-bit value. More... | |
int | from_hex (const char *s, unsigned char id[20]) |
Convert a hexadecimal representation string to a 160-bit value. More... | |
const char * | sockaddr_fmt (const struct sockaddr *sa, socklen_t addrlen) |
Format socket address. More... | |
int | sockaddr_cmp (const struct sockaddr *s1, const struct sockaddr *s2) |
Compare two socket addresses. More... | |
const char * | compactaddr_fmt (const unsigned char *ip, size_t len) |
Format compact address information. More... | |
DHT utilities.
const char* compactaddr_fmt | ( | const unsigned char * | ip, |
size_t | len | ||
) |
Format compact address information.
Returns the given compact address address information as a human-readable string. A compact address is a 4-byte IPv4 address in network byte order followed by a 2-byte port number in network byte order, or a 16-byte IPv6 address in network byte order followed by a 2-byte port number in network byte order.
ip | The compact address string buffer |
len | Length of the compact address string. |
int from_hex | ( | const char * | s, |
unsigned char | id[20] | ||
) |
Convert a hexadecimal representation string to a 160-bit value.
Scans the hexadecimal string s and converts it to a binary info-hash.
s | The hexadecimal string. |
id | The buffer into which the info-hash will be returned. |
const char* hex | ( | const unsigned char | id[20] | ) |
Return the hexadecimal representation of a 160-bit value.
Formats the given binary info-hash into an hexadecimal string. The string is returned in a statically allocated buffer, which subsequent calls will overwrite and is therefore not reentrant.
id | The 160-bit value to convert. |
int sockaddr_cmp | ( | const struct sockaddr * | s1, |
const struct sockaddr * | s2 | ||
) |
Compare two socket addresses.
s1 | First socket address. |
s2 | Second socket address. |
const char* sockaddr_fmt | ( | const struct sockaddr * | sa, |
socklen_t | addrlen | ||
) |
Format socket address.
Returns the socket address as a human-readable string. This function supports AF_INET and AF_INET6 socket address families. The string is returned in a statically allocated buffer, which subsequent calls will overwrite, and is therefore not reentrant.
sa | The socket address |
addrlen | Length of the socket address structure |