⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 list.c

📁 一个可用的dns服务器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	}    }    return FALSE;}intPrintListInfo(file, msg, eom, qtype, domain)    FILE	*file;    u_char	*msg, *eom;    int		qtype;    char	*domain;{    register u_char	*cp;    HEADER		*headerPtr;    int			type, class, dlen, nameLen;    u_int32_t		ttl;    int			n, pref, count;    struct in_addr	inaddr;    char		name[NAME_LEN];    char		name2[NAME_LEN];    Boolean		stripped;    /*     * Read the header fields.     */    headerPtr = (HEADER *)msg;    cp = msg + HFIXEDSZ;    if (headerPtr->rcode != NOERROR) {	return(headerPtr->rcode);    }    /*     *  We are looking for info from answer resource records.     *  If there aren't any, return with an error. We assume     *  there aren't any question records.     */    if (ntohs( (u_short) headerPtr->ancount) == 0) {	return(NO_INFO);      }      for (n = ntohs((u_short) headerPtr->qdcount); n > 0; n--) { 	nameLen = dn_skipname(cp, eom); 	if (nameLen < 0) 	    return (ERROR); 	cp += nameLen + QFIXEDSZ;      }      for (count = ntohs((u_short)headerPtr->ancount); count > 0; count--) {  	nameLen = dn_expand(msg, eom, cp, name, sizeof name);  	if (nameLen < 0)	    return (ERROR);	cp += nameLen;	type = _getshort((u_char*)cp);	cp += INT16SZ;	if (!(type == qtype || qtype == T_ANY) &&	    !((type == T_NS || type == T_PTR) && qtype == T_A))		return(SUCCESS);	class = _getshort((u_char*)cp);	cp += INT16SZ;	ttl = _getlong((u_char*)cp);	cp += INT32SZ;	dlen = _getshort((u_char*)cp);	cp += INT16SZ;	if (name[0] == 0)		strcpy(name, "(root)");	/* Strip the domain name from the data, if desired. */	stripped = FALSE;	if ((_res.options & RES_DEBUG) == 0) {	    if (type != T_SOA) {		stripped = strip_domain(name, domain);	    }	}	if (!stripped && nameLen < sizeof(name)-1) {	    strcat(name, ".");	}	fprintf(file, NAME_FORMAT, name);	if (qtype == T_ANY) {	    if (_res.options & RES_DEBUG) {		fprintf(file,"\t%lu %-5s", ttl, p_class(queryClass));	    }	    fprintf(file," %-5s", p_type(type));	}	/* XXX merge this into debug.c's print routines */	switch (type) {	    case T_A:		if (class == C_IN) {		    bcopy(cp, (char *)&inaddr, INADDRSZ);		    if (dlen == 4) {			fprintf(file," %s", inet_ntoa(inaddr));		    } else if (dlen == 7) {			fprintf(file," %s", inet_ntoa(inaddr));			fprintf(file," (%d, %d)", cp[4],(cp[5] << 8) + cp[6]);		    } else			fprintf(file, " (dlen = %d?)", dlen);		}		cp += dlen;		break;	    case T_CNAME:	    case T_MB:	    case T_MG:	    case T_MR:		nameLen = dn_expand(msg, eom, cp, name2, sizeof name2);		if (nameLen < 0) {		    fprintf(file, " ***\n");		    return (ERROR);		}		fprintf(file, " %s", name2);		cp += nameLen;		break;	    case T_NS:	    case T_PTR:	    case T_NSAP_PTR:		putc(' ', file);		if (qtype != T_ANY)		    fprintf(file,"%s = ", type == T_PTR ? "host" : "server");		cp = (u_char *)Print_cdname2(cp, msg, eom, file);		if (!cp) {		    fprintf(file, " ***\n");		    return (ERROR);		}		break;	    case T_HINFO:	    case T_ISDN:		{		    u_char *cp2 = cp + dlen;		    if (n = *cp++) {			(void)sprintf(name,"%.*s", n, cp);			fprintf(file," %-10s", name);			cp += n;		    } else {			fprintf(file," %-10s", " ");		    }		    if (cp == cp2)			break;		    if (n = *cp++) {			fprintf(file,"  %.*s", n, cp);			cp += n;		    }		}		break;	    case T_SOA:		nameLen = dn_expand(msg, eom, cp, name2, sizeof name2);		if (nameLen < 0) {		    fprintf(file, " ***\n");		    return (ERROR);		}		cp += nameLen;		fprintf(file, " %s", name2);		nameLen = dn_expand(msg, eom, cp, name2, sizeof name2);		if (nameLen < 0) {		    fprintf(file, " ***\n");		    return (ERROR);		}		cp += nameLen;		fprintf(file, " %s. (", name2);		for (n = 0; n < 5; n++) {		    u_int32_t u;		    u = _getlong((u_char*)cp);		    cp += INT32SZ;		    fprintf(file,"%s%lu", n? " " : "", u);		}		fprintf(file, ")");		break;	    case T_MX:	    case T_AFSDB:		case T_RT:		pref = _getshort((u_char*)cp);		cp += INT16SZ;		fprintf(file," %-3d ",pref);		nameLen = dn_expand(msg, eom, cp, name2, sizeof name2);		if (nameLen < 0) {		    fprintf(file, " ***\n");		    return (ERROR);		}		fprintf(file, " %s", name2);		cp += nameLen;		break;	    case T_PX:		pref = _getshort((u_char*)cp);		cp += INT16SZ;		fprintf(file," %-3d ",pref);		nameLen = dn_expand(msg, eom, cp, name2, sizeof name2);		if (nameLen < 0) {			fprintf(file, " ***\n");			return (ERROR);		}		fprintf(file, " %s", name2);		cp += nameLen;		nameLen = dn_expand(msg, eom, cp, name2, sizeof name2);		if (nameLen < 0) {		    fprintf(file, " ***\n");		    return (ERROR);		}		fprintf(file, " %s", name2);		cp += nameLen;		break;	    case T_X25:		if (n = *cp++) {		    fprintf(file,"  %.*s", n, cp);		    cp += n;		}		break;	    case T_TXT:		{		    u_char *cp2 = cp + dlen;		    int c;		    while (cp < cp2) {		        (void) putc('"', file);			if (n = (unsigned char) *cp++)			    for (c = n; c > 0 && cp < cp2; c--) {				if (strchr("\n\"\\", *cp))				    (void) putc('\\', file);				(void) putc(*cp++, file);			    }			(void) putc('"', file);			if (cp < cp2)			    (void) putc(' ', file);		    }		}		break;	    case T_NSAP:		fprintf(file, " %s", inet_nsap_ntoa(dlen, cp, NULL));		cp += dlen;		break;	    case T_AAAA: {		char t[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];		fprintf(file, " %s", inet_ntop(AF_INET6, cp, t, sizeof t));		cp += dlen;		break;	    }	    case T_LOC: {		char t[255];		fprintf(file, "\t%s", loc_ntoa(cp, t));		cp += dlen;		break;	    }	    case T_SRV: {		u_int priority, weight, port;		priority = _getshort(cp);  cp += INT16SZ;		weight   = _getshort(cp);  cp += INT16SZ;		port     = _getshort(cp);  cp += INT16SZ;		fprintf(file, "\t%u %u %u ", priority, weight, port);		if ((cp = (u_char *)Print_cdname(cp, msg, eom, file)) == NULL)			return (ERROR);		break;	    }	    case T_NAPTR: {		u_int order, preference;                GETSHORT(order, cp);                fprintf(file, "\t%u", order);                GETSHORT(preference, cp);                fprintf(file, " %u", preference);                if (n = *cp++) {                     fprintf(file, " \"%.*s\"", (int)n, cp);                     cp += n;                }                if (n = *cp++) {                     fprintf(file, " \"%.*s\"", (int)n, cp);                     cp += n;                }                if (n = *cp++) {                     fprintf(file, " \"%.*s\"", (int)n, cp);                     cp += n;                }		if ((cp = (u_char *)Print_cdname(cp, msg, eom, file)) == NULL)			return (ERROR);                break;	    }	    case T_MINFO:	    case T_RP:		(void) putc(' ', file);		cp = (u_char *)Print_cdname(cp, msg, eom, file);		if (!cp) {		    fprintf(file, " ***\n");		    return (ERROR);		}		fprintf(file, "  ");		cp = (u_char *)Print_cdname(cp, msg, eom, file);		if (!cp) {		    fprintf(file, " ***\n");		    return (ERROR);		}		break;	    case T_UINFO:		fprintf(file, " %s", cp);		cp += dlen;		break;	    case T_UID:	    case T_GID:		fprintf(file, " %lu", _getlong((u_char*)cp));		cp += dlen;		break;	    case T_WKS:		if (class == C_IN) {		    struct protoent *pp;		    struct servent *ss;		    u_short port;		    cp += 4; 	/* skip inet address */		    dlen -= 4;		    setprotoent(1);		    setservent(1);		    n = *cp & 0377;		    pp = getprotobynumber(n);		    if (pp == 0)			fprintf(file," %-3d ", n);		    else			fprintf(file," %-3s ", pp->p_name);		    cp++; dlen--;		    port = 0;		    while (dlen-- > 0) {			n = *cp++;			do {			    if (n & 0200) {				ss = getservbyport((int)htons(port),					    pp->p_name);				if (ss == 0)				    fprintf(file," %u", port);				else				    fprintf(file," %s", ss->s_name);			    }				n <<= 1;			} while (++port & 07);		    }		    endprotoent();		    endservent();		}		break;	}	fprintf(file,"\n");    }    return(SUCCESS);}/* ******************************************************************************* * *  ViewList -- * *	A hack to view the output of the ls command in sorted *	order using more. * ******************************************************************************* */voidViewList(string)    char *string;{    char file[PATH_MAX];    char command[PATH_MAX];    sscanf(string, " view %s", file);    (void)sprintf(command, "grep \"^ \" %s | sort | %s", file, pager);    system(command);}/* ******************************************************************************* * *   Finger -- * *	Connects with the finger server for the current host *	to request info on the specified person (long form) *	who is on the system (short form). * *  Results: *	SUCCESS		the finger server was contacted. *	ERROR		the server could not be contacted because *			a socket could not be obtained or connected *			to or the service could not be found. * ******************************************************************************* */Finger(string, putToFile)    char *string;    int  putToFile;{	struct servent		*sp;	struct sockaddr_in	sin;    #ifndef WINNT	register FILE		*f;    #else    char f[5000];    int numread = 0;    int i;    #endif	register int		c;	register int		lastc;	char			name[NAME_LEN];	char			file[NAME_LEN];	/*	 *  We need a valid current host info to get an inet address.	 */	if (!curHostValid) {#ifndef GUI	    	    fprintf(stderr, "Finger: no current host defined.\n");#else	    fprintf(outputfile, "Finger: no current host defined.\n");#endif	    return (ERROR);	}	if (sscanf(string, " finger %s", name) == 1) {	    if (putToFile && (name[0] == '>')) {		name[0] = '\0';	    }	} else {	    name[0] = '\0';	}	sp = getservbyname("finger", "tcp");	if (sp == 0) {#ifndef GUI	    fprintf(stderr, "Finger: unknown service\n");#else	    fprintf(outputfile, "Finger: unknown service\n");#endif	    return (ERROR);	}	bzero((char *)&sin, sizeof(sin));	sin.sin_family	= curHostInfo.addrType;	sin.sin_port	= sp->s_port;	bcopy(curHostInfo.addrList[0], (char *)&sin.sin_addr,		curHostInfo.addrLen);	/*	 *  Set up a virtual circuit to the host.	 */	sockFD = socket(curHostInfo.addrType, SOCK_STREAM, 0);	if (sockFD < 0) {	    fflush(stdout);	    perror("finger: socket");	    return (ERROR);	}	if (connect(sockFD, (struct sockaddr *)&sin, sizeof (sin)) < 0) {	    fflush(stdout);	    perror("finger: connect");	    close(sockFD);	    sockFD = -1;	    return (ERROR);	}	if (!putToFile) {#ifndef GUI	    filePtr = stdout;#else            filePtr = outputfile;#endif	} else {	    filePtr = AppOpenFile(string, file);	    if (filePtr == NULL) {		fprintf(stderr, "*** Can't open %s for writing\n", file);		close(sockFD);		sockFD = -1;		return(ERROR);	    }	    fprintf(filePtr,"> %s\n", string);	}	fprintf(filePtr, "[%s]\n", curHostInfo.name);	if (name[0] != '\0') {#ifndef WINNT	    write(sockFD, "/W ", 3);        	}	write(sockFD, name, strlen(name));	write(sockFD, "\r\n", 2);#else   /* send(sockFD,"/W",3,0); */         }	send(sockFD, name, strlen(name),0);	send(sockFD, "\r\n", 2,0);	#endif#ifndef WINNT		f = fdopen(sockFD, "r"); 	lastc = '\n';	while ((c = getc(f)) != EOF) {	    switch (c) {		case 0210:		case 0211:		case 0212:		case 0214:			c -= 0200;			break;		case 0215:			c = '\n';			break;	    }	    putc(lastc = c, filePtr);	}#else    while ((numread = recv(sockFD,(char *)f,4999,0)) != 0)      {	   for (i=0; i<=numread; i++)        {          c = f[i];          switch (c)           {		    case 0210:		    case 0211:		    case 0212:		    case 0214:	  		      c -= 0200;			      break;		    case 0215:			     c = '\n';			     break;	       }	        putc(lastc = c, filePtr);      }             } #endif	if (lastc != '\n') 	  {	    putc('\n', filePtr);	  }	  putc('\n', filePtr);	close(sockFD);	sockFD = -1;	if (putToFile) {	    fclose(filePtr);	    filePtr = NULL;	}	return (SUCCESS);}voidListHost_close(){    if (sockFD != -1) {	(void) close(sockFD);	sockFD = -1;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -