DEFLNG A-Z REM $INCLUDE: 'WinSock2.Dec' REM $INCLUDE: 'Helper.Dec' DECLARE FUNCTION GetStr$ (s$) DIM W AS WsaData DIM H AS hostent DIM Rc, Rd, V, N$, N, Re ' must redim so that the calls can change the size REDIM H1(0) AS STRING, H2(0) AS LONG COLOR 11: CLS PRINT "DNSLOOK - Very simple DSN lookup sample" PRINT N$ = LTRIM$(RTRIM$(COMMAND$)) IF N$ = "" THEN PRINT "Usage: DSNLOOK " SYSTEM ELSE PRINT "Looking up: '" + N$ + "'" PRINT END IF ' initialize winsock V = &H202 ' (byte)minor + (byte)major Rc = WsaStartup(V, W) IF Rc <> 0 THEN PRINT "WsaStartup Rc: ", Rc GOTO CloseIt END IF ' lookup name Re = gethostbyname(N$) IF Re = 0 THEN Rd = WsaGetLastError PRINT "gethostbyname WsaGetLastError Rc: ", Rd GOTO CloseIt END IF ' copy the returned hostent structure to basic GetStruc Re, H, LEN(H) ' print returned name PRINT "Name Returned: '" + GetCharP(H.hName) + "'" PRINT ' convert alias list to a string array GetCharPP H.hAliases, 0, H1() ' convert address list to a long array GetLongPP H.hAddrList, H2() ' display aliases, if any returned IF UBOUND(H1) > 0 THEN PRINT "Aliases Returned" FOR N = 1 TO UBOUND(H1) PRINT "'" + H1(N) + "'" NEXT N PRINT END IF ' display addresses, if any returned IF UBOUND(H2) > 0 THEN PRINT "Addresses Returned" FOR N = 1 TO UBOUND(H2) PRINT GetCharP$(inetntoa(H2(N))) NEXT N PRINT END IF ' close winsock CloseIt: Rd = WsaCleanup IF Rc <> 0 THEN Rd = WsaGetLastError PRINT "WsaCleanup WsaGetLastError Rc: ", Rd END IF ' end of program END FUNCTION GetStr$ (s$) ' convert C string (char *) to a basic string GetStr$ = LEFT$(s$, INSTR(s$, CHR$(0)) - 1) END FUNCTION