On Fri, Jul 8, 2011 at 10:23 AM, Russell Bryant
<russell(a)russellbryant.net> wrote:
On Thu, Jul 7, 2011 at 8:43 AM, Adam Stokes
<astokes(a)fedoraproject.org> wrote:
> - Provide Windows querying for DNS_SRV records
>
> Signed-off-by: Adam Stokes <astokes(a)fedoraproject.org>
> ---
> src/lib/CMakeLists.txt | 9 +++++----
> src/lib/dnssrv_windows.c | 36 +++++++++++++++++++++++++++++++++++-
> 2 files changed, 40 insertions(+), 5 deletions(-)
> diff --git a/src/lib/dnssrv_windows.c b/src/lib/dnssrv_windows.c
> index 32b00ee..776caf8 100644
> --- a/src/lib/dnssrv_windows.c
> +++ b/src/lib/dnssrv_windows.c
> @@ -18,6 +18,18 @@
>
> #include "matahari/dnssrv.h"
>
> +#include <windows.h>
> +#include <winsock.h>
> +#include <windns.h>
> +
> +// mingw doesn't include these
> +#ifndef DNS_TYPE_SRV
> +# define DNS_TYPE_SRV 33
> +#endif
> +
> +#ifndef NS_MAXDNAME
> +# define NS_MAXDNAME 1025
> +#endif
> /**
> * Domain lookup providing a Matahari broker
> *
> @@ -31,5 +43,27 @@
> int
> mh_srv_lookup(const char *query, char *target, size_t len)
> {
> - return -1;
> + PDNS_RECORD rr, record;
> + WCHAR wstr[len];
> +
> +
> + MultiByteToWideChar(CP_UTF8, 0, query, len, wstr, len);
> + if (DnsQuery(wstr, DNS_TYPE_SRV,
> + DNS_QUERY_STANDARD, NULL,
> + &rr, NULL) == ERROR_SUCCESS) {
> +
> + record = rr;
> + do {
> + if (record->wType == DNS_TYPE_SRV) {
> + WideCharToMultiByte(CP_UTF8, 0, wstr, len, target, len, NULL,
NULL);
> + target[len] = '\0';
There is an off by one error here. It should be something like:
if (len > 0) {
target[len - 1] = '\0';
}
> + }
> + record = record->pNext;
> + }
> + while (rr != NULL);
I'm not sure if the coding guidelines cover this, but can you put the
while on the same line as the closing }?
Yes please :-)
> + DnsRecordListFree(rr, DnsFreeRecordList);
> + return 0;
> + } else {
> + return -1;
> + }
> }
> --
> 1.7.6
>
> _______________________________________________
> Matahari mailing list
> Matahari(a)lists.fedorahosted.org
>
https://fedorahosted.org/mailman/listinfo/matahari
>
_______________________________________________
Matahari mailing list
Matahari(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/matahari