Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/system/lib/libc/lookup_name.c
6162 views
1
// Emscripten-specific version of musl/src/network/lookup_name.c
2
3
#include <assert.h>
4
#include <string.h>
5
#include "musl/src/network/lookup.h"
6
#include "emscripten_internal.h"
7
8
int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, int flags)
9
{
10
/* We currently only support the callsite in gethostbyname2_r which
11
* passes AI_CANONNAME. Remove this assertion if we ever expand
12
* this support. */
13
assert(flags == AI_CANONNAME);
14
15
if (family != AF_INET) {
16
return EAI_SYSTEM;
17
}
18
19
/* This hunk is duplicated from musl/src/network/lookup_name.c */
20
*canon = 0;
21
if (name) {
22
/* reject empty name and check len so it fits into temp bufs */
23
size_t l = strnlen(name, 255);
24
if (l-1 >= 254)
25
return EAI_NONAME;
26
memcpy(canon, name, l+1);
27
}
28
29
/* We only support a single address */
30
uint32_t addr = _emscripten_lookup_name(name);
31
memset(&buf[0], 0, sizeof(buf[0]));
32
memcpy(&buf[0].addr, &addr, sizeof(addr));
33
return 1;
34
}
35
36