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;
|
|