稳定盈利的期货交易方法-量化趋势交易

alantop -专业量化投资者

爱好:量化投资,逆向工程,渗透
随笔 - 595, 文章 - 0, 评论 - 921, 引用 - 0
数据加载中……

网络编程常用知识

1. 如何获取主机名

2. 如何从域名获取IP地址

3. 如何从struct in_addr和struct hostent结构中获取IP地址

    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 FALSE;
    }
    /* 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 FALSE;
    }

    char hostname[255];

    struct hostent *hst = gethostbyname(www.126.com) ;
    struct   in_addr   ia; 

    if(hst   !=   NULL)  
    {  
        memcpy(&ia.s_addr,hst->h_addr_list[0],sizeof(ia.s_addr));  
        int   iIpLength   =   strlen(inet_ntoa(ia))   +   1;  
        char*   lpcIp   =   new   char[iIpLength];  
        ZeroMemory(lpcIp,iIpLength);  
        strcpy(lpcIp,inet_ntoa(ia));  

       delete []lpclp;

  }

    int i = gethostname(hostname, 255);

            WSACleanup( );

posted on 2007-09-04 12:39 AlanTop 阅读(659) 评论(0)  编辑 收藏 引用 所属分类: VC++


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理