|
-
January 13th, 2011, 11:32 AM
#1
Variable type
Hello. I just started using WinSock and i was using this guide for creating client:
http://www.codeproject.com/KB/IP/winsockintro02.aspx
Everything seems pretty easy in this guide exept one thing... What type of variable should i use for 'addr'?
Code:
if(inet_addr(servername)==INADDR_NONE)
{
hp=gethostbyname(servername);
}
else
{
addr=inet_addr(servername);
hp=gethostbyaddr((char*)&addr,sizeof(addr),AF_INET);
}
if(hp==NULL)
{
closesocket(conn);
return;
}
Thank you
-
January 13th, 2011, 11:38 AM
#2
-
January 13th, 2011, 11:48 AM
#3
Re: Variable type
I tried this
Code:
const char addr[13] = "192.168.1.65";
hostent *hp = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET);
gethostbyaddr returned 0. Maybe i'm doing something wrong?
-
January 13th, 2011, 12:15 PM
#4
Re: Variable type
Victor Nijegorodov
-
January 13th, 2011, 12:22 PM
#5
Re: Variable type
Yes. I call it at the begining of my code
Code:
WSADATA wsaData;
int wsaret = WSAStartup(0x101, &wsaData);
also, WSAGetLastError returned 11004 - WSANO_DATA
http://msdn.microsoft.com/en-us/library/ms740668
It seems that gethostbyaddr founds addres, but has no data about it? Maybe its because 192.168.1.65 is in my local network?
EDIT
Its same when i changed ip to my gateway ip...
-
January 13th, 2011, 04:16 PM
#6
Re: Variable type
According to http://msdn.microsoft.com/en-us/libr...21(VS.85).aspx gethostbyname is deprecated and getnameinfo should be used instead. In the remarks for getnameinfo, http://msdn.microsoft.com/en-us/libr...(v=VS.85).aspx, the name lookup is described as being either a reverse DNS or local hosts file lookup result i.e. without having a DNS entry or a hosts file entry it will fail. Try using 127.0.0.1 instead and you probably will get localhost as the result
-
January 13th, 2011, 04:31 PM
#7
Re: Variable type
inet_addr returns an unsigned long value.
-
January 13th, 2011, 05:05 PM
#8
Re: Variable type
 Originally Posted by itsmeandnobodyelse
inet_addr returns an unsigned long value.
First param to gethostbyaddr should be 'A pointer to an address in network byte order' and that's what inet_addr returns so that should be alright.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|