当前位置:网站首页>MFC obtains local IP (used more in network communication)
MFC obtains local IP (used more in network communication)
2022-04-23 19:29:00 【ToneChip】
CString CUDPDlg::GetIP() // Access to the local IP
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255]; // Local hostname array variable
CString m_ip; // IP Address string variable
PHOSTENT hostinfo; // hostent Structure pointer
wVersionRequested = MAKEWORD(2, 0); // Connecting applications to winsock Dll
if (WSAStartup(wVersionRequested, &wsaData) == 0)
{
if (gethostname(name, sizeof(name)) == 0) // Get the local host name
{
if ((hostinfo = gethostbyname(name)) != NULL) // Get host information
{
m_ip = inet_ntoa(*(struct in_addr *)*hostinfo->h_addr_list); // Convert to get IP Address
}
else m_ip = "IP Detection failed ";
}
WSACleanup(); // suspend winsock DLL Use
}
return m_ip; // return IP Address string
}
Call the following
CString localIP;
localIP = GetIP(); // Get this machine IP
SetDlgItemText(IDC_IP1, localIP); // Get local IP Display to the interface
版权声明
本文为[ToneChip]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231923488465.html
边栏推荐
- 点云数据集常用处理
- Class loading process of JVM
- 指针数组与数组指针的区分
- ArcMap connecting ArcGIS Server
- Main differences between go and PHP
- Executor、ExecutorService、Executors、ThreadPoolExecutor、Future、Runnable、Callable
- Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies
- goroutine
- Solve the problem of invalid listview Click
- MySQL syntax collation
猜你喜欢
随机推荐
Virtual machine performance monitoring and fault handling tools
Web Security
MySQL syntax collation (3)
Customize the non slidable viewpage and how to use it
The most detailed network counting experiment in history (2) -- rip experiment of layer 3 switch
指针数组与数组指针的区分
Steps to build a deep learning environment GPU
C学习完结
Oracle配置st_geometry
Prefer composition to inheritance
Decompile and get the source code of any wechat applet - just read this (latest)
MySQL数据库 - 数据库和表的基本操作(二)
Some speculation about the decline of adults' language learning ability
JS calculation time difference
Gossip: on greed
[report] Microsoft: application of deep learning methods in speech enhancement
Go modules daily use
js上传文件时控制文件类型和大小
An algorithm problem was encountered during the interview_ Find the mirrored word pairs in the dictionary
Scrum Patterns之理解各种团队模式