Click here to Skip to main content
15,911,646 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: IP Address of own PC Pin
ashxly10-Sep-03 16:13
ashxly10-Sep-03 16:13 
GeneralRe: IP Address of own PC Pin
R. Thomas10-Sep-03 16:49
R. Thomas10-Sep-03 16:49 
GeneralRe: IP Address of own PC (EDITED) Pin
John M. Drescher10-Sep-03 17:32
John M. Drescher10-Sep-03 17:32 
GeneralRe: IP Address of own PC (EDITED) Pin
R. Thomas10-Sep-03 18:02
R. Thomas10-Sep-03 18:02 
GeneralRe: IP Address of own PC (EDITED) Pin
John M. Drescher10-Sep-03 18:10
John M. Drescher10-Sep-03 18:10 
GeneralRe: IP Address of own PC (EDITED) Pin
John M. Drescher10-Sep-03 18:23
John M. Drescher10-Sep-03 18:23 
GeneralRe: IP Address of own PC (EDITED) Pin
R. Thomas10-Sep-03 18:50
R. Thomas10-Sep-03 18:50 
GeneralRe: IP Address of own PC (EDITED) Pin
John M. Drescher10-Sep-03 19:03
John M. Drescher10-Sep-03 19:03 
It gets very complicated. Any network adapter may have multiple IP addresses. A computer may have more than one network adapters. I am not sure how you can figure out which ip address is the one that is connected to the internet and actually more than one can be connected to the internet.


You can use this code to go through the list of ip addresses:

#include "Winsock2.h"
#pragma comment(lib,"Ws2_32.lib")


int main(int argc, char* argv[])
{

WORD wVersionRequested;
WSADATA wsaData;
int err;
 
wVersionRequested = MAKEWORD( 2, 2 );
 
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
    /* Tell the user that we could not find a usable */
    /* WinSock DLL.                                  */
    return -1;
}

	char host[80];
	gethostname(host,80);
	LPHOSTENT lpHost;
	lpHost = gethostbyname(host);


	for(int i=0;(LPIN_ADDR)lpHost->h_addr_list[i] != 0;i++) {
		UINT ip = ((LPIN_ADDR)lpHost->h_addr_list[i])->s_addr;
		char* addr= inet_ntoa(*(LPIN_ADDR)lpHost->h_addr_list[i]);
	}
	
	return 0;
}


John
GeneralRe: IP Address of own PC (EDITED) Pin
R. Thomas10-Sep-03 19:29
R. Thomas10-Sep-03 19:29 
GeneralRe: IP Address of own PC (EDITED) Pin
John M. Drescher10-Sep-03 19:37
John M. Drescher10-Sep-03 19:37 
GeneralRe: IP Address of own PC (EDITED) Pin
R. Thomas10-Sep-03 19:50
R. Thomas10-Sep-03 19:50 
GeneralRe: IP Address of own PC (EDITED) Pin
Phil Speller10-Sep-03 23:33
Phil Speller10-Sep-03 23:33 
GeneralRe: IP Address of own PC (EDITED) Pin
John M. Drescher11-Sep-03 4:04
John M. Drescher11-Sep-03 4:04 
Questionquestion on OLEDB?? Pin
ashxly10-Sep-03 15:46
ashxly10-Sep-03 15:46 
GeneralNeed some Help -- Kinda of Dense! Pin
Larry J. Siddens10-Sep-03 15:36
Larry J. Siddens10-Sep-03 15:36 
GeneralRe: Need some Help -- Kinda of Dense! Pin
PengFeidu10-Sep-03 20:52
PengFeidu10-Sep-03 20:52 
GeneralRe: Need some Help -- Kinda of Dense! Pin
Larry J. Siddens11-Sep-03 2:56
Larry J. Siddens11-Sep-03 2:56 
GeneralMinimizing Pin
Dov Sherman10-Sep-03 14:38
Dov Sherman10-Sep-03 14:38 
GeneralRe: Minimizing Pin
Michael Dunn10-Sep-03 14:54
sitebuilderMichael Dunn10-Sep-03 14:54 
Questionhow to link dialog to database Pin
coda_x10-Sep-03 14:13
coda_x10-Sep-03 14:13 
AnswerRe: how to link dialog to database Pin
David Crow11-Sep-03 3:05
David Crow11-Sep-03 3:05 
GeneralRe: how to link dialog to database Pin
coda_x11-Sep-03 18:33
coda_x11-Sep-03 18:33 
GeneralRe: how to link dialog to database Pin
David Crow12-Sep-03 2:33
David Crow12-Sep-03 2:33 
GeneralRe: how to link dialog to database Pin
coda_x12-Sep-03 18:00
coda_x12-Sep-03 18:00 
GeneralRe: how to link dialog to database Pin
coda_x12-Sep-03 18:18
coda_x12-Sep-03 18:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.