I'm trying to enumerate all the IP addresses on a machine.
The problem is that when I get the pointer to the list of all the ip's I can't increase it. When I increase the pointer with 4 bytes the pointer is refering to an invalid address.
Code I use :
#COMPILE EXE
#DIM ALL
#INCLUDE "WIN32API.INC"
#INCLUDE "WSOCK32.INC"
DECLARE FUNCTION StartWinsock()AS LONG
FUNCTION PBMAIN()
DIM winsck AS LONG
DIM Hostname AS ASCIIZ * 80
DIM ptrAsciiz AS ASCIIZ PTR
DIM ErrNumber AS LONG
DIM hstEnt AS hostentStru PTR
DIM varADDR AS in_addr
winsck = StartWinsock()
IF winsck <> 0 THEN
MSGBOX "Error on opening winsock. Error number: " + STR$(winsck)
CALL wsacleanup()
EXIT FUNCTION
END IF
IF (gethostname(Hostname, SIZEOF(Hostname)) = %SOCKET_ERROR) THEN
ErrNumber = WSAGetLastError()
MSGBOX "Error on getting local hostname. Error number: " + STR$(ErrNumber)
CALL wsacleanup()
EXIT FUNCTION
END IF
MSGBOX "The local hostname is: " + hostname
hstEnt = gethostbyname(hostname)
IF hstent = 0 THEN
MSGBOX "Error on host lookup."
CALL wsacleanup()
EXIT FUNCTION
END IF
'-------- Here the enum has to start. Currently I can only
'-------- retrieve 1 address
'-------- C checks if pointer = 0
' FOR (INT i = 0; phe->h_addr_list[i] != 0; ++i) {
' struct in_addr ADDR;
' memcpy(&addr, phe->h_addr_list[i], SIZEOF(struct n_addr));
' cout << "Address " << i << ": " << inet_ntoa(ADDR) << endl;
' }
varADDR.s_addr = @[email protected]@h_list
ptrAsciiz = inet_ntoa(varADDR.s_addr)
MSGBOX " Your IP adress is : " + @ptrAsciiz
CALL wsacleanup()
END FUNCTION
FUNCTION StartWinsock()AS LONG
DIM wsaData AS WSAData
DIM lngReturn AS LONG
lngReturn = wsastartup(257,wsaData)
FUNCTION = lngReturn
END FUNCTION
Anybody who know how to check if the pointer reference is 0 (null) ?
Thanks
The problem is that when I get the pointer to the list of all the ip's I can't increase it. When I increase the pointer with 4 bytes the pointer is refering to an invalid address.
Code I use :
#COMPILE EXE
#DIM ALL
#INCLUDE "WIN32API.INC"
#INCLUDE "WSOCK32.INC"
DECLARE FUNCTION StartWinsock()AS LONG
FUNCTION PBMAIN()
DIM winsck AS LONG
DIM Hostname AS ASCIIZ * 80
DIM ptrAsciiz AS ASCIIZ PTR
DIM ErrNumber AS LONG
DIM hstEnt AS hostentStru PTR
DIM varADDR AS in_addr
winsck = StartWinsock()
IF winsck <> 0 THEN
MSGBOX "Error on opening winsock. Error number: " + STR$(winsck)
CALL wsacleanup()
EXIT FUNCTION
END IF
IF (gethostname(Hostname, SIZEOF(Hostname)) = %SOCKET_ERROR) THEN
ErrNumber = WSAGetLastError()
MSGBOX "Error on getting local hostname. Error number: " + STR$(ErrNumber)
CALL wsacleanup()
EXIT FUNCTION
END IF
MSGBOX "The local hostname is: " + hostname
hstEnt = gethostbyname(hostname)
IF hstent = 0 THEN
MSGBOX "Error on host lookup."
CALL wsacleanup()
EXIT FUNCTION
END IF
'-------- Here the enum has to start. Currently I can only
'-------- retrieve 1 address
'-------- C checks if pointer = 0
' FOR (INT i = 0; phe->h_addr_list[i] != 0; ++i) {
' struct in_addr ADDR;
' memcpy(&addr, phe->h_addr_list[i], SIZEOF(struct n_addr));
' cout << "Address " << i << ": " << inet_ntoa(ADDR) << endl;
' }
varADDR.s_addr = @[email protected]@h_list
ptrAsciiz = inet_ntoa(varADDR.s_addr)
MSGBOX " Your IP adress is : " + @ptrAsciiz
CALL wsacleanup()
END FUNCTION
FUNCTION StartWinsock()AS LONG
DIM wsaData AS WSAData
DIM lngReturn AS LONG
lngReturn = wsastartup(257,wsaData)
FUNCTION = lngReturn
END FUNCTION
Anybody who know how to check if the pointer reference is 0 (null) ?
Thanks
Comment