本文整理汇总了C++中res_init函数的典型用法代码示例。如果您正苦于以下问题:C++ res_init函数的具体用法?C++ res_init怎么用?C++ res_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了res_init函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int
main(int count, char **options) {
int res;
if (strcmp(options[1], "-d") != 0) {
res = daemon(0, 0);
printf("return value: %s\n", res);
}
res_init();
_res.retrans = 4;
_res.retry = 2;
int running = 1;
if (parse_config()) {
printf("error reading configuration!\n");
return 1;
}
if (open_status_socket())
printf("error opening status socket; no status will be provided\n");
stat(config_file, &config_last_mod);
printf("last config modified time: %s\n", ctime(&config_last_mod.st_mtime));
while (running) {
struct config_interfaces *cur = config;
printf("checking if conf file has changed\n");
if (config_changed()) {
printf("modifying:\n");
clear_config(config);
cur = 0;
if (parse_config())
printf("error reading configuration!\n");
else
cur = config;
}
while (cur) {
if (check_interface(cur)) {
printf("media type: %s\n", mediatype(cur->if_name));
if (strcmp(mediatype(cur->if_name), "Ethernet") == 0) {
if (setup_ethernetinterface(cur))
break;
} else if (strcmp(mediatype(cur->if_name), "IEEE802.11") == 0) {
if (setup_wlaninterface(cur))
break;
}
}
cur = cur->next;
}
printf("Sleeping... waiting %d seconds\n", poll_wait);
sleep(poll_wait);
printf("restarto\n");
}
return 0;
}
开发者ID:myauie,项目名称:wlan-daemon,代码行数:51,代码来源:main.c
示例2: nres_search
int
nres_search(struct nres *block)
{
register char *cp, *domain;
int n;
if ((_res.options & RES_INIT) == 0 && res_init() == -1)
return (-1);
block->retries = 0; /* start clock */
if (block->search_index < 0)
return (-1);
/* only try exact match for reverse cases */
if (block->reverse) {
(void) nres_querydomain(block->name, (char *)NULL,
block->search_name);
block->search_index = -1;
return (0);
}
for (cp = block->name, n = 0; *cp; cp++)
if (*cp == '.')
n++;
/* n indicates the presence of trailing dots */
if (block->search_index == 0) {
if (n == 0 && (cp = nres_hostalias(block->name))) {
(void) strncpy(block->search_name, cp, 2 * MAXDNAME);
block->search_index = -1; /* if hostalias try 1 name */
return (0);
}
}
if ((n == 0 || *--cp != '.') && (_res.options & RES_DEFNAMES)) {
domain = _res.dnsrch[block->search_index];
if (domain) {
(void) nres_querydomain(block->name, domain,
block->search_name);
block->search_index++;
return (0);
}
}
if (n) {
(void) nres_querydomain(block->name, (char *)NULL,
block->search_name);
block->search_index = -1;
return (0);
}
block->search_index = -1;
return (-1);
}
开发者ID:andreiw,项目名称:polaris,代码行数:50,代码来源:nres_search.c
示例3: monitor_common_res_init
errno_t
monitor_common_res_init(TALLOC_CTX *mem_ctx,
struct sbus_request *sbus_req,
void *no_data)
{
int ret;
ret = res_init();
if (ret != 0) {
return EIO;
}
return EOK;
}
开发者ID:pbrezina,项目名称:sssd,代码行数:14,代码来源:sss_iface.c
示例4: resolver_init
static void resolver_init(void)
{
#ifdef G_OS_UNIX
static time_t resolv_conf_mtime = 0;
struct stat s;
if (g_stat("/etc/resolv.conf", &s) == 0 &&
s.st_mtime != resolv_conf_mtime) {
debug_print("Reloading /etc/resolv.conf\n");
resolv_conf_mtime = s.st_mtime;
res_init();
}
#endif
}
开发者ID:ittner,项目名称:sylpheed-contrib,代码行数:14,代码来源:socket.c
示例5: utGetDomainInfo
int
utGetDomainInfo(char **szDefDomain, char **szDefServer)
{
if (res_init() != 0)
return 1;
*szDefDomain = calloc(257, sizeof(char));
memcpy(*szDefDomain, _res.defdname, 256);
if (strnlen(*szDefDomain, 256) == 0)
*szDefDomain[0] = '-';
*szDefServer = calloc(IFNAMSIZ, sizeof(char));
memcpy(*szDefServer, inet_ntoa(_res.nsaddr_list[0].sin_addr), IFNAMSIZ-1);
res_close();
return 0;
}
开发者ID:lnslbrty,项目名称:naskpass,代码行数:14,代码来源:utils.c
示例6: my_res_init
static int my_res_init()
{
#ifdef JDNS_OS_MAC
res_init_func mac_res_init;
// look up res_init in the system library (qt does this, not sure why)
mac_res_init = (res_init_func)dlsym(RTLD_NEXT, "res_init");
if(!mac_res_init)
return -1;
return mac_res_init();
#else
return res_init();
#endif
}
开发者ID:shadchin,项目名称:iris,代码行数:14,代码来源:jdns_sys.c
示例7: defined
std::vector<std::string> CNetworkLinux::GetNameServers(void)
{
std::vector<std::string> result;
#if defined(TARGET_DARWIN)
FILE* pipe = popen("scutil --dns | grep \"nameserver\" | tail -n2", "r");
usleep(100000);
if (pipe)
{
std::vector<std::string> tmpStr;
char buffer[256] = {'\0'};
if (fread(buffer, sizeof(char), sizeof(buffer), pipe) > 0 && !ferror(pipe))
{
tmpStr = StringUtils::Split(buffer, "\n");
for (unsigned int i = 0; i < tmpStr.size(); i ++)
{
// result looks like this - > ' nameserver[0] : 192.168.1.1'
// 2 blank spaces + 13 in 'nameserver[0]' + blank + ':' + blank == 18 :)
if (tmpStr[i].length() >= 18)
result.push_back(tmpStr[i].substr(18));
}
}
pclose(pipe);
}
if (result.empty())
CLog::Log(LOGWARNING, "Unable to determine nameserver");
#elif defined(TARGET_ANDROID)
char nameserver[PROP_VALUE_MAX];
if (__system_property_get("net.dns1",nameserver))
result.push_back(nameserver);
if (__system_property_get("net.dns2",nameserver))
result.push_back(nameserver);
if (__system_property_get("net.dns3",nameserver))
result.push_back(nameserver);
if (!result.size())
CLog::Log(LOGWARNING, "Unable to determine nameserver");
#else
res_init();
for (int i = 0; i < _res.nscount; i ++)
{
std::string ns = inet_ntoa(((struct sockaddr_in *)&_res.nsaddr_list[i])->sin_addr);
result.push_back(ns);
}
#endif
return result;
}
开发者ID:FernetMenta,项目名称:xbmc,代码行数:49,代码来源:NetworkLinux.cpp
示例8: make_resolv
static int make_resolv (char *ifname, dhcp_t *dhcp, int wait)
{
FILE *f;
struct stat buf;
char resolvconf[PATH_MAX];
address_t *address;
if (!stat ("/sbin/resolvconf", &buf))
{
logger (LOG_DEBUG, "sending DNS information to resolvconf");
snprintf (resolvconf, PATH_MAX, "/sbin/resolvconf -a %s", ifname);
f = popen (resolvconf, "w");
if (!f)
logger (LOG_ERR, "popen: %m");
}
else
{
if (! (f = fopen(RESOLVFILE, "w")))
logger (LOG_ERR, "fopen `%s': %m", RESOLVFILE);
}
if (f)
{
fprintf (f, "# Generated by dhcpcd for interface %s\n", ifname);
if (dhcp->dnssearch)
fprintf (f, "search %s\n", dhcp->dnssearch);
else if (dhcp->dnsdomain) {
fprintf (f, "search %s\n", dhcp->dnsdomain);
}
for (address = dhcp->dnsservers; address; address = address->next)
fprintf (f, "nameserver %s\n", inet_ntoa (address->address));
if (resolvconf)
{
pclose (f);
logger (LOG_DEBUG, "resolvconf completed");
}
else
fclose (f);
}
else
return -1;
/* Refresh the local resolver */
res_init ();
return 0;
}
开发者ID:BackupTheBerlios,项目名称:dhcpcd-svn,代码行数:49,代码来源:configure.c
示例9: gethostbyname
struct hostent *
gethostbyname(const char *name)
{
struct hostent *hp = NULL;
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
h_errno = NETDB_INTERNAL;
return (NULL);
}
if (_res.options & RES_USE_INET6) { /* XXX */
hp = gethostbyname2(name, AF_INET6); /* XXX */
if (hp) /* XXX */
return (hp); /* XXX */
} /* XXX */
return (gethostbyname2(name, AF_INET));
}
开发者ID:KrisChaplin,项目名称:octeon_toolchain-4.1,代码行数:16,代码来源:gethostnamadr.c
示例10: main
int main( int argc, char ** argv ) {
char domain[ MYMAX ];
int len = 0;
unsigned int res;
int a, i, j, k, l, n, t;
res_init();
len = res_query( argv[1], C_IN, T_MX, buff, MYMAX );
printf( "MX records for gmail.com len =%d\n", len );
a = ReadHeader();
if ( getAnswerRecordCount() > 0 ) {
printf("\n;; Answer section:\n");
for ( i = 0; i < getAnswerRecordCount(); i++ ) {
a = ReadRecord( a );
}
}
if ( getAuthRecordCount() > 0 ) {
printf("\n;; Authority section:\n");
for ( i = 0; i < getAuthRecordCount(); i++ ) {
a = ReadRecord( a );
}
}
if ( getAdditionalRecordCount() > 0 ) {
printf("\n;; Additional section:\n");
for ( i = 0; i < getAdditionalRecordCount(); i++ ) {
a = ReadRecord( a );
}
}
/*
for( a=0; a < len; a++ ) {
printf( "[ %d ] = %d, %c\n", a, buff[ a ], buff[ a ] );
}
for( ; a < len; a++ ) {
printf( "buff[ %d ] = %d, %c\n", a, buff[ a ], buff[ a ] );
}
*/
}
开发者ID:eariassoto,项目名称:laboratoriosCI1321,代码行数:47,代码来源:dns.c
示例11: message
std::vector<IpAddr>
ip_utils::getLocalNameservers()
{
std::vector<IpAddr> res;
#if defined __ANDROID__ || defined _WIN32 || TARGET_OS_IPHONE
#ifdef _MSC_VER
#pragma message (__FILE__ "(" STR2(__LINE__) ") : -NOTE- " "Not implemented")
#else
#warning "Not implemented"
#endif
#else
if (not (_res.options & RES_INIT))
res_init();
res.insert(res.end(), _res.nsaddr_list, _res.nsaddr_list + _res.nscount);
#endif
return res;
}
开发者ID:asadsalman,项目名称:ring-daemon,代码行数:17,代码来源:ip_utils.cpp
示例12: throw
void Resolver::setNameserver(char *nameserver) throw (std::invalid_argument)
{
if (nameserver == NULL) {
throw std::invalid_argument("Cannot use empty nameserver");
}
int ret;
struct addrinfo *result;
struct addrinfo hints;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_protocol = 0;
ret = getaddrinfo(nameserver, "domain", &hints, &result);
if (ret != 0) {
std::string err = std::string("Unable to resolve address '") + nameserver + "': " + gai_strerror(ret);
throw std::invalid_argument(err);
}
res_init();
if (result->ai_addr->sa_family == AF_INET) {
#ifdef DEBUG
std::cerr << "Setting up IPv4 DNS server with address " << nameserver << std::endl;
#endif
struct sockaddr_in *sock4 = (struct sockaddr_in *) result->ai_addr;
memcpy((void *)&_res.nsaddr_list[0], sock4, result->ai_addrlen);
_res.nscount = 1;
} else if (result->ai_addr->sa_family == AF_INET6) {
std::cerr << "IPv6 addresses are not supported for DNS server." << std::endl;
/*
struct sockaddr_in6 *sock6 = (struct sockaddr_in6 *) result->ai_addr;
memcpy((void *)&_res.nsaddr_list[0], sock6, result->ai_addrlen);
_res.nscount = 1;
*/
} else {
std::string err = std::string("Unable to resolve address for ") + nameserver + ": " + "Unknown address family";
throw std::invalid_argument(err);
}
freeaddrinfo(result);
this->nameserver = nameserver;
}
开发者ID:evertlammerts,项目名称:ipfixcol,代码行数:45,代码来源:Resolver.cpp
示例13: nslookup_main
/* ________________________________________________________________________ */
int nslookup_main(int argc, char **argv)
{
struct hostent *host;
if (argc < 2 || *argv[1]=='-') {
show_usage();
}
res_init();
server_print();
if (is_ip_address(argv[1])) {
host = gethostbyaddr_wrapper(argv[1]);
} else {
host = gethostbyname(argv[1]);
}
hostent_fprint(host, 0);
return EXIT_SUCCESS;
}
开发者ID:BackupTheBerlios,项目名称:wl530g-svn,代码行数:19,代码来源:nslookup.c
示例14: nb_dns_init
struct nb_dns_info *
nb_dns_init(char *errstr)
{
register struct nb_dns_info *nd;
nd = (struct nb_dns_info *)malloc(sizeof(*nd));
if (nd == NULL) {
snprintf(errstr, NB_DNS_ERRSIZE, "nb_dns_init: malloc(): %s",
my_strerror(errno));
return (NULL);
}
memset(nd, 0, sizeof(*nd));
nd->s = -1;
/* XXX should be able to init static hostent struct some other way */
(void)gethostbyname("localhost.");
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
snprintf(errstr, NB_DNS_ERRSIZE, "res_init() failed");
free(nd);
return (NULL);
}
nd->s = socket(PF_INET, SOCK_DGRAM, 0);
if (nd->s < 0) {
snprintf(errstr, NB_DNS_ERRSIZE, "socket(): %s",
my_strerror(errno));
free(nd);
return (NULL);
}
/* XXX should use resolver config */
nd->server = _res.nsaddr_list[0];
if (connect(nd->s, (struct sockaddr *)&nd->server,
sizeof(struct sockaddr)) < 0) {
snprintf(errstr, NB_DNS_ERRSIZE, "connect(%s): %s",
inet_ntoa(nd->server.sin_addr), my_strerror(errno));
close(nd->s);
free(nd);
return (NULL);
}
return (nd);
}
开发者ID:aming2007,项目名称:dpi-test-suite,代码行数:44,代码来源:nb_dns.c
示例15: gethostbyname2
struct hostent *
gethostbyname2(const char *name, int af)
{
int r;
res_init();
r = _gethostbyname(name, af, &_hostent, _entbuf, sizeof(_entbuf),
&h_errno);
if (r) {
h_errno = NETDB_INTERNAL;
errno = r;
}
if (h_errno)
return (NULL);
return (&_hostent);
}
开发者ID:ajinkya93,项目名称:OpenBSD,代码行数:19,代码来源:gethostnamadr.c
示例16: res_init
/*
Turn a string into a struct addrinfo.
Return NULL on failure.
*/
struct addrinfo *str2addrinfo(const char *address, const char *service, int socktype) {
struct addrinfo *ai, hint = {0};
int err;
hint.ai_family = addressfamily;
hint.ai_socktype = socktype;
#if HAVE_DECL_RES_INIT
res_init();
#endif
err = getaddrinfo(address, service, &hint, &ai);
if(err) {
logger(DEBUG_ALWAYS, LOG_WARNING, "Error looking up %s port %s: %s", address, service, err == EAI_SYSTEM ? strerror(errno) : gai_strerror(err));
return NULL;
}
return ai;
}
开发者ID:xentec,项目名称:tinc,代码行数:23,代码来源:netutl.c
示例17: query_as
void query_as(char *arg, char *namelisten_addr, char *buf, int buflen) {
u_char nsbuf[4096];
ns_msg msg;
ns_rr rr;
int len;
// Set namelisten_addr
res_init();
struct in_addr listen_addr_in_addr;
if (inet_pton(AF_INET, namelisten_addr, &listen_addr_in_addr) > 0) {
_res.nscount = 1;
_res.nsaddr_list[0].sin_addr = listen_addr_in_addr;
}
len = res_query(arg, ns_c_any, ns_t_txt, nsbuf, sizeof(nsbuf));
ns_initparse(nsbuf, len, &msg);
ns_parserr(&msg, ns_s_an, 0, &rr);
ns_sprintrr(&msg, &rr, NULL, NULL, buf, buflen);
}
开发者ID:novag,项目名称:LookingGlass,代码行数:19,代码来源:LookingGlass.c
示例18: INET_resolve
static int
INET_resolve(char *name, struct sockaddr_in *sin)
{
struct hostent *hp;
struct netent *np;
/* Grmpf. -FvK */
sin->sin_family = AF_INET;
sin->sin_port = 0;
/* Default is special, meaning 0.0.0.0. */
if (!strcmp(name, "default")) {
sin->sin_addr.s_addr = INADDR_ANY;
return(1);
}
/* gethostbyname doesnt resolve this (Pavel Krauz) */
if (!(strcmp(name, "255.255.255.255"))) {
sin->sin_addr.s_addr = htonl(INADDR_BROADCAST);
return (1);
}
/* Try the NETWORKS database to see if this is a known network. */
if ((np = getnetbyname(name)) != (struct netent *)NULL) {
sin->sin_addr.s_addr = htonl(np->n_net);
strcpy(name, np->n_name);
return(1);
}
#ifdef DEBUG
res_init();
_res.options |= RES_DEBUG;
#endif
if ((hp = gethostbyname(name)) == (struct hostent *)NULL) {
errno = h_errno;
return(-1);
}
memcpy((char *) &sin->sin_addr, (char *) hp->h_addr_list[0], hp->h_length);
strcpy(name, hp->h_name);
return(0);
}
开发者ID:AnthraX1,项目名称:rk,代码行数:42,代码来源:inet.c
示例19: _resolv_init
/* init. the resolver
* params: retr_time - time before retransmitting (must be >0)
* retr_no - retransmissions number
* servers_no - how many dns servers will be used
* (from the one listed in /etc/resolv.conf)
* search - if 0 the search list in /etc/resolv.conf will
* be ignored (HINT: even if you don't have a
* search list in resolv.conf, it's still better
* to set search to 0, because an empty seachlist
* means in fact search "" => it takes more time)
* If any of the parameters <0, the default (system specific) value
* will be used. See also resolv.conf(5).
* returns: 0 on success, -1 on error
*/
static int _resolv_init(void)
{
res_init();
#ifdef HAVE_RESOLV_RES
if (cfg_get(core, core_cfg, dns_retr_time)>0)
_res.retrans=cfg_get(core, core_cfg, dns_retr_time);
if (cfg_get(core, core_cfg, dns_retr_no)>0)
_res.retry=cfg_get(core, core_cfg, dns_retr_no);
if ((cfg_get(core, core_cfg, dns_servers_no)>=0)
&& (cfg_get(core, core_cfg, dns_servers_no)<_res.nscount))
_res.nscount=cfg_get(core, core_cfg, dns_servers_no);
if (cfg_get(core, core_cfg, dns_search_list)==0)
_res.options&=~(RES_DEFNAMES|RES_DNSRCH);
#else
#warning "no resolv timeout support"
LOG(L_WARN, "WARNING: _resolv_init: no resolv options support - resolv"
" options will be ignored\n");
#endif
return 0;
}
开发者ID:miao606,项目名称:kamailio,代码行数:34,代码来源:resolve.c
示例20: getMailserver
char* getMailserver(const char* domain) {
int len;
char answer[NS_PACKETSZ];
char *mailserver = malloc(NS_PACKETSZ);
ns_msg msg;
ns_rr rr;
if(res_init() == -1) {
return NULL;
}
len = res_query(domain,C_ANY,T_MX,answer,NS_PACKETSZ);
if(len == -1) {
return NULL;
}
/* return first MX record */
ns_initparse(answer,len,&msg);
ns_parserr(&msg,ns_s_an,0,&rr);
dn_expand(ns_msg_base(msg),ns_msg_base(msg)+ns_msg_size(msg),ns_rr_rdata(rr)+NS_INT16SZ,mailserver,NS_PACKETSZ);
return mailserver;
}
开发者ID:n0g,项目名称:cherami,代码行数:20,代码来源:sendmail.c
注:本文中的res_init函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论