38 lines
2.8 KiB
C
38 lines
2.8 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
* Freestanding x86 Win32 Winsock 1.1 diagnostic. No CRT, no driver install.
|
|
* IPX_ADDRESS ABI per public Winsock API. Only queries local provider.
|
|
*/
|
|
typedef unsigned long U32;
|
|
typedef unsigned short U16;
|
|
typedef unsigned char U8;
|
|
#define IMPORT __declspec(dllimport)
|
|
#define CALL __stdcall
|
|
IMPORT void CALL ExitProcess(U32);
|
|
IMPORT void* CALL GetStdHandle(U32);
|
|
IMPORT int CALL WriteFile(void*,const void*,U32,U32*,void*);
|
|
IMPORT int CALL WSAStartup(U16,void*);
|
|
IMPORT int CALL WSACleanup(void);
|
|
IMPORT int CALL WSAGetLastError(void);
|
|
IMPORT U32 CALL socket(int,int,int);
|
|
IMPORT int CALL closesocket(U32);
|
|
IMPORT int CALL getsockopt(U32,int,int,char*,int*);
|
|
IMPORT int CALL bind(U32,const void*,int);
|
|
IMPORT int CALL getsockname(U32,void*,int*);
|
|
struct address {int adapter; U8 net[4],node[6],wan,status; int maxpkt; U32 speed;};
|
|
struct ipxaddr {U16 family; U8 net[4],node[6]; U16 port;};
|
|
typedef char check_a[sizeof(struct address)==24?1:-1];
|
|
typedef char check_b[sizeof(struct ipxaddr)==14?1:-1];
|
|
static union {U32 align; U8 bytes[512];} wsadata;
|
|
static void *out;
|
|
static void text(const char*s){U32 n=0,w;while(s[n])n++;WriteFile(out,s,n,&w,0);}
|
|
static void hex(const U8*p,unsigned n){static const char h[]="0123456789ABCDEF";char b[3];unsigned i; b[2]=0;for(i=0;i<n;i++){b[0]=h[p[i]>>4];b[1]=h[p[i]&15];text(b);}}
|
|
static void number(U32 v){char b[11];unsigned i=10;b[i]=0;do{b[--i]=(char)('0'+v%10);v/=10;}while(v);text(b+i);}
|
|
static void clear(void*p,unsigned n){volatile U8*b=(volatile U8*)p;while(n--)*b++=0;}
|
|
static void err(const char*s,int e){text(s);text(": ");number((U32)e);text("\r\n");}
|
|
void start(void){U32 s;int rc,i,n,count=0;struct address a;struct ipxaddr local;out=GetStdHandle((U32)-11);text("MARS IPX diagnostic (Winsock 1.1)\r\n");rc=WSAStartup(0x0101,wsadata.bytes);if(rc){err("WSAStartup",rc);ExitProcess(1);return;}
|
|
s=socket(6,2,1000);if(s==0xffffffffUL){err("AF_IPX socket",WSAGetLastError());WSACleanup();ExitProcess(2);return;}
|
|
for(i=0;i<64;i++){clear(&a,sizeof a);a.adapter=i;n=sizeof a;if(getsockopt(s,1000,0x4007,(char*)&a,&n)||n<(int)sizeof a)continue;count++;text("Adapter ");number(i);text(" network=");hex(a.net,4);text(" node=");hex(a.node,6);text(" maxpkt=");number(a.maxpkt);text("\r\n");}
|
|
if(!count)text("IPX_ADDRESS enumeration unavailable; trying wildcard bind.\r\n");
|
|
clear(&local,sizeof local);local.family=6;rc=bind(s,&local,sizeof local);if(rc){err("IPX bind",WSAGetLastError());}else{n=sizeof local;rc=getsockname(s,&local,&n);if(rc)err("getsockname",WSAGetLastError());else if(n<(int)sizeof local){text("Short IPX address\r\n");rc=-1;}else{text("Bound network=");hex(local.net,4);text(" node=");hex(local.node,6);text("\r\n");}}
|
|
closesocket(s);WSACleanup();text("Local IPX test only; not a gateway or Internet test.\r\n");ExitProcess(rc?3:0);}
|