struct sockaddr {    
     unsigned short sa_family; /* 地址家族, AF_xxx */    
     char sa_data[14]; /*14字节协议地址*/    
     };    

套接字地址信息的结构体。

struct sockaddr_in {    
     short int sin_family; /* 通信类型 */    
     unsigned short int sin_port; /* 端口 */    
     struct in_addr sin_addr; /* Internet 地址 */    
     unsigned char sin_zero[8]; /* 与sockaddr结构的长度相同*/    
     };    

/* Internet 地址 (一个与历史有关的结构) */    
     struct in_addr {    
     unsigned long s_addr;    
     };    


简单用用:
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>

int main(int argc, char *argv[])
{
        long in_addr_t;
        in_addr_t=inet_addr("192.168.0.1");
        printf("%ld\n",in_addr_t);    
        system("PAUSE");  
        return 0;
}



再一次例子:


#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>

int main(int argc, char *argv[])
{
        struct sockaddr_in ina;
        ina.sin_addr.s_addr=inet_addr("192.168.0.1");
        printf("%s",inet_ntoa(ina.sin_addr));    
        system("PAUSE");  
        return 0;
}



在一个:

#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>

int main(int argc, char *argv[])
{
        struct sockaddr_in ina1;
        ina1.sin_addr.s_addr=inet_addr("192.168.0.1");
        
        struct sockaddr_in ina2;
        ina2.sin_addr.s_addr=inet_addr("192.168.0.2");
        
        char addr1[20];
        strcpy(addr1,inet_ntoa(ina1.sin_addr));
        
        char addr2[20];
        strcpy(addr2,inet_ntoa(ina2.sin_addr));
            
        printf("%s\n",addr1);    
        printf("%s",addr2);        
        system("PAUSE");  
        return 0;
}



注意在dev-cpp的项目设置-参数-连接器里加入-lws2_32

winsock2的win32 Lib库。