📄 main.c
字号:
#else fprintf(filePtr,"*** Can't find address for server %s: %s\n", server, DecodeError(result));#endif } else { /* PrintHostInfo(filePtr, "Server:", &serverInfo); */ result = DoLookup(host, &serverInfo, server); } if (putToFile) { fclose(filePtr); filePtr = NULL; } return(result);}/* ****************************************************************************** * * SetOption -- * * This routine is used to change the state information * that affect the lookups. The command format is * set keyword[=value] * Most keywords can be abbreviated. Parsing is very simplistic-- * A value must not be separated from its keyword by white space. * * Valid keywords: Meaning: * all lists current values of options. * ALL lists current values of options, including * hidden options. * [no]d2 turn on/off extra debugging mode. * [no]debug turn on/off debugging mode. * [no]defname use/don't use default domain name. * [no]search use/don't use domain search list. * domain=NAME set default domain name to NAME. * [no]ignore ignore/don't ignore trunc. errors. * query=value set default query type to value, * value is one of the query types in RFC883 * without the leading T_. (e.g., A, HINFO) * [no]recurse use/don't use recursive lookup. * retry=# set number of retries to #. * root=NAME change root server to NAME. * time=# set timeout length to #. * [no]vc use/don't use virtual circuit. * port TCP/UDP port to server. * * Deprecated: * [no]primary use/don't use primary server. * * Results: * SUCCESS the command was parsed correctly. * ERROR the command was not parsed correctly. * ****************************************************************************** */intSetOption(option) register char *option;{ char type[NAME_LEN]; char *ptr; int tmp; while (isspace(*option)) ++option; if (strncmp (option, "set ", 4) == 0) option += 4; while (isspace(*option)) ++option; if (*option == 0) { fprintf(stderr, "*** Invalid set command\n"); return(ERROR); } else { if (strncmp(option, "all", 3) == 0) { ShowOptions(); } else if (strncmp(option, "ALL", 3) == 0) { ShowOptions(); } else if (strncmp(option, "d2", 2) == 0) { /* d2 (more debug) */ _res.options |= (RES_DEBUG | RES_DEBUG2); } else if (strncmp(option, "nod2", 4) == 0) { _res.options &= ~RES_DEBUG2;#ifndef GUI printf("d2 mode disabled; still in debug mode\n");#else fprintf(outputfile,"d2 mode disabled; still in debug mode\n");#endif } else if (strncmp(option, "def", 3) == 0) { /* defname */ _res.options |= RES_DEFNAMES; } else if (strncmp(option, "nodef", 5) == 0) { _res.options &= ~RES_DEFNAMES; } else if (strncmp(option, "do", 2) == 0) { /* domain */ ptr = strchr(option, '='); if (ptr != NULL) { sscanf(++ptr, "%s", _res.defdname); res_re_init(); } } else if (strncmp(option, "deb", 1) == 0) { /* debug */ _res.options |= RES_DEBUG; } else if (strncmp(option, "nodeb", 5) == 0) { _res.options &= ~(RES_DEBUG | RES_DEBUG2); } else if (strncmp(option, "ig", 2) == 0) { /* ignore */ _res.options |= RES_IGNTC; } else if (strncmp(option, "noig", 4) == 0) { _res.options &= ~RES_IGNTC; } else if (strncmp(option, "po", 2) == 0) { /* port */ ptr = strchr(option, '='); if (ptr != NULL) { sscanf(++ptr, "%hu", &nsport); }#ifdef deprecated } else if (strncmp(option, "pri", 3) == 0) { /* primary */ _res.options |= RES_PRIMARY; } else if (strncmp(option, "nopri", 5) == 0) { _res.options &= ~RES_PRIMARY;#endif } else if (strncmp(option, "q", 1) == 0 || /* querytype */ strncmp(option, "ty", 2) == 0) { /* type */ ptr = strchr(option, '='); if (ptr != NULL) { sscanf(++ptr, "%s", type); queryType = StringToType(type, queryType, stderr); } } else if (strncmp(option, "cl", 2) == 0) { /* query class */ ptr = strchr(option, '='); if (ptr != NULL) { sscanf(++ptr, "%s", type); queryClass = StringToClass(type, queryClass, stderr); } } else if (strncmp(option, "rec", 3) == 0) { /* recurse */ _res.options |= RES_RECURSE; } else if (strncmp(option, "norec", 5) == 0) { _res.options &= ~RES_RECURSE; } else if (strncmp(option, "ret", 3) == 0) { /* retry */ ptr = strchr(option, '='); if (ptr != NULL) { sscanf(++ptr, "%d", &tmp); if (tmp >= 0) { _res.retry = tmp; } } } else if (strncmp(option, "ro", 2) == 0) { /* root */ ptr = strchr(option, '='); if (ptr != NULL) { sscanf(++ptr, "%s", rootServerName); } } else if (strncmp(option, "sea", 3) == 0) { /* search list */ _res.options |= RES_DNSRCH; } else if (strncmp(option, "nosea", 5) == 0) { _res.options &= ~RES_DNSRCH; } else if (strncmp(option, "srchl", 5) == 0) { /* domain search list */ ptr = strchr(option, '='); if (ptr != NULL) { res_dnsrch(++ptr); } } else if (strncmp(option, "ti", 2) == 0) { /* timeout */ ptr = strchr(option, '='); if (ptr != NULL) { sscanf(++ptr, "%d", &tmp); if (tmp >= 0) { _res.retrans = tmp; } } } else if (strncmp(option, "v", 1) == 0) { /* vc */ _res.options |= RES_USEVC; } else if (strncmp(option, "nov", 3) == 0) { _res.options &= ~RES_USEVC; } else { fprintf(stderr, "*** Invalid option: %s\n", option); return(ERROR); } } return(SUCCESS);}/* * Fake a reinitialization when the domain is changed. */voidres_re_init(){ register char *cp, **pp; int n; /* find components of local domain that might be searched */ pp = _res.dnsrch; *pp++ = _res.defdname; for (cp = _res.defdname, n = 0; *cp; cp++) if (*cp == '.') n++; cp = _res.defdname; for (; n >= LOCALDOMAINPARTS && pp < _res.dnsrch + MAXDFLSRCH; n--) { cp = strchr(cp, '.'); *pp++ = ++cp; } *pp = 0; _res.options |= RES_INIT;}#define SRCHLIST_SEP '/'voidres_dnsrch(cp) register char *cp;{ register char **pp; int n; (void)strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); if ((cp = strchr(_res.defdname, '\n')) != NULL) *cp = '\0'; /* * Set search list to be blank-separated strings * on rest of line. */ cp = _res.defdname; pp = _res.dnsrch; *pp++ = cp; for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) { if (*cp == SRCHLIST_SEP) { *cp = '\0'; n = 1; } else if (n) { *pp++ = cp; n = 0; } } if ((cp = strchr(pp[-1], SRCHLIST_SEP)) != NULL) { *cp = '\0'; } *pp = NULL;}/* ****************************************************************************** * * ShowOptions -- * * Prints out the state information used by the resolver * library and other options set by the user. * ****************************************************************************** */voidShowOptions(){ register char **cp;#ifndef GUI PrintHostInfo(stdout, "Default Server:", defaultPtr); if (curHostValid) { PrintHostInfo(stdout, "Host:", &curHostInfo); }#else PrintHostInfo(outputfile, "Default Server:", defaultPtr); if (curHostValid) { PrintHostInfo(outputfile, "Host:", &curHostInfo); }#endif#ifndef GUI printf("Set options:\n"); printf(" %sdebug \t", (_res.options & RES_DEBUG) ? "" : "no"); printf(" %sdefname\t", (_res.options & RES_DEFNAMES) ? "" : "no"); printf(" %ssearch\t", (_res.options & RES_DNSRCH) ? "" : "no"); printf(" %srecurse\n", (_res.options & RES_RECURSE) ? "" : "no"); printf(" %sd2\t\t", (_res.options & RES_DEBUG2) ? "" : "no"); printf(" %svc\t\t", (_res.options & RES_USEVC) ? "" : "no"); printf(" %signoretc\t", (_res.options & RES_IGNTC) ? "" : "no"); printf(" port=%u\n", nsport); printf(" querytype=%s\t", p_type(queryType)); printf(" class=%s\t", p_class(queryClass)); printf(" timeout=%d\t", _res.retrans); printf(" retry=%d\n", _res.retry); printf(" root=%s\n", rootServerName); printf(" domain=%s\n", _res.defdname); if (cp = _res.dnsrch) { printf(" srchlist=%s", *cp); for (cp++; *cp; cp++) { printf("%c%s", SRCHLIST_SEP, *cp); } putchar('\n'); } putchar('\n');}#else sprintf(final_output,"Set options:\n"); sprintf(output," %sdebug \t", (_res.options & RES_DEBUG) ? "" : "no"); strcat(final_output,output); sprintf(output," %sdefname\t", (_res.options & RES_DEFNAMES) ? "" : "no"); strcat(final_output,output); sprintf(output," %ssearch\t", (_res.options & RES_DNSRCH) ? "" : "no"); strcat(final_output,output); sprintf(output," %srecurse\n", (_res.options & RES_RECURSE) ? "" : "no"); strcat(final_output,output); sprintf(output," %sd2\t\t", (_res.options & RES_DEBUG2) ? "" : "no"); strcat(final_output,output); sprintf(output," %svc\t\t", (_res.options & RES_USEVC) ? "" : "no"); strcat(final_output,output); sprintf(output," %signoretc\t", (_res.options & RES_IGNTC) ? "" : "no"); strcat(final_output,output); sprintf(output," port=%u\n", nsport); strcat(final_output,output); sprintf(output," querytype=%s\t", p_type(queryType)); strcat(final_output,output); sprintf(output," class=%s\t", p_class(queryClass)); strcat(final_output,output); sprintf(output," timeout=%d\t", _res.retrans); strcat(final_output,output); sprintf(output," retry=%d\n", _res.retry); strcat(final_output,output); sprintf(output," root=%s\n", rootServerName); strcat(final_output,output); sprintf(output," domain=%s\n", _res.defdname); strcat(final_output,output); if (cp = _res.dnsrch) { sprintf(output," srchlist=%s", *cp); strcat(final_output,output); for (cp++; *cp; cp++) { sprintf(output,"%c%s", SRCHLIST_SEP, *cp); strcat(final_output,output); } strcat(final_output,"\n"); } strcat(final_output,"\n\0"); PrintToBox(final_output,0);}#endif#undef SRCHLIST_SEP/* ****************************************************************************** * * PrintHelp -- * * Displays the help file. * ****************************************************************************** */voidPrintHelp(){ char cmd[PATH_MAX];#ifndef WINNT sprintf(cmd, "%s %s", pager, _PATH_HELPFILE);#else#ifdef GUI { extern char filestring[100000]; int count; FILE *hfile; hfile = fopen(pathhelpfile,"r+"); count = fread(filestring,sizeof(char),100000,hfile); filestring[count] = '\0'; PrintToBox(filestring,count); fclose(hfile); sprintf(cmd, "%s < %s", pager, pathhelpfile); }#else sprintf(cmd, "%s < %s", pager, pathhelpfile); /* printf("path helpfile = %s ",pathhelpfile); */ system(cmd);#endif#endif}/* ****************************************************************************** * * CvtAddrToPtr -- * * Convert a dotted-decimal Internet address into the standard * PTR format (reversed address with .in-arpa. suffix). * * Assumes the argument buffer is large enougth to hold the result. * ****************************************************************************** */static voidCvtAddrToPtr(name) char *name;{ char *p; int ip[4]; struct in_addr addr; if (IsAddr(name, &addr)) { p = inet_ntoa(addr); if (sscanf(p, "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3]) == 4) { sprintf(name, "%d.%d.%d.%d.in-addr.arpa.", ip[3], ip[2], ip[1], ip[0]); } }}/* ****************************************************************************** * * ReadRC -- * * Use the contents of ~/.nslookuprc as options. * ****************************************************************************** */static voidReadRC(){ register FILE *fp; register char *cp; char buf[PATH_MAX]; if ((cp = getenv("HOME")) != NULL && (strlen(cp) + strlen(_PATH_NSLOOKUPRC)) < sizeof(buf)) { (void) strcpy(buf, cp);#ifndef WINNT (void) strcat(buf, _PATH_NSLOOKUPRC);#else (void) strcat(buf, pathnslookuprc);#endif if ((fp = fopen(buf, "r")) != NULL) { while (fgets(buf, sizeof(buf), fp) != NULL) { if ((cp = strchr(buf, '\n')) != NULL) { *cp = '\0'; } (void) SetOption(buf); } (void) fclose(fp); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -