add lwIP TCP/IP stack as a runtime driver, native socket syscalls, SysGetMemoryStatus replacing CatchAllDebugBucket, fix timeGetTime to return milliseconds, fix SysSleep to interpret argument as milliseconds, SysGetTick now returns microseconds, harden all syscalls against bad user pointers with CopyFromUser/CopyToUser/MmProbeUser throughout, add networking test apps, port-forward 8080 in runa.bat, split LWIP_DRIVER_CFLAGS, add settings.ini to deploy, remove ethernet.c stub
This commit is contained in:
1 parent
18b4dd0f61
commit
df13b8056c
365 files changed
+143263
-1362
No files matched your search
@@ -0,0 +1,81 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <syscall.h>
|
||||
|
||||
static void print(const char* s) {
|
||||
if (s) SysWriteConsole(s, strlen(s));
|
||||
}
|
||||
|
||||
static void print_char(char c) {
|
||||
SysWriteConsole(&c, 1);
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
char name[256];
|
||||
const char* cmd = SysGetPeb()->CommandLine;
|
||||
cmd = next_token(cmd, name, sizeof(name)); // program path
|
||||
(void)cmd;
|
||||
|
||||
name[0] = 0;
|
||||
if (cmd)
|
||||
(void)next_token(cmd, name, sizeof(name));
|
||||
if (!name[0]) {
|
||||
print("usage: resolve.exe hostname\n");
|
||||
SysExitProcess(1);
|
||||
}
|
||||
|
||||
SYS_SOCKET_ADDRESS_IPV4 addr;
|
||||
size_t addrSize = sizeof(addr);
|
||||
SYS_RESOLVE_HOST_REQUEST req;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.Name = name;
|
||||
req.NameLength = strlen(name);
|
||||
req.Family = SYS_AF_INET;
|
||||
req.AddressOut = &addr;
|
||||
req.AddressSizeInOut = &addrSize;
|
||||
|
||||
uint32_t st = SysResolveHost(&req);
|
||||
if (st != SYS_STATUS_SUCCESS) {
|
||||
print("resolve: SysResolveHost failed "); print_u64(st); print("\n");
|
||||
SysExitProcess(1);
|
||||
}
|
||||
|
||||
print(name);
|
||||
print(" -> ");
|
||||
print_ipv4(addr.Address);
|
||||
print("\n");
|
||||
SysExitProcess(0);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user