cosmopolitan/libc/dns/hoststxt.h

47 lines
1.3 KiB
C
Raw Normal View History

2020-06-15 14:18:57 +00:00
#ifndef COSMOPOLITAN_LIBC_DNS_HOSTSTXT_H_
#define COSMOPOLITAN_LIBC_DNS_HOSTSTXT_H_
2021-05-16 04:53:26 +00:00
#include "libc/sock/sock.h"
#include "libc/stdio/stdio.h"
2020-06-15 14:18:57 +00:00
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct HostsTxtEntry {
2021-05-16 04:53:26 +00:00
uint8_t ip[4]; /* inet_ntop(AF_INET, he->ip, buf, size) */
uint32_t name; /* &ht->strings.p[he->name] */
uint32_t canon; /* &ht->strings.p[he->canon] */
2020-06-15 14:18:57 +00:00
};
struct HostsTxtEntries {
2021-05-16 04:53:26 +00:00
size_t i, n;
2020-06-15 14:18:57 +00:00
struct HostsTxtEntry *p;
};
struct HostsTxtStrings {
2021-05-16 04:53:26 +00:00
size_t i, n;
2020-06-15 14:18:57 +00:00
char *p;
};
#define HOSTSTXT_NOT_SORTED 0
#define HOSTSTXT_SORTEDBYNAME 1
#define HOSTSTXT_SORTEDBYADDR 2
2020-06-15 14:18:57 +00:00
struct HostsTxt {
int sorted_by;
2020-06-15 14:18:57 +00:00
struct HostsTxtEntries entries;
struct HostsTxtStrings strings;
};
2021-05-16 04:53:26 +00:00
const struct HostsTxt *GetHostsTxt(void) returnsnonnull;
void FreeHostsTxt(struct HostsTxt **) paramsnonnull();
int ParseHostsTxt(struct HostsTxt *, FILE *) paramsnonnull();
void SortHostsTxt(struct HostsTxt *, int) paramsnonnull();
2021-05-16 04:53:26 +00:00
int ResolveHostsTxt(const struct HostsTxt *, int, const char *,
2020-06-15 14:18:57 +00:00
struct sockaddr *, uint32_t, const char **)
paramsnonnull((1, 3));
int ResolveHostsReverse(const struct HostsTxt *, int, const uint8_t *, char *,
size_t);
2020-06-15 14:18:57 +00:00
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_DNS_HOSTSTXT_H_ */