Get the first IP of this unit (common routine: 1)

zhaozj2021-02-17  73

I just collect it.

#include "winsock2.h" #pragma comment (lib, "ws2_32") const char * get_first_ip (void) {char szHostName [128]; const char * pszAddr = NULL; struct hostent * pHost; int i; WSADATA wsaData; WSAStartup (0x202, & wsadata); if (gethostname (SzhostName, 128) == 0) {phost = gethostByname (szhostname); for (i = 0; phost! = Null && phst-> h_addr_list [i]! = Null; i ) {/ * Processes each IP address * / pszaddr = inet_ntoa (* (Struct in_addr *) phost-> h_addr_list [i]); Break;}} wsacleanup (); Return Pszaddr;}

转载请注明原文地址:https://www.9cbs.com/read-31214.html

New Post(0)