fix warnings and some windows compatibility issues in enum/udns

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4167 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2007-02-08 19:23:36 +00:00
parent d8f906850b
commit e7d0aaef27
6 changed files with 57 additions and 30 deletions

View File

@ -58,6 +58,13 @@ struct sockaddr;
/**************************************************************************/
/**************** Common definitions **************************************/
#ifdef WIN32
#include "winsock2.h"
typedef SOCKET dns_socket;
#else
typedef int dns_socket
#endif
UDNS_API const char *
dns_version(void);
@ -352,7 +359,7 @@ UDNS_DATA_API extern struct dns_ctx dns_defctx;
/* initialize default resolver context and open it if do_open is true.
* <0 on failure. */
UDNS_API int
UDNS_API dns_socket
dns_init(int do_open);
/* return new resolver context with the same settings as copy */
@ -408,11 +415,11 @@ UDNS_API void
dns_set_dbgfn(struct dns_ctx *ctx, dns_dbgfn *dbgfn);
/* open and return UDP socket */
UDNS_API int
UDNS_API dns_socket
dns_open(struct dns_ctx *ctx);
/* return UDP socket or -1 if not open */
UDNS_API int
UDNS_API dns_socket
dns_sock(const struct dns_ctx *ctx);
/* close the UDP socket */

View File

@ -82,7 +82,7 @@ dns_ptodn(const char *name, unsigned namelen,
while(np < ne) {
if (*np == '.') { /* label delimiter */
c = dp - llab; /* length of the label */
c = (unsigned)(dp - llab); /* length of the label */
if (!c) { /* empty label */
if (np == (dnscc_t *)name && np + 1 == ne) {
/* special case for root dn, aka `.' */
@ -131,7 +131,7 @@ dns_ptodn(const char *name, unsigned namelen,
*dp++ = (dnsc_t)c; /* place next out byte */
}
if ((c = dp - llab) > DNS_MAXLABEL)
if ((c = (unsigned)(dp - llab)) > DNS_MAXLABEL)
return -1; /* label too long */
if ((llab[-1] = (dnsc_t)c) != 0) {
*dp++ = 0;
@ -141,7 +141,7 @@ dns_ptodn(const char *name, unsigned namelen,
else if (isabs)
*isabs = 1;
return dp - dn;
return (int)(dp - dn);
}
dnscc_t dns_inaddr_arpa_dn[14] = "\07in-addr\04arpa";
@ -169,7 +169,7 @@ dns_a4todn_(const struct in_addr *addr, dnsc_t *dn, dnsc_t *dne) {
if (p > dne) return 0;
*p = n + '0';
}
*dn = p - dn;
*dn = (dnsc_t)(p - dn);
dn = p + 1;
}
return dn;
@ -187,7 +187,7 @@ int dns_a4todn(const struct in_addr *addr, dnscc_t *tdn,
l = dns_dnlen(tdn);
if (p + l > dne) return dnsiz >= DNS_MAXDN ? -1 : 0;
memcpy(p, tdn, l);
return (p + l) - dn;
return (int)((p + l) - dn);
}
int dns_a4ptodn(const struct in_addr *addr, const char *tname,
@ -232,7 +232,7 @@ int dns_a6todn(const struct in6_addr *addr, dnscc_t *tdn,
l = dns_dnlen(tdn);
if (p + l > dne) return dnsiz >= DNS_MAXDN ? -1 : 0;
memcpy(p, tdn, l);
return (p + l) - dn;
return (int)((p + l) - dn);
}
int dns_a6ptodn(const struct in6_addr *addr, const char *tname,
@ -331,7 +331,7 @@ int dns_dntop(dnscc_t *dn, char *name, unsigned namesiz) {
}
if (np >= ne) goto toolong;
*np++ = '\0';
return np - name;
return (int)(np - name);
toolong:
return namesiz >= DNS_MAXNAME ? -1 : 0;
}

View File

@ -60,7 +60,7 @@ dns_getdn(dnscc_t *pkt, dnscc_t **cur, dnscc_t *end,
*dp++ = 0;
/* return next pos: either after the first jump or current */
*cur = jump ? jump : pp;
return dp - dn;
return (int)(dp - dn);
}
if (c & 192) { /* jump */
if (pp >= end) /* eop instead of jump pos */

View File

@ -22,6 +22,18 @@
*/
#ifdef WIN32
#ifdef _MSC_VER
#if (_MSC_VER >= 1400) // VC8+
#ifndef _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE
#endif
#ifndef _CRT_NONSTDC_NO_DEPRECATE
#define _CRT_NONSTDC_NO_DEPRECATE
#endif
#endif // VC8+
#include "inet_pton.h"
#include "process.h"
#endif
# include <winsock2.h> /* includes <windows.h> */
# include <ws2tcpip.h> /* needed for struct in6_addr */
# include <iphlpapi.h> /* for dns server addresses etc */
@ -187,7 +199,7 @@ struct dns_ctx { /* resolver context */
/* dynamic data */
unsigned short dnsc_nextid; /* next queue ID to use */
int dnsc_udpsock; /* UDP socket */
dns_socket dnsc_udpsock; /* UDP socket */
struct dns_qlink dnsc_qactive; /* active list sorted by deadline */
int dnsc_nactive; /* number entries in dnsc_qactive */
dnsc_t *dnsc_pbuf; /* packet buffer (udpbuf size) */
@ -225,7 +237,14 @@ struct dns_ctx dns_defctx;
#define SETCTXFRESH(ctx) SETCTXINITED(ctx); assert(!CTXOPEN(ctx))
#define SETCTXINACTIVE(ctx) SETCTXINITED(ctx); assert(qlist_empty(&ctx->dnsc_qactive))
#define SETCTXOPEN(ctx) SETCTXINITED(ctx); assert(CTXOPEN(ctx))
#ifdef WIN32
#define CTXOPEN(ctx) (ctx->dnsc_udpsock != INVALID_SOCKET )
#else
#define CTXOPEN(ctx) (ctx->dnsc_udpsock >= 0)
#ifndef INVALID_SOCKET
#define INVALID_SOCKET -1
#endif
#endif
#if defined(NDEBUG) || !defined(DEBUG)
#define dns_assert_ctx(ctx)
@ -321,7 +340,7 @@ int dns_add_serv_s(struct dns_ctx *ctx, const struct sockaddr *sa) {
}
static void dns_set_opts_internal(struct dns_ctx *ctx, const char *opts) {
unsigned i, v;
size_t i, v;
for(;;) {
while(ISSPACE(*opts)) ++opts;
if (!*opts) break;
@ -337,7 +356,7 @@ static void dns_set_opts_internal(struct dns_ctx *ctx, const char *opts) {
while (*opts >= '0' && *opts <= '9');
if (dns_opts[i].min && v < dns_opts[i].min) v = dns_opts[i].min;
else if (v > dns_opts[i].max) v = dns_opts[i].max;
dns_ctxopt(ctx, dns_opts[i].offset) = v;
dns_ctxopt(ctx, dns_opts[i].offset) = (unsigned)v;
break;
}
while(*opts && !ISSPACE(*opts)) ++opts;
@ -420,7 +439,7 @@ dns_request_utm(struct dns_ctx *ctx, time_t now) {
else if (!now || q->dnsq_deadline <= now)
deadline = 0, timeout = 0;
else
deadline = q->dnsq_deadline, timeout = deadline - now;
deadline = q->dnsq_deadline, timeout = (int)(deadline - now);
if (ctx->dnsc_utmexp == deadline)
return;
ctx->dnsc_utmfn(ctx, timeout, ctx->dnsc_utmctx);
@ -608,10 +627,10 @@ static int dns_init_internal(struct dns_ctx *ctx) {
static void dns_firstid(struct dns_ctx *ctx) {
struct timeval tv;
gettimeofday(&tv, NULL);
ctx->dnsc_nextid = (tv.tv_usec ^ getpid()) & 0xffff;
ctx->dnsc_nextid = (unsigned short)((tv.tv_usec ^ getpid()) & 0xffff);
}
int dns_init(int do_open) {
dns_socket dns_init(int do_open) {
struct dns_ctx *ctx = &dns_defctx;
assert(!CTXINITED(ctx));
memset(ctx, 0, sizeof(*ctx));
@ -620,7 +639,7 @@ int dns_init(int do_open) {
ctx->dnsc_ndots = 1;
ctx->dnsc_udpbuf = DNS_EDNS0PACKET;
ctx->dnsc_port = DNS_PORT;
ctx->dnsc_udpsock = -1;
ctx->dnsc_udpsock = INVALID_SOCKET;
qlist_init(&ctx->dnsc_qactive);
if (dns_init_internal(ctx) != 0)
return -1;
@ -637,7 +656,7 @@ struct dns_ctx *dns_new(const struct dns_ctx *ctx) {
if (!n)
return NULL;
*n = *ctx;
n->dnsc_udpsock = -1;
n->dnsc_udpsock = INVALID_SOCKET;
qlist_init(&n->dnsc_qactive);
n->dnsc_nactive = 0;
n->dnsc_pbuf = NULL;
@ -665,8 +684,8 @@ void dns_free(struct dns_ctx *ctx) {
memset(ctx, 0, sizeof(*ctx));
}
int dns_open(struct dns_ctx *ctx) {
int sock;
dns_socket dns_open(struct dns_ctx *ctx) {
dns_socket sock;
unsigned i;
int port;
union sockaddr_ns *sns;
@ -768,12 +787,12 @@ void dns_close(struct dns_ctx *ctx) {
SETCTXINITED(ctx);
if (ctx->dnsc_udpsock < 0) return;
closesocket(ctx->dnsc_udpsock);
ctx->dnsc_udpsock = -1;
ctx->dnsc_udpsock = INVALID_SOCKET;
free(ctx->dnsc_pbuf);
ctx->dnsc_pbuf = NULL;
}
int dns_sock(const struct dns_ctx *ctx) {
dns_socket dns_sock(const struct dns_ctx *ctx) {
SETCTXINITED(ctx);
return ctx->dnsc_udpsock;
}
@ -983,7 +1002,7 @@ dns_submit_dn(struct dns_ctx *ctx,
q->dnsq_buf[DNS_H_ARCNT2] = 1;
}
assert(p <= q->dnsq_buf + DNS_QBUF);
q->dnsq_len = p - q->dnsq_buf;
q->dnsq_len = (unsigned)(p - q->dnsq_buf);
qlist_add_head(q, &ctx->dnsc_qactive);
++ctx->dnsc_nactive;
@ -1248,7 +1267,7 @@ int dns_timeouts(struct dns_ctx *ctx, int maxwait, time_t now) {
dns_request_utm(ctx, now);
if (!q)
return maxwait;
w = q->dnsq_deadline - now;
w = (int)(q->dnsq_deadline - now);
return maxwait < 0 || maxwait > w ? w : maxwait;
}
@ -1306,7 +1325,7 @@ void *dns_resolve(struct dns_ctx *ctx, struct dns_query *q) {
tv.tv_sec = n;
tv.tv_usec = 0;
FD_SET(ctx->dnsc_udpsock, &rfd);
n = select(ctx->dnsc_udpsock + 1, &rfd, NULL, NULL, &tv);
n = select((int)(ctx->dnsc_udpsock + 1), &rfd, NULL, NULL, &tv);
#endif
now = time(NULL);
if (n > 0)

View File

@ -75,7 +75,7 @@ dns_parse_txt(dnscc_t *qdn, dnscc_t *pkt, dnscc_t *cur, dnscc_t *end,
sp += l;
cp += l;
}
ret->dnstxt_txt[r].len = sp - ret->dnstxt_txt[r].txt;
ret->dnstxt_txt[r].len = (int)(sp - ret->dnstxt_txt[r].txt);
*sp++ = '\0';
}
dns_stdrr_finish((struct dns_rr_null *)ret, (char*)sp, &p);

View File

@ -423,7 +423,8 @@ static switch_status_t enum_lookup(char *root, char *in, enum_record_t **results
char *name = NULL;
enum_query_t query = {0};
enum dns_type l_qtyp = DNS_T_NAPTR;
int i = 0, fd = -1, abs = 0;
int i = 0, abs = 0;
dns_socket fd = (dns_socket)-1;
fd_set fds;
struct timeval tv = {0};
time_t now = 0;
@ -484,7 +485,7 @@ static switch_status_t enum_lookup(char *root, char *in, enum_record_t **results
#endif
tv.tv_sec = i;
tv.tv_usec = 0;
i = select(fd+1, &fds, 0, 0, &tv);
i = select((int)(fd+1), &fds, 0, 0, &tv);
now = time(NULL);
if (i > 0) dns_ioevent(nctx, now);
}
@ -500,7 +501,7 @@ static switch_status_t enum_lookup(char *root, char *in, enum_record_t **results
if (fd > -1) {
closesocket(fd);
fd = -1;
fd = (dns_socket)-1;
}
if (nctx) {