Files
nt-lite/code/user/apps/resolve/resolve.c
T
maksw 73abd6f90d isolate POSIX builds from the host UCRT, wire lwext4 and ntfs-3g as ext4.sys and ntfs.sys, split the FAT driver into directory/file/async/driver/mount units, add posixsrv and dwm plus input/console/desktop syscall clients and a pile of new smoke targets, rename serial.sys to cereal.sys, name HDA/USB/lwIP/AHCI workers, harden ATA probing/reset/removal around actual hardware deadlines, absent-channel detection, diagnostics and explicit worker lifetime, redo ACPI S5 shutdown around GAS/MMIO and HW-reduced firmware, scan SSDTs for _S5 and deal with Intel SMI sleep trapping, make serial and SMP timeouts use real monotonic deadlines, add thread names and fix terminal thread teardown, scheduler and APC prepare/commit races, make advisory file locks queryable and preserve split ranges and add mutable file append state, add shared-memory pipes with kernel-assisted wait/wake, introduce capability-scoped input and display managers, split surface map rights into read/write, add explicit unmap and replace present with commit/generation/damage tracking while keeping physical presentation under the display manager, decouple native exception classes from Win32 exception numbers and translate them in kernel32, add opaque process startup data, bump the resource protocol to v3 with namespace directories, symlinks and enumeration and service control to v2 with generic READY handle exports, add the new POSIX errno/status surface and rebuild fds around posixsrv-owned shared open descriptions, descriptor-local flags, exact inheritance snapshots, dup/fcntl/record locks and shared-ring pipes, add waitpid, POSIX credentials/groups/sessions/passwd/group lookups and move sockets onto stable open descriptions, port the shells and apps to the new console/input services and surface commit API, teach init to load services.ini and start/supervise RSSRV, DWM and generic services under restricted capabilities while publishing their endpoints through RSSRV, split RSSRV into namespace, volume, display, session, input, console and resource components and make /SystemRoot a real symlink to the independently published system volume, shift the syscall table again, expand lock/resource/surface/POSIX/service/thread smoke coverage, make docs scream ASK QUESTIONS and DISCUSS at LLMs, replace MIT No Attribution with WTFPL+.
2026-09-16 10:33:20 +02:00

133 lines
3.6 KiB
C

// User application entry points for resolve.
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <ntlite/syscall.h>
#include <ntlite/console_service.h>
// Prints the requested operation.
static void print(const char* s) {
if (s) (void)NtlConsoleWrite(SYS_HANDLE_INVALID, s, strlen(s), NULL);
}
// Prints char.
static void print_char(char c) {
(void)NtlConsoleWrite(SYS_HANDLE_INVALID, &c, 1, NULL);
}
// Prints u64.
static void print_u64(uint64_t v) {
char buf[32];
int n = 0;
if (v == 0) { print("0"); return; }
while (v && n < (int)sizeof(buf)) {
buf[n++] = (char)('0' + (v % 10));
v /= 10;
}
while (n > 0) print_char(buf[--n]);
}
// Implements the next token operation.
static const char* next_token(const char* s, char* out, size_t outSize) {
if (!s || !out || outSize == 0) return NULL;
while (*s == ' ' || *s == '\t') s++;
if (*s == 0) { out[0] = 0; return NULL; }
size_t n = 0;
while (*s && *s != ' ' && *s != '\t') {
if (n + 1 < outSize) out[n++] = *s;
s++;
}
out[n] = 0;
return s;
}
// Prints ipv4.
static void print_ipv4(const uint8_t ip[4]) {
print_u64(ip[0]); print("."); print_u64(ip[1]); print(".");
print_u64(ip[2]); print("."); print_u64(ip[3]);
}
// Prints ipv6.
static void print_ipv6(const uint8_t ip[16]) {
static const char hex[] = "0123456789abcdef";
for (int i = 0; i < 8; ++i) {
uint16_t word = ((uint16_t)ip[i * 2] << 8) | ip[i * 2 + 1];
int started = 0;
for (int shift = 12; shift >= 0; shift -= 4) {
unsigned nibble = (word >> shift) & 0xfu;
if (nibble || started || shift == 0) {
char c = hex[nibble];
print_char(c);
started = 1;
}
}
if (i != 7)
print(":");
}
}
// Runs the requested operation.
int main(void) {
char familyText[16];
char name[256];
uint32_t family = 0;
const char* cmd = SysGetPeb()->CommandLine.Data;
cmd = next_token(cmd, name, sizeof(name));
(void)cmd;
familyText[0] = 0;
name[0] = 0;
if (cmd) {
const char* rest = next_token(cmd, familyText, sizeof(familyText));
if (strcmp(familyText, "-4") == 0) {
family = SYS_AF_INET;
if (rest)
(void)next_token(rest, name, sizeof(name));
} else if (strcmp(familyText, "-6") == 0) {
family = SYS_AF_INET6;
if (rest)
(void)next_token(rest, name, sizeof(name));
} else {
strcpy(name, familyText);
}
}
if (!name[0]) {
print("usage: resolve.exe [-4|-6] hostname\n");
SysExitProcess(1);
}
SYS_SOCKET_ADDRESS addr;
size_t addrSize = sizeof(addr);
SYS_RESOLVE_HOST_REQUEST req;
memset(&addr, 0, sizeof(addr));
memset(&req, 0, sizeof(req));
req.Size = sizeof(req);
req.Name = SysSvFromCstr(name);
req.Family = family ? family : SYS_AF_INET6;
req.AddressOut = &addr;
req.AddressSizeInOut = &addrSize;
uint32_t st = SysResolveHost(&req);
if (st != NTLSTATUS_SUCCESS && family == 0) {
req.Family = SYS_AF_INET;
addrSize = sizeof(addr);
st = SysResolveHost(&req);
}
if (st != NTLSTATUS_SUCCESS) {
print("resolve: SysResolveHost failed "); print_u64(st); print("\n");
SysExitProcess(1);
}
print(name);
print(" -> ");
if (addr.Family == SYS_AF_INET6)
print_ipv6(addr.Address);
else
print_ipv4(addr.Address);
print("\n");
SysExitProcess(0);
return 0;
}