gethostbyname

Compile a static binary which code there a function gethostbyname

心不动则不痛 提交于 2019-11-28 07:31:50
How to resolve compile a static binary which code include a function gethostbyname and if compiled without warning like this: warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking I compile on ubuntu 12.04 with command: $ gcc -static lookup.c -o lookup This is code for lookup.c: /* lookup.c */ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> extern int h_errno; int

nodejs cannot resolve 'localhost' on windows

与世无争的帅哥 提交于 2019-11-27 06:55:21
问题 The following code produces an exception in node.js under windows: var Socket = require("net").Socket; socket = new Socket(); socket.connect(80, "localhost"); here's the message: events.js:2083: Uncaught Error: getHostByName ENOTFOUND When I remove localhost , it works fine. What could be causing this? I tried turning the firewall off, but to no effect. 回答1: node.js uses c-ares resolver and ignores system resolver completely. So the advices regarding C:\WINDOWS\system32\drivers\etc\hosts are

Compile a static binary which code there a function gethostbyname

我只是一个虾纸丫 提交于 2019-11-27 01:50:27
问题 How to resolve compile a static binary which code include a function gethostbyname and if compiled without warning like this: warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking I compile on ubuntu 12.04 with command: $ gcc -static lookup.c -o lookup This is code for lookup.c: /* lookup.c */ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include

网络编程(8)—— IP地址和域名之间的转换

ⅰ亾dé卋堺 提交于 2019-11-26 19:25:16
一、引言 域名,简单来理解就是我们平常说的网址。比如登录某度买假药时,会在IE浏览器的地址栏输入www.baidu.com,这里我们输入的就是百度的域名。而实际上我们在互联网中要找到某个网站,是需要这个网站的IP地址的,因为在网络中IP地址就是一台主机的联系地址,而通过域名寻找主机时,就需要先将域名转换成IP地址,这就是我们通常说的DNS服务器的作用。 二、通过域名获取IP地址 网络编程中,我们通过gethostbyname函数可以通过域名获取主机信息。所谓主机信息就是网络那头web服务器的信息,其中就包含该服务器的IP地址。gethostbyname的函数原型如下: #include <netdb.h> struct hostent *gethostbyname(const char *name); 它接收的唯一参数就是我们在浏览器中输入的域名,在前面的例子中也就是某度的url:www.baidu.com。而他的返回值是一个hostent类型的指针,该结构体的定义如下: struct hostent { char* h_name; char** h_aliases; int h_addrtype; int h_length; char** h_addr_list; } h_name,存有官方域名。官方域名代表某一主页,但是一些公司的域名可能并未在官方域名注册。 h_aliases