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

📄 list.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
     *  If there aren't any, return with an error. We assume     *  there aren't any question records.     */    if (ntohs(headerPtr->ancount) == 0) {	return(NO_INFO);    } else {	if (ntohs(headerPtr->qdcount) > 0) {	    nameLen = dn_skipname(cp, eom);	    if (nameLen < 0)		return (ERROR);	    cp += nameLen + QFIXEDSZ;	}	if ((nameLen = dn_expand(msg, eom, cp, name, sizeof(name))) < 0) {	    return (ERROR);	}	cp += nameLen;	type = _getshort(cp);	cp += sizeof(u_short);	class = _getshort(cp);	cp += sizeof(u_short);	ttl = _getlong(cp);	cp += sizeof(u_long);	dlen = _getshort(cp);	cp += sizeof(u_short);	if (name[0] == 0)		strcpy(name, "(root)");	/*	 * QueryType is used to specify the type of desired information.	 *  T_A   	- internet address	 *  T_CNAME 	- aliases	 *  T_HINFO	- cpu, OS type	 *  T_MX	- mail routing	 *  T_WKS	- well known service	 *  T_ANY	- any	 *	 */	switch (type) {	    case T_A:		if (queryType != T_A && queryType != T_ANY)		    break;		if ((_res.options & RES_DEBUG) == 0)		    STRIP_DOMAIN(name);		fprintf(file, NAME_FORMAT, name);		if (queryType == T_ANY)		    fprintf(file," %-5s", p_type(type));		if (class == C_IN) {		    bcopy(cp, (char *)&inaddr, sizeof(inaddr));		    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);		    if (_res.options & RES_DEBUG)			fprintf(file,"\t\t\t%lu", ttl);		    fprintf(file,"\n");		} else		    goto other;		break;			    case T_CNAME:		if (queryType != T_CNAME && queryType != T_ANY)		    break;		if ((_res.options & RES_DEBUG) == 0)			STRIP_DOMAIN(name);		fprintf(file, NAME_FORMAT, name);		if (queryType == T_ANY)		    fprintf(file," %-5s", p_type(type));		if ((nameLen = dn_expand(msg, eom, cp, name2, sizeof(name2))) < 0) {		    fprintf(file, " ***\n");		    return (ERROR);		}		/* 		 * a bug -- cnames need not be in same domain!		 * STRIP_DOMAIN(name2);		 */		fprintf(file, NAME_FORMAT, name2);		if (_res.options & RES_DEBUG)		    fprintf(file,"\t%lu", ttl);		fprintf(file,"\n");		break;			    case T_HINFO:		if (queryType != T_HINFO && queryType != T_ANY)		    break;		if ((_res.options & RES_DEBUG) == 0)		    STRIP_DOMAIN(name);		fprintf(file, NAME_FORMAT, name);		if (queryType == T_ANY)		    fprintf(file," %-5s", p_type(type));		if (n = *cp++) {		    (void)sprintf(name,"%.*s", n, cp);		    fprintf(file," %-10s", name);		    cp += n;		} else {		    fprintf(file," %-10s", " ");		}		if (n = *cp++) {		    fprintf(file," %.*s", n, cp);		    cp += n;		}		if (_res.options & RES_DEBUG)		    fprintf(file,"\t\t%lu", ttl);		fprintf(file,"\n");		break;	    case T_MX:		if (queryType != T_MX && queryType != T_ANY)		    break;		if ((_res.options & RES_DEBUG) == 0)		    STRIP_DOMAIN(name);		fprintf(file, NAME_FORMAT, name);		if (queryType == T_ANY)		    fprintf(file," %-5s", p_type(type));		{		    short pref;		    pref = _getshort(cp);		    cp += sizeof(u_short);		    fprintf(file," %-3d ",pref);		}		if ((nameLen = dn_expand(msg, eom, cp, name2, sizeof(name2))) < 0) {		    fprintf(file, " ***\n");		    return (ERROR);		}		fprintf(file, " %s", name2);		if (_res.options & RES_DEBUG)		    fprintf(file,"\t%lu", ttl);		fprintf(file,"\n");		break;	    case T_NS:	    case T_PTR:		if (queryType != T_A && queryType != T_ANY)		    break;		/*		 *  Found a name server or pointer record.		 */		if ((_res.options & RES_DEBUG) == 0)		    STRIP_DOMAIN(name);		fprintf(file, NAME_FORMAT, name);		if (queryType == T_ANY)		    fprintf(file," %-5s", p_type(type));		fprintf(file," %s = ", type == T_PTR ? "host" : "server");		cp = Print_cdname2(cp, msg, eom, file);		if (_res.options & RES_DEBUG)		    fprintf(file,"\t%lu", ttl);		fprintf(file,"\n");		break;	    case T_WKS:		if (queryType != T_WKS && queryType != T_ANY)		    break;		if ((_res.options & RES_DEBUG) == 0)		    STRIP_DOMAIN(name);		fprintf(file, NAME_FORMAT, name);		if (queryType == T_ANY)		    fprintf(file," %-5s", p_type(type));		if (class == C_IN) {		    cp += 4; dlen -= 4;		    {			struct protoent *pp;			struct servent *ss;			u_short port;			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," %d", port);				    else					fprintf(file," %s", ss->s_name);				}				    n <<= 1;			    } while(++port & 07);			}		    } 		} else		    goto other;		if (_res.options & RES_DEBUG)		    fprintf(file,"\t%lu", ttl);		fprintf(file,"\n");		endprotoent();		endservent();		break;	    case T_SOA:	    case T_AXFR:		if (queryType != T_ANY)		    break;		fprintf(file, NAME_FORMAT, name);		if (queryType == T_ANY)		    fprintf(file," %-5s", p_type(type));		if ((nameLen = dn_expand(msg, eom, cp, name2, sizeof(name2))) < 0) {		    fprintf(file, " ***\n");		    return (ERROR);		}		cp += nameLen;		fprintf(file, " %s", name2);		if ((nameLen = dn_expand(msg, eom, cp, name2, sizeof(name2))) < 0) {		    fprintf(file, " ***\n");		    return (ERROR);		}		cp += nameLen;		fprintf(file, " %s. (", name2);		for (n = 0; n < 5; n++) {		    u_long u;		    u = _getlong(cp);		    cp += sizeof(u_long);		    fprintf(file,"%s%d", n? " " : "", u);		}		fprintf(file, ")", name2);		if (_res.options & RES_DEBUG)		    fprintf(file,"\t%lu", ttl);		fprintf(file,"\n");		break;	    default:		/*		 * Unwanted answer type -- ignore it.		 */		if (queryType != T_ANY)		    break;		if ((_res.options & RES_DEBUG) == 0)		    STRIP_DOMAIN(name);		fprintf(file, NAME_FORMAT, name);other:		fprintf(file," type = %-5s", p_type(type));		fprintf(file,", class = %-5s", p_class(class));		if (_res.options & RES_DEBUG)		    fprintf(file,"\t%lu\n", ttl);		break;	}    }    return(SUCCESS);}/* ******************************************************************************* * *  ViewList -- * *	A hack to view the output of the ls command in sorted *	order using more. * ******************************************************************************* */ViewList(string)    char *string;{    char file[NAME_LEN];    char command[NAME_LEN];    sscanf(string, " view %s", file);    (void)sprintf(command, "grep \"^ \" %s | sort | more", file);    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;	register FILE 		*f;	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) {	    fprintf(stderr, "Finger: no current host defined.\n");	    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) {	    fprintf(stderr, "Finger: unknown service\n");	    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");	    return (ERROR);	}	if (connect(sockFD, (char *)&sin, sizeof (sin)) < 0) {	    fflush(stdout);	    perror("Finger");	    close(sockFD);	    sockFD = -1;	    return (ERROR);	}	if (!putToFile) {	    filePtr = stdout;	} else {	    filePtr = OpenFile(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') {	    write(sockFD, "/W ", 3);	}	write(sockFD, name, strlen(name));	write(sockFD, "\r\n", 2);	f = fdopen(sockFD, "r");	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);	}	if (lastc != '\n') {	    putc('\n', filePtr);	}	putc('\n', filePtr);	close(sockFD);	sockFD = -1;	if (putToFile) {	    fclose(filePtr);	    filePtr = NULL;	}	return (SUCCESS);}

⌨️ 快捷键说明

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