Browse Source

libc/inet/resolv.c: use dn_{comp,expand} for __{en,de}code_dotted

Minimal-invasive change: just ifdeffing away the older code.

There is no reason to have two different sets of functions doing
the same thing, one used in half the code and another, doing less
escaping, in the other half; just use one.

Signed-off-by: mirabilos <mirabilos@evolvis.org>
mirabilos 2 years ago
parent
commit
8d96343468
1 changed files with 9 additions and 0 deletions
  1. 9 0
      libc/inet/resolv.c

+ 9 - 0
libc/inet/resolv.c

@@ -11,6 +11,7 @@
 /*
 /*
  * Portions Copyright (c) 1985, 1993
  * Portions Copyright (c) 1985, 1993
  *    The Regents of the University of California.  All rights reserved.
  *    The Regents of the University of California.  All rights reserved.
+ * Portions Copyright © 2021 mirabilos <m@mirbsd.org>
  *
  *
  * Redistribution and use in source and binary forms, with or without
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * modification, are permitted provided that the following conditions
@@ -559,6 +560,9 @@ void __decode_header(unsigned char *data,
    the data */
    the data */
 int __encode_dotted(const char *dotted, unsigned char *dest, int maxlen)
 int __encode_dotted(const char *dotted, unsigned char *dest, int maxlen)
 {
 {
+#ifndef WHY_UCLIBC_WHY_DID_YOU_DO_THIS
+	return (dn_comp(dotted, dest, maxlen, NULL, NULL));
+#else
 	unsigned used = 0;
 	unsigned used = 0;
 
 
 	while (dotted && *dotted) {
 	while (dotted && *dotted) {
@@ -587,6 +591,7 @@ int __encode_dotted(const char *dotted, unsigned char *dest, int maxlen)
 	dest[used++] = 0;
 	dest[used++] = 0;
 
 
 	return used;
 	return used;
+#endif
 }
 }
 #endif /* L_encoded */
 #endif /* L_encoded */
 
 
@@ -601,6 +606,9 @@ int __decode_dotted(const unsigned char *packet,
 		char *dest,
 		char *dest,
 		int dest_len)
 		int dest_len)
 {
 {
+#ifndef WHY_UCLIBC_WHY_DID_YOU_DO_THIS
+	return (dn_expand(packet, packet + packet_len, packet + offset, dest, dest_len));
+#else
 	unsigned b;
 	unsigned b;
 	bool measure = 1;
 	bool measure = 1;
 	unsigned total = 0;
 	unsigned total = 0;
@@ -658,6 +666,7 @@ int __decode_dotted(const unsigned char *packet,
 	DPRINTF("Total decode len = %d\n", total);
 	DPRINTF("Total decode len = %d\n", total);
 
 
 	return total;
 	return total;
+#endif
 }
 }
 #endif /* L_decoded */
 #endif /* L_decoded */