invalid conversion from int to socklen

烂漫一生 提交于 2019-12-21 12:58:29
问题 Below is my code for Linux. I am implementing a client/server application and below is the server .cpp file. int main() { int serverFd, clientFd, serverLen, clientLen; struct sockaddr_un serverAddress;/* Server address */ struct sockaddr_un clientAddress; /* Client address */ struct sockaddr* serverSockAddrPtr; /* Ptr to server address */ struct sockaddr* clientSockAddrPtr; /* Ptr to client address */ /* Ignore death-of-child signals to prevent zombies */ signal (SIGCHLD, SIG_IGN);

getnameinfo specifies socklen_t

匆匆过客 提交于 2019-12-19 04:08:23
问题 The 2nd arg for the getnameinfo prototype asks for a socklen_t type but sizeof uses size_t. So how can I get socklen_t ? Prototype: int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, char *restrict node, socklen_t nodelen, char *restrict service, socklen_t servicelen, int flags); Example: struct sockaddr_in SIN; memset(&SIN, 0, sizeof(SIN)); // This should also be socklen_t ? SIN.sin_family = AF_INET; SIN.sin_addr.s_addr = inet_addr(IP); SIN.sin_port = 0; getnameinfo((struct

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>