Click here to Skip to main content
15,923,051 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questiongethostname() function returns errror Pin
Anu_Bala18-Sep-08 1:38
Anu_Bala18-Sep-08 1:38 
I have used the below code to determine the Host Name of the local machine in which the application is running. gethostname() function returns SOCKET_ERROR. The same code works fine in another application. Pls tell me why it is not working in my application. Should I change any Project settings.

SOCKADDR_IN sockAddr;
memset(&sockAddr,0,sizeof(sockAddr));
CString rSocketAddress;
LPHOSTENT lphost;
char HostName[80];

if (gethostname(HostName, sizeof(HostName)) == SOCKET_ERROR)
{
AfxMessageBox(WSAGetLastError());
PostQuitMessage(WM_QUIT);
}
//_tcscpy(mInstSess[ind].INSHost,HostName);
m_sInsHost = HostName;

lphost = gethostbyname(HostName);
if (lphost != NULL)
{
sockAddr.sin_addr.s_addr = ((LPIN_ADDR)lphost->h_addr)->s_addr;
rSocketAddress = inet_ntoa(sockAddr.sin_addr);
//strcpy(mInstSess[ind].INSIP,rSocketAddress);
m_sInsIP = rSocketAddress;
}



Thanks in advance

Anusuya

Anu

AnswerRe: gethostname() function returns errror Pin
Roger Stoltz18-Sep-08 1:55
Roger Stoltz18-Sep-08 1:55 
GeneralRe: gethostname() function returns errror Pin
Anu_Bala18-Sep-08 2:11
Anu_Bala18-Sep-08 2:11 
GeneralRe: gethostname() function returns errror Pin
Rajesh R Subramanian18-Sep-08 2:27
professionalRajesh R Subramanian18-Sep-08 2:27 
AnswerRe: gethostname() function returns errror Pin
Roger Stoltz18-Sep-08 2:36
Roger Stoltz18-Sep-08 2:36 
AnswerRe: gethostname() function returns errror Pin
Rajesh R Subramanian18-Sep-08 2:25
professionalRajesh R Subramanian18-Sep-08 2:25 
AnswerRe: gethostname() function returns errror Pin
Varghese Paul M18-Sep-08 5:14
Varghese Paul M18-Sep-08 5:14 
QuestionHow to find the number of files in a folder Pin
Deepu Antony18-Sep-08 1:31
Deepu Antony18-Sep-08 1:31 
AnswerRe: How to find the number of files in a folder Pin
Hamid_RT18-Sep-08 1:50
Hamid_RT18-Sep-08 1:50 
GeneralRe: How to find the number of files in a folder Pin
Deepu Antony18-Sep-08 2:04
Deepu Antony18-Sep-08 2:04 
GeneralRe: How to find the number of files in a folder Pin
Hamid_RT18-Sep-08 2:07
Hamid_RT18-Sep-08 2:07 
GeneralRe: How to find the number of files in a folder Pin
Deepu Antony18-Sep-08 3:15
Deepu Antony18-Sep-08 3:15 
GeneralRe: How to find the number of files in a folder Pin
David Crow18-Sep-08 3:35
David Crow18-Sep-08 3:35 
GeneralRe: How to find the number of files in a folder Pin
Deepu Antony18-Sep-08 4:42
Deepu Antony18-Sep-08 4:42 
GeneralRe: How to find the number of files in a folder Pin
David Crow18-Sep-08 5:18
David Crow18-Sep-08 5:18 
GeneralRe: How to find the number of files in a folder Pin
Joe Woodbury18-Sep-08 8:43
professionalJoe Woodbury18-Sep-08 8:43 
GeneralRe: How to find the number of files in a folder Pin
David Crow18-Sep-08 8:56
David Crow18-Sep-08 8:56 
GeneralRe: How to find the number of files in a folder Pin
Joe Woodbury18-Sep-08 10:38
professionalJoe Woodbury18-Sep-08 10:38 
AnswerRe: How to find the number of files in a folder Pin
Michael Schubert18-Sep-08 1:52
Michael Schubert18-Sep-08 1:52 
QuestionBitmap drawn via BitBlt not visible over Remote Desktop (WinXP) Pin
JuriB18-Sep-08 1:27
JuriB18-Sep-08 1:27 
QuestionRe: Bitmap drawn via BitBlt not visible over Remote Desktop (WinXP) Pin
Mark Salsbery18-Sep-08 4:01
Mark Salsbery18-Sep-08 4:01 
AnswerRe: Bitmap drawn via BitBlt not visible over Remote Desktop (WinXP) Pin
JuriB18-Sep-08 4:23
JuriB18-Sep-08 4:23 
QuestionRe: Bitmap drawn via BitBlt not visible over Remote Desktop (WinXP) Pin
Mark Salsbery18-Sep-08 4:44
Mark Salsbery18-Sep-08 4:44 
AnswerRe: Bitmap drawn via BitBlt not visible over Remote Desktop (WinXP) [modified] Pin
JuriB18-Sep-08 5:18
JuriB18-Sep-08 5:18 
GeneralRe: Bitmap drawn via BitBlt not visible over Remote Desktop (WinXP) Pin
Mark Salsbery18-Sep-08 5:43
Mark Salsbery18-Sep-08 5:43 

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.