Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / IP Address Problem

Author
Message
Bighead
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location:
Posted: 4th Jan 2003 15:53
Does anybody know how to get the IP Address of a server/host with DBPro using "ws2_32.dll"? (or any other dll)
levent
21
Years of Service
User Offline
Joined: 2nd Nov 2002
Location: United States
Posted: 5th Jan 2003 03:28
Here is an extract in C that might help you:


......................
#include <winsock2.h>

Link with Wsock32.lib
....................
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
CString ip;
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 2, 0 );

if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{

if( gethostname ( name, sizeof(name)) == 0)
{
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
}
}

WSACleanup( );
}
}
Bighead
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location:
Posted: 5th Jan 2003 04:10
Thx for the info, but what I want to know is whether there ia a way to use the dll commands in DBPro to directly emulate that (I mean without using C or other language) ...

Having loaded the dll, when I use a sentence like:
, DBP displays a 16-char number that seems to be a pointer to somewhere, perhaps the HOSTENT. The number is like, in my case, say: "5340448251969366" for "127.0.0.1".

The funny thing is that when I want to store that "number" in an integer variable and then display it, the result is "-1". When I use a floating the result is "-1.#QNAN", and when I finally use a string one, DBP crashes.

Any ideas?
MrTAToad
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 5th Jan 2003 15:32
Have you tried DOUBLE INTEGER ?

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 5th Jan 2003 22:43
It is actually returning an integer and not a double integer - the -1 tells you that the call failed for some reason.

I'm having a look now, and will give you a result tomorrow evening sometime ... at least I hope so
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 6th Jan 2003 00:13
Well, it actually turned out to be not too difficult, just a bit long winded.

Bighead
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location:
Posted: 6th Jan 2003 09:51
Nice coding! Thanks ... [img][/img]

Login to post a reply

Server time is: 2024-05-17 04:40:58
Your offset time is: 2024-05-17 04:40:58