我是初学tcp/ip编程。我在winsock2.h中找到了gethostname()函数申明,
gethostname(
    char FAR * name,
    int namelen
    );
但在winsock2.h没有找到这个函数的实现。到底是在哪实现这个函数的的呢?另外winsock2.h与winsock.h的区别是什么?
谢谢

解决方案 »

  1.   

    版本不同而以应该有gethostname的声明的,不过,头文件里没有它的实现,实现在dll里
      

  2.   

    gethostname
    The Windows Sockets gethostname function returns the standard host name for the local machine.int gethostname (
      char FAR * name,  
      int namelen       
    );
    Parameters
    name 
    [out] A pointer to a buffer that receives the local host name. 
    namelen 
    [in] The length of the buffer. 
    Res
    The gethostname function returns the name of the local host into the buffer specified by the name parameter. The host name is returned as a null-terminated string. The form of the host name is dependent on the Windows Sockets provider — it can be a simple host name, or it can be a fully qualified domain name. However, it is guaranteed that the name returned will be successfully parsed by gethostbyname and WSAAsyncGetHostByName.Note If no local host name has been configured, gethostname must succeed and return a token host name that gethostbyname or WSAAsyncGetHostByName can resolve.Return Values
    If no error occurs, gethostname returns zero. Otherwise, it returns SOCKET_ERROR and a specific error code can be retrieved by calling WSAGetLastError.Error Codes
    WSAEFAULT The name parameter is not a valid part of the user address space, or the buffer size specified by namelen parameter is too small to hold the complete host name. 
    WSANOTINITIALISED A successful WSAStartup must occur before using this function. 
    WSAENETDOWN The network subsystem has failed. 
    WSAEINPROGRESS A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function. 
    QuickInfo
      Windows NT: Yes
      Windows: Yes
      Windows CE: Use version 1.0 and later.
      Header: Declared in winsock2.h.
      Import Library: Link with ws2_32.lib.