Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Add res_randomid #8

Closed
doughdemon opened this issue Jun 18, 2015 · 6 comments
Closed

Add res_randomid #8

doughdemon opened this issue Jun 18, 2015 · 6 comments
Assignees

Comments

@doughdemon
Copy link

libasr has copied many resolver functions from OpenBSD. However the function res_randomid(), which is used in res_send_async() and res_mkquery() seems to have been forgotten.

Because of this libasr currently only works with glibc and uclibc>=0.9.33 as these libc's provide the function. It however seems to be a non-standard function with no real documentation.

Could res_randomid() be provided, inclusion possibly depending on a configure test?

@poolpOrg
Copy link
Member

This is a known issue, I recently got access to a Linux distro with a musl based libc which lacks res_randomid(), this will be worked out in a very near future.

@poolpOrg poolpOrg self-assigned this Jun 19, 2015
@ncopa
Copy link

ncopa commented Jun 19, 2015

I googled and found glibc's implementation:

u_int
res_randomid(void) {
    return 0xffff & __getpid();
}

and they call it random??? 👎

Good news is that it should be trivial to fix.

@ncopa
Copy link

ncopa commented Jun 19, 2015

Quick and dirty hack. We probably want something better though.

diff --git a/configure.ac b/configure.ac
index 10aff04..07e149f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -456,6 +456,7 @@ AC_CHECK_FUNCS([ \
        issetugid \
        memmove \
        reallocarray \
+       res_randomid \
        snprintf \
        strdup \
        strerror \
diff --git a/src/asr_private.h b/src/asr_private.h
index 0960e37..254e83e 100644
--- a/src/asr_private.h
+++ b/src/asr_private.h
@@ -365,3 +365,7 @@ extern FILE * asr_debug;
                asr_statestr((a)->as_state),    \
                asr_statestr((s)));             \
        (a)->as_state = (s); } while (0)
+
+#ifndef HAVE_RES_RANDOMID
+#define res_randomid(x) (0xfff & getpid())
+#endif

@poolpOrg
Copy link
Member

neither @ericfaurot or I feel comfortable with mimic-ing the glibc dumb res_randomid()

with a little bit of work, we should be able to bring an arc4random()-based one relying on the arc4random() from the portable layer.

@ncopa
Copy link

ncopa commented Jun 23, 2015

That was what I wanted to hear. Thanks!

@poolpOrg
Copy link
Member

this has been opened for way too long, I've merged a diff very similar to yours, eric can improve further when he gets a better idea.

thanks !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants