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

📄 res_mkupdate.c

📁 bind 9.3结合mysql数据库
💻 C
📖 第 1 页 / 共 2 页
字号:
			cp += n;			ShrinkBuffer(n);			maxtype = 0;			memset(data, 0, sizeof data);			for (;;) {				if (!getword_str(buf2, sizeof buf2, &startp,						 endp))					break;				nxt_type = sym_ston(__p_type_syms, buf2,						    &success);				if (!success || !ns_t_rr_p(nxt_type))					return (-1);				NS_NXT_BIT_SET(nxt_type, data);				if (nxt_type > maxtype)					maxtype = nxt_type;			}			n = maxtype/NS_NXT_BITS+1;			ShrinkBuffer(n);			memcpy(cp, data, n);			cp += n;			break;		    }		case ns_t_cert:			/* type */			n = getnum_str(&startp, endp);			if (n < 0)				return (-1);			ShrinkBuffer(INT16SZ);			PUTSHORT(n, cp);			/* key tag */			n = getnum_str(&startp, endp);			if (n < 0)				return (-1);			ShrinkBuffer(INT16SZ);			PUTSHORT(n, cp);			/* alg */			n = getnum_str(&startp, endp);			if (n < 0)				return (-1);			ShrinkBuffer(1);			*cp++ = n;			/* cert */			if ((n = getword_str(buf2, sizeof buf2,					     &startp, endp)) < 0)				return (-1);			certlen = b64_pton(buf2, buf3, sizeof(buf3));			if (certlen < 0)				return (-1);			ShrinkBuffer(certlen);			memcpy(cp, buf3, certlen);			cp += certlen;			break;		case ns_t_aaaa:			if (!getword_str(buf2, sizeof buf2, &startp, endp))				return (-1);			if (inet_pton(AF_INET6, buf2, &in6a) <= 0)				return (-1);			ShrinkBuffer(NS_IN6ADDRSZ);			memcpy(cp, &in6a, NS_IN6ADDRSZ);			cp += NS_IN6ADDRSZ;			break;		case ns_t_naptr:			/* Order Preference Flags Service Replacement Regexp */			/* Order */			n = getnum_str(&startp, endp);			if (n < 0 || n > 65535)				return (-1);			ShrinkBuffer(INT16SZ);			PUTSHORT(n, cp);			/* Preference */			n = getnum_str(&startp, endp);			if (n < 0 || n > 65535)				return (-1);			ShrinkBuffer(INT16SZ);			PUTSHORT(n, cp);			/* Flags */			if ((n = getstr_str(buf2, sizeof buf2,					&startp, endp)) < 0) {				return (-1);			}			if (n > 255)				return (-1);			ShrinkBuffer(n+1);			*cp++ = n;			memcpy(cp, buf2, n);			cp += n;			/* Service Classes */			if ((n = getstr_str(buf2, sizeof buf2,					&startp, endp)) < 0) {				return (-1);			}			if (n > 255)				return (-1);			ShrinkBuffer(n+1);			*cp++ = n;			memcpy(cp, buf2, n);			cp += n;			/* Pattern */			if ((n = getstr_str(buf2, sizeof buf2,					&startp, endp)) < 0) {				return (-1);			}			if (n > 255)				return (-1);			ShrinkBuffer(n+1);			*cp++ = n;			memcpy(cp, buf2, n);			cp += n;			/* Replacement */			if (!getword_str(buf2, sizeof buf2, &startp, endp))				return (-1);			n = dn_comp(buf2, cp, buflen, NULL, NULL);			if (n < 0)				return (-1);			cp += n;			ShrinkBuffer(n);			break;		default:			return (-1);		} /*switch*/		n = (u_int16_t)((cp - sp2) - INT16SZ);		PUTSHORT(n, sp2);	} /*for*/			hp->qdcount = htons(counts[0]);	hp->ancount = htons(counts[1]);	hp->nscount = htons(counts[2]);	hp->arcount = htons(counts[3]);	return (cp - buf);}/* * Get a whitespace delimited word from a string (not file) * into buf. modify the start pointer to point after the * word in the string. */static intgetword_str(char *buf, int size, u_char **startpp, u_char *endp) {        char *cp;        int c;         for (cp = buf; *startpp <= endp; ) {                c = **startpp;                if (isspace(c) || c == '\0') {                        if (cp != buf) /* trailing whitespace */                                break;                        else { /* leading whitespace */                                (*startpp)++;                                continue;                        }                }                (*startpp)++;                if (cp >= buf+size-1)                        break;                *cp++ = (u_char)c;        }        *cp = '\0';        return (cp != buf);}/* * get a white spae delimited string from memory.  Process quoted strings * and \DDD escapes.  Return length or -1 on error.  Returned string may * contain nulls. */static char digits[] = "0123456789";static intgetstr_str(char *buf, int size, u_char **startpp, u_char *endp) {        char *cp;        int c, c1 = 0;	int inquote = 0;	int seen_quote = 0;	int escape = 0;	int dig = 0; 	for (cp = buf; *startpp <= endp; ) {                if ((c = **startpp) == '\0')			break;		/* leading white space */		if ((cp == buf) && !seen_quote && isspace(c)) {			(*startpp)++;			continue;		}		switch (c) {		case '\\':			if (!escape)  {				escape = 1;				dig = 0;				c1 = 0;				(*startpp)++;				continue;			} 			goto do_escape;		case '"':			if (!escape) {				inquote = !inquote;				seen_quote = 1;				(*startpp)++;				continue;			}			/* fall through */		default:		do_escape:			if (escape) {				switch (c) {				case '0':				case '1':				case '2':				case '3':				case '4':				case '5':				case '6':				case '7':				case '8':				case '9':					c1 = c1 * 10 + 						(strchr(digits, c) - digits);					if (++dig == 3) {						c = c1 &0xff;						break;					}					(*startpp)++;					continue;				}				escape = 0;			} else if (!inquote && isspace(c))				goto done;			if (cp >= buf+size-1)				goto done;			*cp++ = (u_char)c;			(*startpp)++;		}	} done:	*cp = '\0';	return ((cp == buf)?  (seen_quote? 0: -1): (cp - buf));}/* * Get a whitespace delimited base 16 number from a string (not file) into buf * update the start pointer to point after the number in the string. */static intgethexnum_str(u_char **startpp, u_char *endp) {        int c, n;        int seendigit = 0;        int m = 0;	if (*startpp + 2 >= endp || strncasecmp((char *)*startpp, "0x", 2) != 0)		return getnum_str(startpp, endp);	(*startpp)+=2;        for (n = 0; *startpp <= endp; ) {                c = **startpp;                if (isspace(c) || c == '\0') {                        if (seendigit) /* trailing whitespace */                                break;                        else { /* leading whitespace */                                (*startpp)++;                                continue;                        }                }                if (c == ';') {                        while ((*startpp <= endp) &&			       ((c = **startpp) != '\n'))					(*startpp)++;                        if (seendigit)                                break;                        continue;                }                if (!isxdigit(c)) {                        if (c == ')' && seendigit) {                                (*startpp)--;                                break;                        }			return (-1);                }                        (*startpp)++;		if (isdigit(c))	                n = n * 16 + (c - '0');		else			n = n * 16 + (tolower(c) - 'a' + 10);                seendigit = 1;        }        return (n + m);}/* * Get a whitespace delimited base 10 number from a string (not file) into buf * update the start pointer to point after the number in the string. */static intgetnum_str(u_char **startpp, u_char *endp) {        int c, n;        int seendigit = 0;        int m = 0;        for (n = 0; *startpp <= endp; ) {                c = **startpp;                if (isspace(c) || c == '\0') {                        if (seendigit) /* trailing whitespace */                                break;                        else { /* leading whitespace */                                (*startpp)++;                                continue;                        }                }                if (c == ';') {                        while ((*startpp <= endp) &&			       ((c = **startpp) != '\n'))					(*startpp)++;                        if (seendigit)                                break;                        continue;                }                if (!isdigit(c)) {                        if (c == ')' && seendigit) {                                (*startpp)--;                                break;                        }			return (-1);                }                        (*startpp)++;                n = n * 10 + (c - '0');                seendigit = 1;        }        return (n + m);}/* * Allocate a resource record buffer & save rr info. */ns_updrec *res_mkupdrec(int section, const char *dname,	     u_int class, u_int type, u_long ttl) {	ns_updrec *rrecp = (ns_updrec *)calloc(1, sizeof(ns_updrec));	if (!rrecp || !(rrecp->r_dname = strdup(dname))) {		if (rrecp)			free((char *)rrecp);		return (NULL);	}	INIT_LINK(rrecp, r_link);	INIT_LINK(rrecp, r_glink); 	rrecp->r_class = class;	rrecp->r_type = type;	rrecp->r_ttl = ttl;	rrecp->r_section = section;	return (rrecp);}/* * Free a resource record buffer created by res_mkupdrec. */voidres_freeupdrec(ns_updrec *rrecp) {	/* Note: freeing r_dp is the caller's responsibility. */	if (rrecp->r_dname != NULL)		free(rrecp->r_dname);	free(rrecp);}struct valuelist {	struct valuelist *	next;	struct valuelist *	prev;	char *			name;	char *			proto;	int			port;};static struct valuelist *servicelist, *protolist;static voidres_buildservicelist() {	struct servent *sp;	struct valuelist *slp;#ifdef MAYBE_HESIOD	setservent(0);#else	setservent(1);#endif	while ((sp = getservent()) != NULL) {		slp = (struct valuelist *)malloc(sizeof(struct valuelist));		if (!slp)			break;		slp->name = strdup(sp->s_name);		slp->proto = strdup(sp->s_proto);		if ((slp->name == NULL) || (slp->proto == NULL)) {			if (slp->name) free(slp->name);			if (slp->proto) free(slp->proto);			free(slp);			break;		}		slp->port = ntohs((u_int16_t)sp->s_port);  /* host byt order */		slp->next = servicelist;		slp->prev = NULL;		if (servicelist)			servicelist->prev = slp;		servicelist = slp;	}	endservent();}voidres_destroyservicelist() {	struct valuelist *slp, *slp_next;	for (slp = servicelist; slp != NULL; slp = slp_next) {		slp_next = slp->next;		free(slp->name);		free(slp->proto);		free(slp);	}	servicelist = (struct valuelist *)0;}voidres_buildprotolist(void) {	struct protoent *pp;	struct valuelist *slp;#ifdef MAYBE_HESIOD	setprotoent(0);#else	setprotoent(1);#endif	while ((pp = getprotoent()) != NULL) {		slp = (struct valuelist *)malloc(sizeof(struct valuelist));		if (!slp)			break;		slp->name = strdup(pp->p_name);		if (slp->name == NULL) {			free(slp);			break;		}		slp->port = pp->p_proto;	/* host byte order */		slp->next = protolist;		slp->prev = NULL;		if (protolist)			protolist->prev = slp;		protolist = slp;	}	endprotoent();}voidres_destroyprotolist(void) {	struct valuelist *plp, *plp_next;	for (plp = protolist; plp != NULL; plp = plp_next) {		plp_next = plp->next;		free(plp->name);		free(plp);	}	protolist = (struct valuelist *)0;}static intfindservice(const char *s, struct valuelist **list) {	struct valuelist *lp = *list;	int n;	for (; lp != NULL; lp = lp->next)		if (strcasecmp(lp->name, s) == 0) {			if (lp != *list) {				lp->prev->next = lp->next;				if (lp->next)					lp->next->prev = lp->prev;				(*list)->prev = lp;				lp->next = *list;				*list = lp;			}			return (lp->port);	/* host byte order */		}	if (sscanf(s, "%d", &n) != 1 || n <= 0)		n = -1;	return (n);}/* * Convert service name or (ascii) number to int. */intres_servicenumber(const char *p) {	if (servicelist == (struct valuelist *)0)		res_buildservicelist();	return (findservice(p, &servicelist));}/* * Convert protocol name or (ascii) number to int. */intres_protocolnumber(const char *p) {	if (protolist == (struct valuelist *)0)		res_buildprotolist();	return (findservice(p, &protolist));}static struct servent *cgetservbyport(u_int16_t port, const char *proto) {	/* Host byte order. */	struct valuelist **list = &servicelist;	struct valuelist *lp = *list;	static struct servent serv;	port = ntohs(port);	for (; lp != NULL; lp = lp->next) {		if (port != (u_int16_t)lp->port)	/* Host byte order. */			continue;		if (strcasecmp(lp->proto, proto) == 0) {			if (lp != *list) {				lp->prev->next = lp->next;				if (lp->next)					lp->next->prev = lp->prev;				(*list)->prev = lp;				lp->next = *list;				*list = lp;			}			serv.s_name = lp->name;			serv.s_port = htons((u_int16_t)lp->port);			serv.s_proto = lp->proto;			return (&serv);		}	}	return (0);}static struct protoent *cgetprotobynumber(int proto) {				/* Host byte order. */	struct valuelist **list = &protolist;	struct valuelist *lp = *list;	static struct protoent prot;	for (; lp != NULL; lp = lp->next)		if (lp->port == proto) {		/* Host byte order. */			if (lp != *list) {				lp->prev->next = lp->next;				if (lp->next)					lp->next->prev = lp->prev;				(*list)->prev = lp;				lp->next = *list;				*list = lp;			}			prot.p_name = lp->name;			prot.p_proto = lp->port;	/* Host byte order. */			return (&prot);		}	return (0);}const char *res_protocolname(int num) {	static char number[8];	struct protoent *pp;	if (protolist == (struct valuelist *)0)		res_buildprotolist();	pp = cgetprotobynumber(num);	if (pp == 0)  {		(void) sprintf(number, "%d", num);		return (number);	}	return (pp->p_name);}const char *res_servicename(u_int16_t port, const char *proto) {	/* Host byte order. */	static char number[8];	struct servent *ss;	if (servicelist == (struct valuelist *)0)		res_buildservicelist();	ss = cgetservbyport(htons(port), proto);	if (ss == 0)  {		(void) sprintf(number, "%d", port);		return (number);	}	return (ss->s_name);}

⌨️ 快捷键说明

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