原文地址:http://blog.sina.com.cn/s/blog_4880c4bb0100b6a5.html
WSAGetLastError()函数返回结果与对照表:
Windows Sockets code Error Description
------------------------------------------------------------------------
WSAEINTR 10004 Interrupted system call.系统调用已中断
WSAEBADF 10009 Bad file number.不良档案
WSEACCES 10013 Permission denied.许可被拒绝
WSAEFAULT 10014 Bad address.错误处理
WSAEINVAL 10022 Invalid argument.无效的论点
WSAEMFILE 10024 Too many open files.文件打开太多
WSAEWOULDBLOCK 10035 Operation would block.操作阻塞
WSAEINPROGRESS 10036 Operation now in progress. This error is
returned if any Windows Sockets API
function is called while a blocking
function is in progress.
WSAEALREADY 10037 Operation already in progress.行动已经取得进展
WSAENOTSOCK 10038 Socket operation on nonsocket.套接字操作没有接口
WSAEDESTADDRREQ 10039 Destination address required.需要目标地址
WSAEMSGSIZE 10040 Message too long.
WSAEPROTOTYPE 10041 Protocol wrong type for socket.协议类型错误的接口
WSAENOPROTOOPT 10042 Protocol not available.协议书不存在
WSAEPROTONOSUPPORT 10043 Protocol not supported.不支持的协议
WSAESOCKTNOSUPPORT 10044 Socket type not supported.不支持的接口类型
WSAEOPNOTSUPP 10045 Operation not supported on socket.接口不支持的动作
WSAEPFNOSUPPORT 10046 Protocol family not supported.不支持的协议簇
WSAEAFNOSUPPORT 10047 Address family not supported by protocol
family.
WSAEADDRINUSE 10048 Address already in use.地址已在使用中
WSAEADDRNOTAVAIL 10049 Cannot assign requested address.
WSAENETDOWN 10050 Network is down. This error may be
reported at any time if the Windows
Sockets implementation detects an
underlying failure.
WSAENETUNREACH 10051 Network is unreachable.
WSAENETRESET 10052 Network dropped connection on reset.
WSAECONNABORTED 10053 Software caused connection abort.
WSAECONNRESET 10054 Connection reset by peer.
WSAENOBUFS 10055 No buffer space available.
WSAEISCONN 10056 Socket is already connected.
WSAENOTCONN 10057 Socket is not connected.接口没有连接成功
WSAESHUTDOWN 10058 Cannot send after socket shutdown.接口断开,不能发送
WSAETOOMANYREFS 10059 Too many references: cannot splice.
WSAETIMEDOUT 10060 Connection timed out.
WSAECONNREFUSED 10061 Connection refused.
WSAELOOP 10062 Too many levels of symbolic links.
WSAENAMETOOLONG 10063 File name too long.
WSAEHOSTDOWN 10064 Host is down.
WSAEHOSTUNREACH 10065 No route to host.
WSASYSNOTREADY 10091 Returned by WSAStartup(), indicating that
the network subsystem is unusable.
WSAVERNOTSUPPORTED 10092 Returned by WSAStartup(), indicating that
the Windows Sockets DLL cannot support
this application.
WSANOTINITIALISED 10093 Winsock not initialized. This message is
returned by any function except
WSAStartup(), indicating that a
successful WSAStartup() has not yet been
performed.
WSAEDISCON 10101 Disconnect.
WSAHOST_NOT_FOUND 11001 Host not found. This message indicates
that the key (name, address, and so on)
was not found.——找不到主机。关键(姓名,地址,等等)没有找到。
WSATRY_AGAIN 11002 Nonauthoritative host not found. This
error may suggest that the name service
itself is not functioning.
WSANO_RECOVERY 11003 Nonrecoverable error. This error may
suggest that the name service itself is
not functioning.
WSANO_DATA 11004 Valid name, no data record of requested
type. This error indicates that the key
(name, address, and so on) was not found.
个人总结:
windows下socket编程,socket创建前需要设置WSAStartup();close后,需要WSACleanup(),但是linux下不需要。windows下会报出10093 GetLastError()的错误。
windows下socket编程,
struct sockaddr_in localsin;
memset(&localsin, 0, sizeof(localsin));
localsin.sin_family = AF_INET;
//localsin.sin_addr.s_addr = htonl(localipaddr);//windows下不能设置本地ip,只需要写为0就可以了。但是linux下需要的。
//若设置了本地ip,windows下会报出10049的GetLastError()的错误。
localsin.sin_addr.S_un.S_addr = htonl(0);