IP address of a machine

Hello !
Is there a way to determine IP-address of current machine I’m working on …?
in kernel or user mode


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Hi,
In user mode you can use the windows sockets API gethostbyname

Clark
----- Original Message -----
From: foxgen
To: NT Developers Interest List
Sent: Wednesday, November 28, 2001 2:30 PM
Subject: [ntdev] IP address of a machine

Hello !
Is there a way to determine IP-address of current machine I’m working on …?
in kernel or user mode

You are currently subscribed to ntdev as: xxxxx@yahoo.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

You can use TDI(Transport Driver Interface) from kernel, there’s some
macros to build irp’s like TdiBuildQueryInformation, you can set to this
macro an argument TDI_QUERY_ADDRESS_INFO to obtain desired info. There’s
full description in DDK.

Cheers,
Sebastian Slezak
Mikronika, Poland


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

#include <winsock2.h>

//
// Get this computer IP address (Winsock must be already initialized)
//
BOOL GetThisIPAddress( LPTSTR pszIP, int nMax, LPTSTR pszError/=NULL/, int
nErrorMax/=-1/ )
{
char szHostName[512];

try
{
pszIP = _T(‘\0’);

// Get this computer name
if( gethostname( szHostName, sizeof(szHostName)-1) != SOCKET_ERROR )
{
//
// Get host entry
//

HOSTENT
pHostEntry = gethostbyname( szHostName );

if( pHostEntry != NULL )
{
//
// Get IP address
//

in_addr aInAddr;

memcpy( &aInAddr, pHostEntry -> h_addr_list[0], sizeof(aInAddr));

const char* pszSrvIP = inet_ntoa( aInAddr );

if( pszSrvIP )
{
_tcsncpy( pszIP, pszSrvIP, nMax );

return TRUE;
}
else if( pszError != NULL )
{
_tcsncpy( pszError, _T(“Cannot convert inet address into string.”),
nErrorMax );
}
}
else if( pszError != NULL )
{
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, (ULONG)WSAGetLastError(), MAKELANGID(LANG_NEUTRAL,
SUBLANG_DEFAULT),
pszError, nErrorMax, NULL );
}
}
else if( pszError != NULL )
{
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, (ULONG)WSAGetLastError(), MAKELANGID(LANG_NEUTRAL,
SUBLANG_DEFAULT),
pszError, nErrorMax, NULL );
}
}
catch( … )
{
if( pszError != NULL )
{
_tcsncpy( pszError, _T(“Exception has occurred.”), nErrorMax );
}
}

return FALSE;
}

-----Original Message-----
From: foxgen [mailto:xxxxx@yandex.ru]
Sent: Wednesday, November 28, 2001 1:01 AM
To: NT Developers Interest List
Subject: [ntdev] IP address of a machine

Hello !
Is there a way to determine IP-address of current machine I’m working on
…?
in kernel or user mode

You are currently subscribed to ntdev as: xxxxx@Starbase.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com</winsock2.h>

xxxxx@yandex.ru said:

Is there a way to determine IP-address of current machine I’m working
on …? i

That question doesn’t always have an obvious meaning, as a computer
can have multiple network interfaces, each with its own IP address.


Steve Williams “The woods are lovely, dark and deep.
steve at icarus.com But I have promises to keep,
steve at picturel.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep.”


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

You can retrieve all of an adapters associated IP addresses in user mode using the IP helper library functions (if the OS has IPHLPAPI.DLL installed), by enumerating the entries returned by a call to GetIpAddrTable…

Ed Lau

MidCore Software, Inc.
900 Straits Tpke
Middlebury, CT 06762

www.midcore.com

----- Original Message -----
From: Stephen Williams
To: NT Developers Interest List
Sent: Wednesday, November 28, 2001 12:31 PM
Subject: [ntdev] Re: IP address of a machine

xxxxx@yandex.ru said:

Is there a way to determine IP-address of current machine I’m working
on …? i

That question doesn’t always have an obvious meaning, as a computer
can have multiple network interfaces, each with its own IP address.


Steve Williams “The woods are lovely, dark and deep.
steve at icarus.com But I have promises to keep,
steve at picturel.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep.”


You are currently subscribed to ntdev as: xxxxx@midcore.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

On top of that, there are static and dynamic IP’s (NAT, DHCP,…).


Get your own “800” number
Voicemail, fax, email, and a lot more
http://www.ureach.com/reg/tag

---- On Wed, 28 Nov 2001, Stephen Williams (xxxxx@icarus.com) wrote:

xxxxx@yandex.ru said:
> Is there a way to determine IP-address of current machine I’m working
> on …? i

That question doesn’t always have an obvious meaning, as a computer
can have multiple network interfaces, each with its own IP address.


Steve Williams “The woods are lovely, dark and deep.
steve at icarus.com But I have promises to keep,
steve at picturel.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep.”


You are currently subscribed to ntdev as: xxxxx@ureach.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Try these sites:

http://members.tripod.com/~staskh/

http://www.cyberport.com/~tangent/winsock/examples

http:
http://www.codeguru.com/mfc/comments/21308.shtml

Adam

-----Original Message-----
From: Chtchetkine, Vladimir [mailto:xxxxx@Starbase.com]
Sent: Wednesday, November 28, 2001 8:54 AM
To: NT Developers Interest List
Subject: [ntdev] RE: IP address of a machine

#include <winsock2.h>

//
// Get this computer IP address (Winsock must be already initialized)
//
BOOL GetThisIPAddress( LPTSTR pszIP, int nMax, LPTSTR pszError/=NULL/, int
nErrorMax/=-1/ )
{
char szHostName[512];

try
{
pszIP = _T(‘\0’);

// Get this computer name
if( gethostname( szHostName, sizeof(szHostName)-1) != SOCKET_ERROR )
{
//
// Get host entry
//

HOSTENT
pHostEntry = gethostbyname( szHostName );

if( pHostEntry != NULL )
{
//
// Get IP address
//

in_addr aInAddr;

memcpy( &aInAddr, pHostEntry -> h_addr_list[0], sizeof(aInAddr));

const char* pszSrvIP = inet_ntoa( aInAddr );

if( pszSrvIP )
{
_tcsncpy( pszIP, pszSrvIP, nMax );

return TRUE;
}
else if( pszError != NULL )
{
_tcsncpy( pszError, _T(“Cannot convert inet address into string.”),
nErrorMax );
}
}
else if( pszError != NULL )
{
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, (ULONG)WSAGetLastError(), MAKELANGID(LANG_NEUTRAL,
SUBLANG_DEFAULT),
pszError, nErrorMax, NULL );
}
}
else if( pszError != NULL )
{
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, (ULONG)WSAGetLastError(), MAKELANGID(LANG_NEUTRAL,
SUBLANG_DEFAULT),
pszError, nErrorMax, NULL );
}
}
catch( … )
{
if( pszError != NULL )
{
_tcsncpy( pszError, _T(“Exception has occurred.”), nErrorMax );
}
}

return FALSE;
}

-----Original Message-----
From: foxgen [mailto:xxxxx@yandex.ru]
Sent: Wednesday, November 28, 2001 1:01 AM
To: NT Developers Interest List
Subject: [ntdev] IP address of a machine

Hello !
Is there a way to determine IP-address of current machine I’m working on
…?
in kernel or user mode

You are currently subscribed to ntdev as: xxxxx@Starbase.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@efficient.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com</winsock2.h></http:>

> ----------

From: xxxxx@icarus.com[SMTP:xxxxx@icarus.com]
Reply To: xxxxx@lists.osr.com
Sent: Wednesday, November 28, 2001 6:31 PM
To: xxxxx@lists.osr.com
Subject: [ntdev] Re: IP address of a machine

xxxxx@yandex.ru said:
> Is there a way to determine IP-address of current machine I’m working
> on …? i

That question doesn’t always have an obvious meaning, as a computer
can have multiple network interfaces, each with its own IP address.

To make things even more confusing, a single adapter can have more IP
addresses.

Best regards,

Michal Vodicka
STMicroelectronics Design and Application s.r.o.
[michal.vodicka@st.com, http:://www.st.com]


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com