[git commit] inet/resolv: add dn_skipname and ns_name_skip

Daniel Mack zonque at gmail.com
Fri Aug 26 07:49:56 UTC 2011


commit: http://git.uclibc.org/uClibc/commit/?id=95ff96497d513e89675eabef2f052cabb96e4080
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/master

One uses the other, so add them in one go.

Signed-off-by: Daniel Mack <zonque at gmail.com>
---
 include/resolv.h   |    4 ++--
 libc/inet/resolv.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/include/resolv.h b/include/resolv.h
index 0afb375..6556365 100644
--- a/include/resolv.h
+++ b/include/resolv.h
@@ -336,8 +336,8 @@ __END_DECLS
 #endif
 #define dn_comp			__dn_comp
 #define dn_expand		__dn_expand
-#if 0
 #define dn_skipname		__dn_skipname
+#if 0
 #define fp_resstat		__fp_resstat
 #define loc_aton		__loc_aton
 #define loc_ntoa		__loc_ntoa
@@ -388,7 +388,6 @@ int		b64_ntop (u_char const *, size_t, char *, size_t) __THROW;
 int		b64_pton (char const *, u_char *, size_t) __THROW;
 int		loc_aton (const char *ascii, u_char *binary) __THROW;
 const char *	loc_ntoa (const u_char *binary, char *ascii) __THROW;
-int		dn_skipname (const u_char *, const u_char *) __THROW;
 void		putlong (u_int32_t, u_char *) __THROW;
 void		putshort (u_int16_t, u_char *) __THROW;
 const char *	p_class (int) __THROW;
@@ -405,6 +404,7 @@ const char *	p_option (u_long option) __THROW;
 char *		p_secstodate (u_long) __THROW;
 int		dn_count_labels (const char *) __THROW;
 #endif
+int		dn_skipname (const u_char *, const u_char *) __THROW;
 int		dn_comp (const char *, u_char *, int, u_char **, u_char **)
      __THROW;
 int		dn_expand (const u_char *, const u_char *, const u_char *,
diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
index a74ab30..6bfe52c 100644
--- a/libc/inet/resolv.c
+++ b/libc/inet/resolv.c
@@ -3348,6 +3348,58 @@ int ns_name_compress(const char *src,
 
 	return ns_name_pack(tmp, dst, dstsiz, dnptrs, lastdnptr);
 }
+
+int ns_name_skip(const unsigned char **ptrptr,
+				 const unsigned char *eom)
+{
+	const unsigned char *cp;
+	u_int n;
+	int l;
+
+	cp = *ptrptr;
+	while (cp < eom && (n = *cp++) != 0) {
+		/* Check for indirection. */
+		switch (n & NS_CMPRSFLGS) {
+		case 0:		 /*%< normal case, n == len */
+			cp += n;
+			continue;
+		case NS_TYPE_ELT: /*%< EDNS0 extended label */
+			if ((l = labellen(cp - 1)) < 0) {
+				errno = EMSGSIZE; /*%< XXX */
+				return -1;
+			}
+			cp += l;
+			continue;
+		case NS_CMPRSFLGS:      /*%< indirection */
+			cp++;
+			break;
+		default:		/*%< illegal type */
+			errno = EMSGSIZE;
+			return -1;
+		}
+
+		break;
+	}
+
+	if (cp > eom) {
+		errno = EMSGSIZE;
+		return -1;
+	}
+
+	*ptrptr = cp;
+
+	return 0;
+}
+
+int dn_skipname(const unsigned char *ptr, const unsigned char *eom)
+{
+	const unsigned char *saveptr = ptr;
+
+	if (ns_name_skip(&ptr, eom) == -1)
+		return -1;
+
+	return ptr - saveptr;
+}
 #endif /* L_ns_name */
 
 
-- 
1.7.3.4



More information about the uClibc-cvs mailing list