如何使用C编程找到系统的IP地址? [英] How to find the ip address of a system using C programming?

查看:112
本文介绍了如何使用C编程找到系统的IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何使用C代码查找系统的IP地址?

Hi,

How to find the IP address of a system using C code?

推荐答案

这取决于操作系统。



使用Linux,使用 getifaddrs 。只需在终端输入'man getifaddrs'或查看此处 [ ^ ]。手册页包含一个示例。



使用Windows,使用 gethostname() [ ^ ]后跟 gethostbyname() [ ^ ]或 getaddrinfo() [ ^ ]。最后两个链接包含示例代码。
This depends on the operating system.

With Linux, use getifaddrs. Just type 'man getifaddrs' in a terminal or see here[^]. The man page contains an example.

With Windows, use gethostname()[^] followed by gethostbyname()[^] or getaddrinfo()[^]. The last two links contain example code.


这篇关于如何使用C编程找到系统的IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆