error C2065: 'socklen_t' : undeclared identifier

大城市里の小女人 提交于 2019-12-08 06:17:02

问题


The whole error is:

Error   1   error C2065: 'socklen_t' : undeclared identifier    c:\users\richard\documents\visual studio 2010\projects\server\server\server.cpp 41  1   Server

This is the problematic line:

int iRcvdBytes=recvfrom(iSockFd, buff, 1024000, 0, (struct sockaddr*)&cliAddr, (socklen_t*)&cliAddrLen);

I have these headers included:

#include <winsock2.h>
#include <windows.h>

#include <direct.h>
#include <stdlib.h>
#include <stdio.h>

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

I have also added WS2_32.lib to the linker in Visual Studio 2010.

What else could cause this problem? I'm just trying to rewrite my simple UDP program to work under Windows.


回答1:


The socklen_t type is defined inside of WS2tcpip.h in windows. This is not transitively included from winsock2.h (AFAICT). You'll need to include WS2tcpip.h manually in order to use the socklen_t type.




回答2:


Visual Studio can't find the type socklen_t. MSDN says that this function takes an int* as the last parameter, so cast to that.



来源:https://stackoverflow.com/questions/4453992/error-c2065-socklen-t-undeclared-identifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!