feat: implement SLIST command

This commit is contained in:
Mario Fetka
2026-05-22 19:34:07 +02:00
parent dbf7be5104
commit 6f998a497d
2 changed files with 71 additions and 18 deletions

View File

@@ -117,3 +117,8 @@ install(FILES "${MARS_DOSUTILS_NET_EXE}"
install(FILES "${MARS_DOSUTILS_NET_EXE}"
DESTINATION "${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/login"
RENAME map.exe)
install(FILES "${MARS_DOSUTILS_NET_EXE}"
DESTINATION "${MARS_NWE_INSTALL_FULL_FILEDIR}/SYS/login"
RENAME slist.exe)

84
slist.c
View File

@@ -2,17 +2,49 @@
#include "net.h"
#define NCP_BINDERY_FSERVER 0x0004
static int usage(void)
{
fprintf(stderr, "usage:\t%s [pattern]\n", funcname);
return(-1);
fprintf(stdout, "Usage: SLIST [Server] [/Continue]\n");
return(0);
}
static void print_net_node(uint8 *addr)
static int same_arg(char *a, char *b)
{
fprintf(stdout, "%08lX %02X%02X%02X%02X%02X%02X",
while (*a || *b) {
int ca = *a++;
int cb = *b++;
if (ca >= 'a' && ca <= 'z') ca -= 32;
if (cb >= 'a' && cb <= 'z') cb -= 32;
if (ca != cb) return(0);
}
return(1);
}
static int is_help_arg(char *s)
{
if (!s) return(0);
return(same_arg(s, "/?") || same_arg(s, "-?") || same_arg(s, "?"));
}
static unsigned long node_to_number(uint8 *addr)
{
unsigned long n = 0;
int i;
for (i = 4; i < 10; i++)
n = (n << 8) + addr[i];
return(n);
}
static void print_net_node_status(uint8 *addr, int is_default)
{
fprintf(stdout, "[%08lX][%12lu]%s",
(unsigned long)GET_BE32(addr),
addr[4], addr[5], addr[6], addr[7], addr[8], addr[9]);
node_to_number(addr),
is_default ? "Default" : "");
}
int func_slist(int argc, char *argv[], int mode)
@@ -22,33 +54,50 @@ int func_slist(int argc, char *argv[], int mode)
uint8 pattern[50];
int found = 0;
int result;
int i;
(void)mode;
if (argc > 2) return(usage());
strcpy(pattern, "*");
for (i = 1; i < argc; i++) {
if (is_help_arg(argv[i])) return(usage());
if (argv[i][0] == '/' || argv[i][0] == '-') {
if (same_arg(argv[i], "/C") || same_arg(argv[i], "/CONTINUE") ||
same_arg(argv[i], "-C") || same_arg(argv[i], "-CONTINUE")) {
continue;
}
return(usage());
}
strmaxcpy(pattern, argv[i], sizeof(pattern) - 1);
}
if (argc == 2) strmaxcpy(pattern, argv[1], sizeof(pattern) - 1);
else strcpy(pattern, "*");
upstr(pattern);
fprintf(stdout, "\n%-52s%-10s%-12s\n",
"Known NetWare File Servers", "Network", "Node Address");
fprintf(stdout,
"-----------------------------------------------"
"---------------------------\n");
/*
* Novell-like layout from the DOS client:
* Known NetWare File Servers Network Node Address Status
* ------------------------- -------- -------------------
*/
fprintf(stdout, "%-44sNetwork Node Address Status\n",
"Known NetWare File Servers");
fprintf(stdout, "%-44s------- ----------- ------\n",
"--------------------------");
while ((result = ncp_17_37(last_id, NCP_BINDERY_FSERVER,
pattern, &obj)) == 0) {
NW_PROPERTY prop;
found = 1;
found++;
last_id = obj.object_id;
fprintf(stdout, "%-52s", obj.object_name);
fprintf(stdout, "%-44s", obj.object_name);
if (!ncp_17_3d(NCP_BINDERY_FSERVER, obj.object_name,
1, "NET_ADDRESS", &prop)) {
print_net_node(prop.value);
print_net_node_status(prop.value, found == 1);
}
fprintf(stdout, "\n");
@@ -56,8 +105,7 @@ int func_slist(int argc, char *argv[], int mode)
if (last_id == MAX_U32) break;
}
if (!found)
fprintf(stdout, "No servers found\n");
fprintf(stdout, "\nTotal of %d file servers found\n", found);
return(0);
}