>Synopsis: getting a dig compatible vis is hard >Category: library >Environment: System : OpenBSD 7.2 Details : OpenBSD 7.2 (GENERIC.MP) #2: Thu Nov 24 23:53:03 MST 2022 r...@syspatch-72-arm64.openbsd.org:/usr/src/sys/arch/arm64/compile/GENERIC.MP
Architecture: OpenBSD.arm64 Machine : arm64 >Description: I'm trying to vis my program and make an output like dig(1) but it doesn't work because it's like an octal number \027 but in decimal. This would make it easy for my dns program to use vis. I have made a patch to OpenBSD 7.2 which I checked that the versions are right. This seems like something I tried to get committed before but my research with google didn't find it. >How-To-Repeat: >From dig: ;; QUESTION SECTION: ;mapping33.dtschland.eu. IN TXT ;; ANSWER SECTION: mapping33.dtschland.eu. 72891 IN TXT "\027test" notice it took me some understanding that in dig \000 is decimal after RFC 1035 section 5.1. >Fix: I have made patches for your consideration. I can only hope it will be included for 7.4. It's not tested but if put in snapshots I'll dedicate a machine to testing this. Index: include/vis.h =================================================================== RCS file: /cvs/src/include/vis.h,v retrieving revision 1.15 diff -u -p -r1.15 vis.h --- include/vis.h 20 Jul 2015 01:52:27 -0000 1.15 +++ include/vis.h 27 Mar 2023 12:40:06 -0000 @@ -52,6 +52,7 @@ #define VIS_SAFE 0x20 /* only encode "unsafe" characters */ #define VIS_DQ 0x200 /* backslash-escape double quotes */ #define VIS_ALL 0x400 /* encode all characters */ +#define VIS_DNS 0x800 /* for RFC 1035 section 5.1 escapes */ /* * other Index: lib/libc/gen/vis.3 =================================================================== RCS file: /cvs/src/lib/libc/gen/vis.3,v retrieving revision 1.37 diff -u -p -r1.37 vis.3 --- lib/libc/gen/vis.3 30 Jul 2022 07:19:30 -0000 1.37 +++ lib/libc/gen/vis.3 27 Mar 2023 12:40:06 -0000 @@ -27,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: July 30 2022 $ +.Dd $Mdocdate: March 27 2023 $ .Dt VIS 3 .Os .Sh NAME @@ -285,6 +285,11 @@ The form is where .Ar d represents an octal digit. +.It Dv VIS_DNS +Use a three digit decimal sequence like the command +.Xr dig 1 +which is a backslash followed by three decimal letters. This coincides with +RFC 1035 section 5.1. .El .Pp There is one additional flag, Index: lib/libc/gen/vis.c =================================================================== RCS file: /cvs/src/lib/libc/gen/vis.c,v retrieving revision 1.26 diff -u -p -r1.26 vis.c --- lib/libc/gen/vis.c 4 May 2022 18:57:50 -0000 1.26 +++ lib/libc/gen/vis.c 27 Mar 2023 12:40:06 -0000 @@ -83,6 +83,7 @@ vis(char *dst, int c, int flag, int next int vis_cstyle = flag & VIS_CSTYLE; int vis_octal = flag & VIS_OCTAL; int vis_glob = flag & VIS_GLOB; + int vis_dns = flag & VIS_DNS; if (isvisible(c, flag)) { if ((c == '"' && vis_dq) || @@ -134,6 +135,17 @@ vis(char *dst, int c, int flag, int next *dst++ = '0'; *dst++ = '0'; } + goto done; + } + } + if (vis_dns) { + /* reversed from /usr/src/usr.bin/dig/lib/dns/name.c */ + if (c < 0x20 || c > 0x7f) { + *dst++ = '\\'; + *dst++ = 0x30 + ((c / 100) % 10); + *dst++ = 0x30 + ((c / 10) % 10); + *dst++ = 0x30 + (c % 10); + goto done; } } dmesg: my box hasn't changed yet.