大部分代码都是从MSDN上复制下来的~~编译后有100多个错~~~帮忙看下
#include "ws2tcpip.h"
#include<Winsock2.h>
void main()
{WORD wVersionRequested;
WSADATA wsaData;
int err;
 
wVersionRequested = MAKEWORD( 2, 2 );
 
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
    /* Tell the user that we could not find a usable */
    /* WinSock DLL.                                  */
    return;
}
 
/* Confirm that the WinSock DLL supports 2.2.*/
/* Note that if the DLL supports versions greater    */
/* than 2.2 in addition to 2.2, it will still return */
/* 2.2 in wVersion since that is the version we      */
/* requested.                                        */
 
if ( LOBYTE( wsaData.wVersion ) != 2 ||
        HIBYTE( wsaData.wVersion ) != 2 ) {
    /* Tell the user that we could not find a usable */
    /* WinSock DLL.                                  */
    WSACleanup( );
    return; 
}
char *ip="127.0.0.1";
char *port="6000";
addrinfo hints;
addrinfo *ailist=NULL;
hints.ai_family=AF_INET;
hints.ai_protocol=IPPROTO_TCP;
hints.ai_socktype=SOCK_STREAM;
getaddrinfo(ip,port,&hints,&ailist);}
只复制了部分报错的内容:其余的类似,各位给点整改意见~谢了
1>c:\users\joshua.lee\documents\visual studio 2005\projects\myid\myid\ws2tcpip.h(29) : error C2079: “ip_mreq::imr_multiaddr”使用未定义的 struct“in_addr”
1>c:\users\joshua.lee\documents\visual studio 2005\projects\myid\myid\ws2tcpip.h(30) : error C2079: “ip_mreq::imr_interface”使用未定义的 struct“in_addr”
1>c:\users\joshua.lee\documents\visual studio 2005\projects\myid\myid\ws2tcpip.h(38) : error C2079: “ip_mreq_source::imr_multiaddr”使用未定义的 struct“in_addr”
1>c:\users\joshua.lee\documents\visual studio 2005\projects\myid\myid\ws2tcpip.h(39) : error C2079: “ip_mreq_source::imr_sourceaddr”使用未定义的 struct“in_addr”
1>c:\users\joshua.lee\documents\visual studio 2005\projects\myid\myid\ws2tcpip.h(40) : error C2079: “ip_mreq_source::imr_interface”使用未定义的 struct“in_addr”
1>c:\users\joshua.lee\documents\visual studio 2005\projects\myid\myid\ws2tcpip.h(46) : error C2079: “ip_msfilter::imsf_multiaddr”使用未定义的 struct“in_addr”
1>c:\users\joshua.lee\documents\visual studio 2005\projects\myid\myid\ws2tcpip.h(47) : error C2079: “ip_msfilter::imsf_interface”使用未定义的 struct“in_addr”
1>c:\users\joshua.lee\documents\visual studio 2005\projects\myid\myid\ws2tcpip.h(48) : error C2146: 语法错误 : 缺少“;”(在标识符“imsf_fmode”的前面)
1>c:\users\joshua.lee\documents\visual studio 2005\projects\myid\myid\ws2tcpip.h(48) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\joshua.lee\documents\visual studio 2005\projects\myid\myid\ws2tcpip.h(48) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\joshua.lee\documents\visual studio 2005\projects\myid\myid\ws2tcpip.h(49) : error C2146: 语法错误 : 缺少“;”(在标识符“imsf_numsrc”的前面)

解决方案 »

  1.   

    加个#pragma comment(lib,"Ws2_32.lib")看错误会不会少点~~
      

  2.   

    #include <WS2tcpip.h>
    #include <winsock2.h>
    这两个文件都定义了ip_mreq_source,所以出现了重复定义结构的错误,冲突了.
      

  3.   

    #include "stdafx.h"
    #include <iostream>
    #include <stdio.h>
    #include <WinSock2.h>
    #include <Windows.h>
    #pragma comment(lib,"ws2_32.lib")
    using namespace std;BOOL InitWinsock();struct addrinfo
    {  
    int ai_flags;  
    int ai_family;  
    int ai_socktype;  
    int ai_protocol;  
    size_t ai_addrlen;  
    TCHAR* ai_canonname;  
    struct sockaddr_in* ai_addr;  
    struct addrinfo* ai_next;
    };
    int _tmain() 
    {
    InitWinsock();

        sockaddr_in server;
        server.sin_family=AF_INET;
        server.sin_port=htons(8015);                      
        server.sin_addr.s_addr=inet_addr("127.0.0.1");    

        addrinfo aiHints;
        addrinfo *aiList = NULL;    memset(&aiHints, 0, sizeof(aiHints));
        aiHints.ai_socktype = SOCK_STREAM;
        aiHints.ai_protocol = IPPROTO_TCP;
        cout << "aiHints.ai_family :"    << aiHints.ai_flags    << endl;
        cout << "aiHints.ai_protocol:"   << aiHints.ai_protocol << endl;
        cout << "aiHints.ai_socktype :"  << aiHints.ai_socktype << endl;
        
        Sleep(3000);
        return 0;
    } BOOL InitWinsock()
    {
    int Error;
    WORD VersionRequested;
    WSADATA WsaData;
    VersionRequested=MAKEWORD(2,2);
    Error=WSAStartup(VersionRequested,&WsaData); //启动WinSock2
    if(Error!=0)
    {
    return FALSE;
    }
    else
    {
    if(LOBYTE(WsaData.wVersion)!=2 || HIBYTE(WsaData.wHighVersion)!=2)
    {
    WSACleanup();
    return FALSE;
    }
    }
    return TRUE;
    }
    去掉#include "ws2tcpip.h",这样MS可以哈. 你要是想两个.h一起用,就想个办法不让它们冲突.
      

  4.   

    汗...
    我忘记把struct addrinfo 和sockaddr_in server 连起来了,你自己连吧.