build standalone ipx utilities without ncpfs private headers

This commit is contained in:
Mario Fetka
2026-04-29 19:17:02 +02:00
parent 80f13f2193
commit ea1cadb737
32 changed files with 11006 additions and 666 deletions

View File

@@ -1,5 +1,5 @@
/* Copyright (c) 1995-1996 Caldera, Inc. All Rights Reserved.
*
* See file COPYING for details.
*/
@@ -9,193 +9,176 @@
#include <errno.h>
#include <string.h>
#include <netinet/in.h>
#include <netipx/ipx.h>
#include <linux/if.h>
#include <ncp/kernel/ipx.h>
#include <ncp/kernel/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
static struct ifreq id;
static char *progname;
#include "ipxutil.h"
void
#include "nls.h"
static struct ifreq id;
static char *progname;
static void
usage(void)
{
fprintf(stderr, "Usage: %s add net_number(hex) node(hex)\n\
Usage: %s del\n", progname, progname);
exit(-1);
fprintf(stderr, _("Usage: %s add net_number(hex) node(hex)\n"
"Usage: %s del\n"),
progname, progname);
}
int
map_char_to_val(char dig)
{
char digit = tolower(dig);
if ((digit >= '0') && (digit <= '9')) {
return digit - '0';
} else if ((digit >= 'a') && (digit <= 'f')) {
return (10 + (digit - 'a'));
} else {
return 0;
}
}
int
static int
ipx_add_internal_net(int argc, char **argv)
{
struct sockaddr_ipx *sipx = (struct sockaddr_ipx *)&id.ifr_addr;
int s;
int result;
unsigned long netnum;
char errmsg[80];
int nodelen;
char *node;
char tmpnode[13];
unsigned char *tout;
char *tin;
int i;
if (argc != 3) {
struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) &id.ifr_addr;
int s;
int result;
unsigned long netnum;
int i;
if (argc < 1)
{
usage();
return -1;
}
netnum = strtoul(argv[1], (char **)NULL, 16);
if ((netnum == 0L) || (netnum == 0xffffffffL)) {
fprintf(stderr, "%s: Inappropriate network number %08lX\n",
i = sscanf_ipx_addr(sipx, argv[0], SSIPX_NETWORK|SSIPX_NODE);
if (!(i & SSIPX_NETWORK)) {
fprintf(stderr, _("%s: Invalid internal network address %s\n"),
progname, argv[0]);
return -1;
}
if (!(i & SSIPX_NODE)) {
if (argc < 2)
memcpy(sipx->sipx_node, "\0\0\0\0\0\1", IPX_NODE_LEN);
else if (sscanf_ipx_addr(sipx, argv[1], SSIPX_NODE) != SSIPX_NODE) {
fprintf(stderr, _("%s: Invalid internal network node %s\n"),
progname, argv[1]);
return -1;
}
}
netnum = ntohl(sipx->sipx_network);
if ((netnum == 0L) || (netnum == 0xffffffffL))
{
fprintf(stderr, _("%s: Inappropriate network number %08lX\n"),
progname, netnum);
exit(-1);
return -1;
}
node = argv[2];
nodelen = strlen(node);
if (nodelen > 12) {
fprintf(stderr, "%s: Node length is too long (> 12).\n", progname);
exit(-1);
}
for (i = 0; (i < nodelen) && isxdigit(node[i]); i++)
;
if (i < nodelen) {
fprintf(stderr, "%s: Invalid value in node, must be hex digits.\n",
progname);
exit(-1);
}
strcpy(tmpnode, "000000000000");
memcpy(&(tmpnode[12-nodelen]), node, nodelen);
for (tin = tmpnode, tout = sipx->sipx_node; *tin != '\0'; tin += 2, tout++) {
*tout = (unsigned char) map_char_to_val(*tin);
*tout <<= 4;
*tout |= (unsigned char) map_char_to_val(*(tin+1));
}
if ((memcmp(sipx->sipx_node, "\0\0\0\0\0\0\0\0", IPX_NODE_LEN) == 0) ||
(memcmp(sipx->sipx_node, "\377\377\377\377\377\377", IPX_NODE_LEN) == 0)){
fprintf(stderr, "%s: Node is invalid.\n", progname);
exit(-1);
(memcmp(sipx->sipx_node, "\377\377\377\377\377\377", IPX_NODE_LEN) == 0))
{
fprintf(stderr, _("%s: Node is invalid.\n"), progname);
return -1;
}
sipx->sipx_network = htonl(netnum);
sipx->sipx_type = IPX_FRAME_NONE;
sipx->sipx_special = IPX_INTERNAL;
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
if (s < 0) {
sprintf(errmsg, "%s: socket", progname);
perror(errmsg);
exit(-1);
if (s < 0)
{
fprintf(stderr, _("%s: socket: %s\n"), progname,
strerror(errno));
return -1;
}
sipx->sipx_family = AF_IPX;
sipx->sipx_action = IPX_CRTITF;
i = 0;
do {
do
{
result = ioctl(s, SIOCSIFADDR, &id);
i++;
} while ((i < 5) && (result < 0) && (errno == EAGAIN));
}
while ((i < 5) && (result < 0) && (errno == EAGAIN));
if (result == 0) exit(0);
switch (errno) {
if (result == 0) {
return 0;
}
switch (errno)
{
case EEXIST:
fprintf(stderr, "%s: Primary network already selected.\n",
fprintf(stderr, _("%s: Primary network already selected.\n"),
progname);
break;
case EADDRINUSE:
fprintf(stderr, "%s: Network number (%08X) already in use.\n",
progname, htonl(sipx->sipx_network));
fprintf(stderr, _("%s: Network number (%08X) already in use.\n"),
progname, (u_int32_t)htonl(sipx->sipx_network));
break;
case EAGAIN:
fprintf(stderr,
"%s: Insufficient memory to create internal net.\n",
fprintf(stderr,
_("%s: Insufficient memory to create internal net.\n"),
progname);
break;
default:
sprintf(errmsg, "%s: ioctl", progname);
perror(errmsg);
fprintf(stderr, _("%s: ioctl: %s\n"), progname,
strerror(errno));
break;
}
exit(-1);
return -1;
}
int
ipx_del_internal_net(int argc, char **argv)
static int
ipx_del_internal_net(int argc, char **argv __attribute__((unused)))
{
struct sockaddr_ipx *sipx = (struct sockaddr_ipx *)&id.ifr_addr;
int s;
int result;
char errmsg[80];
struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) &id.ifr_addr;
int s;
int result;
(void)argv;
if (argc != 1) {
if (argc != 0)
{
usage();
return -1;
}
sipx->sipx_network = 0L;
sipx->sipx_special = IPX_INTERNAL;
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
if (s < 0) {
sprintf(errmsg, "%s: socket", progname);
perror(errmsg);
exit(-1);
if (s < 0)
{
fprintf(stderr, _("%s: socket: %s\n"), progname,
strerror(errno));
return -1;
}
sipx->sipx_family = AF_IPX;
sipx->sipx_action = IPX_DLTITF;
result = ioctl(s, SIOCSIFADDR, &id);
if (result == 0) exit(0);
if (result == 0) {
return 0;
}
switch (errno) {
switch (errno)
{
case ENOENT:
fprintf(stderr, "%s: No internal network configured.\n", progname);
fprintf(stderr, _("%s: No internal network configured.\n"), progname);
break;
default:
sprintf(errmsg, "%s: ioctl", progname);
perror(errmsg);
fprintf(stderr, _("%s: ioctl: %s\n"), progname,
strerror(errno));
break;
}
exit(-1);
return -1;
}
int
main(int argc, char **argv)
{
int i;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
progname = argv[0];
if (argc < 2) {
if (argc < 2)
{
usage();
exit(-1);
return -1;
}
if (strncasecmp(argv[1], "add", 3) == 0) {
for (i = 1; i < (argc-1); i++)
argv[i] = argv[i+1];
ipx_add_internal_net(argc-1, argv);
} else if (strncasecmp(argv[1], "del", 3) == 0) {
for (i = 1; i < (argc-1); i++)
argv[i] = argv[i+1];
ipx_del_internal_net(argc-1, argv);
if (strcasecmp(argv[1], "add") == 0)
{
return ipx_add_internal_net(argc - 2, argv + 2);
} else if (strcasecmp(argv[1], "del") == 0)
{
return ipx_del_internal_net(argc - 2, argv + 2);
}
usage();
return 0;
return -1;
}