getting ip address of local host
-
hi all i am able to get the ip address of local host using gethostname() and gethostbyname() functions. but it is not working in Windows 95. it says WSAHOST_NOT_FOUND. if i given value of hostname in gethostbyname function as Win95 m/c's name and i run it in Win98, its fetching the IP address perfectly(Win95 m/c ip address). i don't know why its not fetching in Win95? these system are all DHCP configured. please get me if u have any idea Thanks in advance. regards Halid
-
hi all i am able to get the ip address of local host using gethostname() and gethostbyname() functions. but it is not working in Windows 95. it says WSAHOST_NOT_FOUND. if i given value of hostname in gethostbyname function as Win95 m/c's name and i run it in Win98, its fetching the IP address perfectly(Win95 m/c ip address). i don't know why its not fetching in Win95? these system are all DHCP configured. please get me if u have any idea Thanks in advance. regards Halid
(Just a guess) Have you previously initialized Winsock with
WSAStartup
? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
(Just a guess) Have you previously initialized Winsock with
WSAStartup
? Joaquín M López Muñoz Telefónica, Investigación y Desarrollohi, i initialized Winsock by using WSAStartup function. i am able to get the IP address in 98/NT systems. but its not woking in Win95. i don't know the problem why its not working in Win95. any suggestions. regards Halid
-
hi, i initialized Winsock by using WSAStartup function. i am able to get the IP address in 98/NT systems. but its not woking in Win95. i don't know the problem why its not working in Win95. any suggestions. regards Halid
Well, you can pass NULL to
gethostbyname
if it's the local machine IP what you're after, but that would only mask your problem. What version of Winsock are you using? If it is 2.0, how did you do the upgrade? (95 comes with 1.1 by default) Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
Well, you can pass NULL to
gethostbyname
if it's the local machine IP what you're after, but that would only mask your problem. What version of Winsock are you using? If it is 2.0, how did you do the upgrade? (95 comes with 1.1 by default) Joaquín M López Muñoz Telefónica, Investigación y Desarrollohi this is my code to fetch the ip address of local host. CString hname, IPAddress; IPAddress.Empty(); WSADATA WSAData; if(WSAStartup(MAKEWORD(1,1), &WSAData) != 0) { // MessageBox("Sockets unInitialized ","Server Sockets", MB_OK); return ; } char hostname[250]; /* SOCKADDR_IN sin; sin.sin_family = AF_INET; sin.sin_port = 5000;*/ memset(hostname,'\0',sizeof(hostname)); if( gethostname(hostname,sizeof(hostname)) == SOCKET_ERROR) { // MessageBox(" Error getting host name","Server Sockets", MB_OK); return ; } AfxMessageBox(hostname); PHOSTENT phe; phe = gethostbyname(hostname); CString s; struct in_addr *inaddr; // AfxMessageBox(phe->h_name ); inaddr = (struct in_addr *)phe->h_addr_list[0]; int a = inaddr->S_un.S_un_b.s_b1; int b = inaddr->S_un.S_un_b.s_b2; int c = inaddr->S_un.S_un_b.s_b3; int d = inaddr->S_un.S_un_b.s_b4; IPAddress.Format("%d.%d.%d.%d",a,b,c,d); AfxMessageBox(IPAddress); } how do i upgrade Winsock 1.1 to Winsock 2.0. i'll try with hostname as NULL. Thanks for your suggestion. but reply me if you find any other method regards Halid
-
hi this is my code to fetch the ip address of local host. CString hname, IPAddress; IPAddress.Empty(); WSADATA WSAData; if(WSAStartup(MAKEWORD(1,1), &WSAData) != 0) { // MessageBox("Sockets unInitialized ","Server Sockets", MB_OK); return ; } char hostname[250]; /* SOCKADDR_IN sin; sin.sin_family = AF_INET; sin.sin_port = 5000;*/ memset(hostname,'\0',sizeof(hostname)); if( gethostname(hostname,sizeof(hostname)) == SOCKET_ERROR) { // MessageBox(" Error getting host name","Server Sockets", MB_OK); return ; } AfxMessageBox(hostname); PHOSTENT phe; phe = gethostbyname(hostname); CString s; struct in_addr *inaddr; // AfxMessageBox(phe->h_name ); inaddr = (struct in_addr *)phe->h_addr_list[0]; int a = inaddr->S_un.S_un_b.s_b1; int b = inaddr->S_un.S_un_b.s_b2; int c = inaddr->S_un.S_un_b.s_b3; int d = inaddr->S_un.S_un_b.s_b4; IPAddress.Format("%d.%d.%d.%d",a,b,c,d); AfxMessageBox(IPAddress); } how do i upgrade Winsock 1.1 to Winsock 2.0. i'll try with hostname as NULL. Thanks for your suggestion. but reply me if you find any other method regards Halid
Your code seems OK to me (I compiled and ran it in a 95 box without problems). I'd say probably your network settings are misconfigured, or it could be a problem with DHCP. I suggest to try the following tests:
- Record the name returned by
gethostname
and issue aping
to that name from the command line. It it fails then something's be wrong with your network settings. - Run
winipcfg
from the command line and check that your machine has been given an IP from the DHCP server. If it is not, then that could be the cause of the problem: in that case, try clicking on "Renew all" and running your program again. - Just for testing purposes, disable momentarily DHCP on your 95 machine and assign it some fixed IP instead. Run your program to see what happens.
You can follow this link to Windows Socket 2 Update for Windows 95. I don't think your problem will solve with the upgrade, though. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
- Record the name returned by
-
Your code seems OK to me (I compiled and ran it in a 95 box without problems). I'd say probably your network settings are misconfigured, or it could be a problem with DHCP. I suggest to try the following tests:
- Record the name returned by
gethostname
and issue aping
to that name from the command line. It it fails then something's be wrong with your network settings. - Run
winipcfg
from the command line and check that your machine has been given an IP from the DHCP server. If it is not, then that could be the cause of the problem: in that case, try clicking on "Renew all" and running your program again. - Just for testing purposes, disable momentarily DHCP on your 95 machine and assign it some fixed IP instead. Run your program to see what happens.
You can follow this link to Windows Socket 2 Update for Windows 95. I don't think your problem will solve with the upgrade, though. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Thanks for your suggestion. i have tried out all the options what you mentioned in message. In winipcfg, it shows the full details of that machine, including IP,DHCP server IP,MAC address and etc., if i run this code in 98/NT machine with hostname as Win95 machine's name, it shows the IP address of Win95 machine perfectly. In gethostbyname function, i given "www.google.com" it shows the IP address of Google webserver, i ran this it in Win98. the same code is not running in Win95. for all the values it says "WSAHOST_NOT_FOUND" error. i have passed NULL value in gethostbyname, still its giving this error only. Pls, i need help from u. regards Halid
- Record the name returned by
-
Thanks for your suggestion. i have tried out all the options what you mentioned in message. In winipcfg, it shows the full details of that machine, including IP,DHCP server IP,MAC address and etc., if i run this code in 98/NT machine with hostname as Win95 machine's name, it shows the IP address of Win95 machine perfectly. In gethostbyname function, i given "www.google.com" it shows the IP address of Google webserver, i ran this it in Win98. the same code is not running in Win95. for all the values it says "WSAHOST_NOT_FOUND" error. i have passed NULL value in gethostbyname, still its giving this error only. Pls, i need help from u. regards Halid
I cannot think of much more to do... You might want to prepare a complete project for downloading and post the link here so that people can take a look at it and determine what's going wrong. Also, have you tried running your program on a different 95 machine? Sorry I couldn't be of more help. Regards, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
I cannot think of much more to do... You might want to prepare a complete project for downloading and post the link here so that people can take a look at it and determine what's going wrong. Also, have you tried running your program on a different 95 machine? Sorry I couldn't be of more help. Regards, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
hi Thanks for your suggestion. i got one source code for fetching NIC informations using SNMP. i tested that exe in Win95 its reading IP addresses and other informations perfectly. once again thanks for your suggestion. pls, give your mail id, so that i can contact if i have any problems. regards Halid