TCP/IP socket programming in C(二)
来源:互联网 发布:tcp端口是什么 编辑:程序博客网 时间:2024/05/16 12:51
// get_ipaddr.c#include <errno.h> #include <stdio.h> #include <stdlib.h>#include <string.h>#include <fcntl.h>#include <unistd.h>#include <sys/socket.h>#include <netdb.h>int main(int argc, char *argv[]){ char *hostname = "www.baidu.com"; char ip[100]; struct hostent *he; struct in_addr **addr_list; int i; if ((he = gethostbyname(hostname)) == NULL) { // gethostbyname failed herror("gethostbyname"); return 1; } // Cast the h_addr_list to in_addr, since h_addr_list also has the // ip address in long format only addr_list = (struct in_addr **)he->h_addr_list; for (i = 0; addr_list[i] != NULL; i++) { // Return the first one strcpy(ip, inet_ntoa(*addr_list[i])); } printf("%s resolved to : %s\n", hostname, ip); return 0;}
原文:http://www.binarytides.com/socket-programming-c-linux-tutorial/
0 0
- TCP/IP socket programming in C(二)
- TCP/IP socket programming in C(一)
- TCP/IP socket programming in C(三)
- tcp/ip socket programming
- TCP/IP socket.c
- Programming TCP/IP Windows Sockets in C++
- Blockchain的鱼和熊掌系列(21) 之 TCP端口交互之socket programming in standard C
- Socket Programming in C# (二)(转载)
- TCP IP Sockets in C
- Asynchronous Socket Programming in C#: Part I
- Asynchronous Socket Programming in C#: Part II
- Asynchronous Socket Programming in C#: Part II
- Socket programming in C on Linux | tutorial
- TCP/IP Socket Communications in MATLAB example
- 基本的TCP/IP Socket用法(二)
- 基本的TCP/IP Socket用法(二)
- Linux下TCP/IP socket 编程二
- 经典基础教程---Programming TCP/IP Windows Sockets in C++
- Oracle 集合的一些用法例子
- URI与URL的区别
- 视频图像处理入门(一)
- 一段时间内只学习一项技术,学会抵制诱惑
- 我的第一篇博客,希望能坚持下去
- TCP/IP socket programming in C(二)
- Java 正确的做字符串编码转换
- 3497. 水仙花数 诶 用了三个for分别代表百十个位就不行了为什么呢 喵~ >▽<
- GDAL读取杂记
- 视图控制器视图的加载过程
- [LeetCode]48.Rotate Image
- HDU 1405 The Last Practice 数学水题
- 令人恼火的CMO
- Ubuntu 12.04 中安装和配置 Java JDK