1. SOCKADDR_IN sock; - This declares a variable sock of type SOCKADDR_IN, which is a structure defined in the Windows Socket API for storing socket address information.
  2. sock.sin_family = AF_INET; - This sets the address family of the socket to AF_INET, which is used for IPv4 addresses.
  3. sock.sin_addr.S_un.S_addr = inet_addr("192.168.1.111"); - This converts the string representation of an IPv4 address "192.168.1.111" to a network byte order format and assigns it to the S_addr member of the sin_addr structure within sock.
  4. sock.sin_port = htons(5000); - This converts the port number 5000 to network byte order format and assigns it to the sin_port member of sock.
  5. printf("inet_ntoa ip = %s\n",inet_ntoa(sock.sin_addr)); - This converts the sin_addr member of sock from network byte order to a string representation of an IPv4 address using the inet_ntoa function, and then prints it out
SOCKADDR_IN sock;socksin_family = AF_INET;将字符串转换为in_addr类型socksin_addrS_unS_addr = inet_addr1921681111;socksin_port = htons5000; 将in_addr类型转换为字符串printfinet_ntoa ip = sninet_ntoasocksin_addr;解释每行代码

原文地址: https://www.cveoy.top/t/topic/iyki 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录