为什么getpeername在Windows下的c中变得不成功 [英] why the getpeername became unsucessful in c under windows
本文介绍了为什么getpeername在Windows下的c中变得不成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的编码:
my coding:
sockaddr *name =new sockaddr();
int *isize;
isize =(int*) sizeof(name);
if( 0 == getpeername(acceptsocket,name,isize))
{
printf("\n\nThe peer sucessfult\n");
printf("%s",name->sa_family);
}
else
{
printf("\nThe peer is unsucessful\n");
}
我创建了简单的tcp客户端和服务器程序.
我想阅读客户信息.所以我尝试使用getpeername()函数..
但产生不成功..
什么是错误...
i created the simple tcp client and server program .
i want to read the client information. so i try to use the getpeername() function..
but it producing unsucessful..
what is the error...
推荐答案
您没有说收到什么错误.但是,您可能会猜到 WSAEFAULT [ ^ ]作为您的namelen值已设置为指针的大小(sizeof(name)
)而不是结构的大小(sizeof(*name)
或sizeof(sockaddr)
).
You do not say what error you are receiving. However, at a guess you may be getting WSAEFAULT[^] as your namelen value has been set to the size of the pointer (sizeof(name)
) rather than the size of the structure (sizeof(*name)
orsizeof(sockaddr)
).
这篇关于为什么getpeername在Windows下的c中变得不成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文