Pierre,
Thanks for taking a look at this HostEntStru TYPE change. I am always eager to learn something new.
Trying "google.com" as the hostname in your code, it generates Google's three IP addresses, the same ones as are reported by the Window's command line utility NSLOOKUP. IP addresses beyond the 3rd are garbage in memory I guess.
David
Announcement
Collapse
No announcement yet.
Code Doesn't Compile - pointer "@" syntax error
Collapse
X
-
Seem's that the newer HostEntStru definition is more appropriate
becose h_alias is an array of pointers to aliasses names, in fact it's Microsoft way.
It would be appreciated if anybody can test the following code
with a host that have one or many aliasses names and give feedback
so we can know if code is valid or need corection...
Code:#COMPILE EXE '#Win 8.04# #DIM ALL #INCLUDE "WIN32API.INC" '#2005-01-27# #INCLUDE "WSOCK32.INC" TYPE HostEntStru 'PowerBASIC 7+ definition h_name AS ASCIIZ PTR 'Official name of the host h_alias AS DWORD 'A NULL-terminated array of alternate names. h_addr AS INTEGER 'The type of address being returned. h_len AS INTEGER 'The length, in bytes, of each address. h_list AS DWORD 'A NULL-terminated list of addresses for the host. END TYPE %MAX_HostName_LEN = 128 '______________________________________________________________________________ FUNCTION AddrTypeString(AddrType AS INTEGER)AS STRING SELECT CASE AddrType CASE %AF_UNSPEC : FUNCTION = "AF_UNSPEC" ' 0 unspecified CASE %AF_UNIX : FUNCTION = "AF_UNIX" ' 1 local to host (pipes, portals) CASE %AF_INET : FUNCTION = "AF_INET" ' 2 internetwork: UDP, TCP, etc. CASE %AF_IMPLINK : FUNCTION = "AF_IMPLINK" ' 3 arpanet imp addresses CASE %AF_PUP : FUNCTION = "AF_PUP" ' 4 pup protocols: e.g. BSP CASE %AF_CHAOS : FUNCTION = "AF_CHAOS" ' 5 mit CHAOS protocols CASE %AF_IPX, %AF_NS : FUNCTION = "F_IPX - AF_NS" ' 6 IPX and SPX, XEROX NS protocols CASE %AF_ISO, %AF_OSI : FUNCTION = "AF_ISO - AF_OSI" ' 7 ISO protocols CASE %AF_ECMA : FUNCTION = "AF_ECMA" ' 8 european computer manufacturers CASE %AF_DATAKIT : FUNCTION = "AF_DATAKIT" ' 9 datakit protocols CASE %AF_CCITT : FUNCTION = "AF_CCITT" '10 CCITT protocols, X.25 etc CASE %AF_SNA : FUNCTION = "AF_SNA" '11 IBM SNA CASE %AF_DECnet : FUNCTION = "AF_DECnet" '12 DECnet CASE %AF_DLI : FUNCTION = "AF_DLI" '13 Direct data link interface CASE %AF_LAT : FUNCTION = "AF_LAT" '14 LAT CASE %AF_HYLINK : FUNCTION = "AF_HYLINK" '15 NSC Hyperchannel CASE %AF_APPLETALK : FUNCTION = "AF_APPLETALK" '16 AppleTalk CASE %AF_NETBIOS : FUNCTION = "AF_NETBIOS" '17 NetBios-style addresses END SELECT END FUNCTION '______________________________________________________________________________ FUNCTION PBMAIN() LOCAL sBuffer AS STRING LOCAL WinSock AS WsaData LOCAL HostName AS ASCIIZ * %MAX_HostName_LEN LOCAL HostEntry AS HostEntStru PTR LOCAL ipPointer AS ASCIIZ PTR LOCAL AliasPointer AS ASCIIZ PTR LOCAL ListArrayPointer AS DWORD POINTER LOCAL AliasArrayPointer AS DWORD POINTER LOCAL RetVal AS LONG RetVal = WsaStartup(&H101, WinSock) 'Initiates Windows Sockets IF RetVal = %NOERROR THEN HOST NAME TO HostName 'Set HostName to your machine name... HostEntry = GetHostByName(HostName) 'Returns a pointer to the hostent structure IF HostEntry THEN 'GetHostByName was successfull sBuffer = "IP addresses assignement..." & $CRLF & $CRLF sBuffer = sBuffer & "Host name: " & @[email protected]_name & $CRLF AliasArrayPointer = @HostEntry.h_alias 'We'll use AliasArrayPointer instead of .h_alias DO WHILE @AliasArrayPointer 'If pointer is zero then no more data AliasPointer = @AliasArrayPointer sBuffer = sBuffer & "Alias: " & @AliasPointer & $CRLF @AliasArrayPointer = @AliasArrayPointer + 4 '4 is dword lenght LOOP sBuffer = sBuffer & "Adress type: " & AddrTypeString(@HostEntry.h_addr) & $CRLF sBuffer = sBuffer & "Adress lenght:" & STR$(@HostEntry.h_len) & $CRLF & $CRLF ListArrayPointer = @HostEntry.h_list 'We'll use ListArrayPointer instead of .h_list DO WHILE @@ListArrayPointer 'If pointer is zero then no more data ipPointer = inet_ntoa(@@ListArrayPointer) 'Converts network address into a dotted string sBuffer = sBuffer & "ip : " & @ipPointer & $CRLF @ListArrayPointer = @ListArrayPointer + @HostEntry.h_len 'Move to next entry LOOP WSACleanup MessageBox %HWND_DESKTOP, BYCOPY sBuffer, "GetHostByName", 64 END IF END IF END FUNCTION '______________________________________________________________________________
Leave a comment:
-
Thanks for the references Fred. I took a brief look and will have to return to them later on a more studied level.
David
Leave a comment:
-
Pointer Examples
Maybe this will help David...
C To PowerBASIC Pointer Conversions
Pointers, Dynamic Memory Allocation, and Instance Data
They include real short programs along with output showing how to get started with pointers.
Leave a comment:
-
> do wish though that I understood why the structure in wsock32.inc was changed
That would be PwerBASIC Inc's Windows' Header Information Management system.
aka "WHIM"
MCM
Leave a comment:
-
As an immediate work around I simply created the same hostentStru I found in the wsock32.inc for PB/DLL 6.1 with a change for the name of the structure.
Code:TYPE hostentStru2 h_name AS ASCIIZ PTR h_alias AS ASCIIZ PTR h_addr AS INTEGER h_len AS INTEGER h_list AS LONG PTR END TYPE
I do wish though that I understood why the structure in wsock32.inc was changed. I also wish I had more experience with pointers.
DavidLast edited by David Gwillim; 16 Oct 2007, 11:02 PM.
Leave a comment:
-
OK I did a bit more digging and it seems that the definition for the structure TYPE hostentStru in wsock32.inc changed from this in PB/DLL 6.1:
Code:TYPE hostentStru h_name AS ASCIIZ PTR h_alias AS ASCIIZ PTR h_addr AS INTEGER h_len AS INTEGER h_list AS LONG PTR END TYPE
Code:TYPE hostentStru h_name AS ASCIIZ PTR ' official name of host h_alias AS DWORD ' alias list (pointer to ASCIIZ PTR list) h_addr AS INTEGER ' host address type h_len AS INTEGER ' length of address h_list AS DWORD ' list of addresses (pointer to ASCIIZ PTR list) END TYPE
David
Leave a comment:
-
Code Doesn't Compile - pointer "@" syntax error
I retrieved the following from the Source Code forum and found that it doesn't compile in PBWin 7.04 and later, but does compile in PBDLL 6.1.
It's some code by Florent Heyworth for DNS Query.
The problem code uses pointers and any line containing
@[email protected]@h_list
triggers a compiler syntax error at the "@@".
I have never used pointers and am not familiar with what changes occurred in the allowed syntax for their use. Could someone help me please? I would like to get the code to compile.
Thanks,
DavidLast edited by David Gwillim; 16 Oct 2007, 08:59 PM.Tags: None
Leave a comment: