由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - How to get local hostname under linux?
相关主题
有没有人在Vista下试过UDP广播double转换int的问题
C10M 练习2: 空TCP 连接,1M per 4G RAMTruncation error import csv file to SQL table (转载)
python question: A socket operation was attempted to an unreachable network[合集] 快速填充memory的方法?
Linux Socket编程请帮忙看看这个字符函数的错误在哪里
UNIX DATAGRAM 类型socket最大报文长度多少?诚心请教一个linux c问题
一个socket中select函数的问题地址空间里的一个BYTE不能写入(是合法地址)
问一个Linux无法监听指定端口的问题C++菜问: 怎么这样也可以?
C10M 练习 step 1: 10M sockets大家谈谈看??
相关话题的讨论汇总
话题: hostname话题: ifr话题: get话题: local话题: sizeof
进入Programming版参与讨论
1 (共1页)
B********s
发帖数: 3610
1
Code is as below. after I got the actural local ip information (credit to
ansel), I got a correct hostname but it was truncated at the first period.
For example, it gives "abc" instead of "abc.cs.mit.edu"
How can I get the full hostname then? Please pay attention to "my code" part.
Thanks.
fd = socket(AF_INET, SOCK_DGRAM, 0);
memset(&ifr, 0, sizeof(ifr));
memcpy(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name));
ioctl(fd, SIOCGIFADDR, &ifr);
sin_ptr = (struct sockaddr_in *) &ifr.ifr_addr;
myself = sin
B********s
发帖数: 3610
2
ding

part.

【在 B********s 的大作中提到】
: Code is as below. after I got the actural local ip information (credit to
: ansel), I got a correct hostname but it was truncated at the first period.
: For example, it gives "abc" instead of "abc.cs.mit.edu"
: How can I get the full hostname then? Please pay attention to "my code" part.
: Thanks.
: fd = socket(AF_INET, SOCK_DGRAM, 0);
: memset(&ifr, 0, sizeof(ifr));
: memcpy(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name));
: ioctl(fd, SIOCGIFADDR, &ifr);
: sin_ptr = (struct sockaddr_in *) &ifr.ifr_addr;

B********s
发帖数: 3610
3
没人知道么?

【在 B********s 的大作中提到】
: ding
:
: part.

e******d
发帖数: 14
4
I think it depends on your system configuration of hostname. The API reads
just your configuration and returns. If you change the hostname to abc.cs.
mit.edu in your configuration, you might get what you want.
Actually, I am not sure of it. Maybe wrong.

part.

【在 B********s 的大作中提到】
: Code is as below. after I got the actural local ip information (credit to
: ansel), I got a correct hostname but it was truncated at the first period.
: For example, it gives "abc" instead of "abc.cs.mit.edu"
: How can I get the full hostname then? Please pay attention to "my code" part.
: Thanks.
: fd = socket(AF_INET, SOCK_DGRAM, 0);
: memset(&ifr, 0, sizeof(ifr));
: memcpy(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name));
: ioctl(fd, SIOCGIFADDR, &ifr);
: sin_ptr = (struct sockaddr_in *) &ifr.ifr_addr;

1 (共1页)
进入Programming版参与讨论
相关主题
大家谈谈看??UNIX DATAGRAM 类型socket最大报文长度多少?
一道 memset in C++的题一个socket中select函数的问题
some c++ question.问一个Linux无法监听指定端口的问题
一个很诡异的ifstream问题,求助~~C10M 练习 step 1: 10M sockets
有没有人在Vista下试过UDP广播double转换int的问题
C10M 练习2: 空TCP 连接,1M per 4G RAMTruncation error import csv file to SQL table (转载)
python question: A socket operation was attempted to an unreachable network[合集] 快速填充memory的方法?
Linux Socket编程请帮忙看看这个字符函数的错误在哪里
相关话题的讨论汇总
话题: hostname话题: ifr话题: get话题: local话题: sizeof