Dolda2000 GitWeb
/
doldaconnect.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Comment getsrvrr.
[doldaconnect.git]
/
lib
/
uilib.c
diff --git
a/lib/uilib.c
b/lib/uilib.c
index
4d440de
..
26958a7
100644
(file)
--- a/
lib/uilib.c
+++ b/
lib/uilib.c
@@
-47,7
+47,9
@@
#endif
#include <doldaconnect/uilib.h>
#endif
#include <doldaconnect/uilib.h>
-#include <doldaconnect/utils.h>
+#include <utils.h>
+
+#define DOLCON_SRV_NAME "_dolcon._tcp"
#define RESP_END -1
#define RESP_DSC 0
#define RESP_END -1
#define RESP_DSC 0
@@
-472,6
+474,7
@@
int dc_handleread(void)
int ret, done;
char *p1, *p2;
size_t len;
int ret, done;
char *p1, *p2;
size_t len;
+ socklen_t optlen;
int errnobak;
/* Ewww... this really is soo ugly. I need to clean this up some day. */
static int pstate = 0;
int errnobak;
/* Ewww... this really is soo ugly. I need to clean this up some day. */
static int pstate = 0;
@@
-481,7
+484,8
@@
int dc_handleread(void)
static size_t cbufsize = 0, cbufdata = 0;
static wchar_t *pptr = NULL;
static wchar_t **argv = NULL;
static size_t cbufsize = 0, cbufdata = 0;
static wchar_t *pptr = NULL;
static wchar_t **argv = NULL;
- static int argc = 0, args = 0;
+ static int argc = 0;
+ static size_t args = 0;
static wchar_t *cw = NULL;
static size_t cwsize = 0, cwdata = 0;
static struct dc_response *curresp = NULL;
static wchar_t *cw = NULL;
static size_t cwsize = 0, cwdata = 0;
static struct dc_response *curresp = NULL;
@@
-493,8
+497,8
@@
int dc_handleread(void)
case -1:
return(-1);
case 0:
case -1:
return(-1);
case 0:
- len = sizeof(ret);
- getsockopt(fd, SOL_SOCKET, SO_ERROR, &ret, &len);
+
opt
len = sizeof(ret);
+ getsockopt(fd, SOL_SOCKET, SO_ERROR, &ret, &
opt
len);
if(ret)
{
int newfd;
if(ret)
{
int newfd;
@@
-782,6
+786,10
@@
int dc_handlewrite(void)
}
#ifdef HAVE_RESOLVER
}
#ifdef HAVE_RESOLVER
+/*
+ * It kind of sucks that libresolv doesn't have any DNS parsing
+ * routines. We'll have to do it manually.
+ */
static char *readname(unsigned char *msg, unsigned char *eom, unsigned char **p)
{
char *name, *tname;
static char *readname(unsigned char *msg, unsigned char *eom, unsigned char **p)
{
char *name, *tname;
@@
-856,15
+864,10
@@
static int getsrvrr(char *name, char **host, int *port)
return(-1);
}
/* res_querydomain doesn't work for some reason */
return(-1);
}
/* res_querydomain doesn't work for some reason */
- name2 = smalloc(strlen("_dolcon._tcp.") + strlen(name) + 2);
- strcpy(name2, "_dolcon._tcp.");
- strcat(name2, name);
- len = strlen(name2);
- if(name2[len - 1] != '.')
- {
- name2[len] = '.';
- name2[len + 1] = 0;
- }
+ if(name[strlen(name) - 1] == '.')
+ name2 = sprintf2("%s.%s", DOLCON_SRV_NAME, name);
+ else
+ name2 = sprintf2("%s.%s.", DOLCON_SRV_NAME, name);
ret = res_query(name2, C_IN, T_SRV, buf, sizeof(buf));
if(ret < 0)
{
ret = res_query(name2, C_IN, T_SRV, buf, sizeof(buf));
if(ret < 0)
{
@@
-872,12
+875,20
@@
static int getsrvrr(char *name, char **host, int *port)
return(-1);
}
eom = buf + ret;
return(-1);
}
eom = buf + ret;
+ /*
+ * Assume transaction ID is correct.
+ *
+ * Flags check: FA0F masks in request/response flag, opcode,
+ * truncated flag and status code, and ignores authoritativeness,
+ * recursion flags and DNSSEC and reserved bits.
+ */
flags = (buf[2] << 8) + buf[3];
if((flags & 0xfa0f) != 0x8000)
{
free(name2);
return(-1);
}
flags = (buf[2] << 8) + buf[3];
if((flags & 0xfa0f) != 0x8000)
{
free(name2);
return(-1);
}
+ /* Skip the query entries */
num = (buf[4] << 8) + buf[5];
p = buf + 12;
for(i = 0; i < num; i++)
num = (buf[4] << 8) + buf[5];
p = buf + 12;
for(i = 0; i < num; i++)
@@
-887,8
+898,9
@@
static int getsrvrr(char *name, char **host, int *port)
free(name2);
return(-1);
}
free(name2);
return(-1);
}
- p += 4;
+ p += 4;
/* Type and class */
}
}
+ /* Parse answers */
num = (buf[6] << 8) + buf[7];
for(i = 0; i < num; i++)
{
num = (buf[6] << 8) + buf[7];
for(i = 0; i < num; i++)
{
@@
-901,7
+913,7
@@
static int getsrvrr(char *name, char **host, int *port)
type += *(p++);
class = *(p++) << 8;
class += *(p++);
type += *(p++);
class = *(p++) << 8;
class += *(p++);
- p += 4;
+ p += 4;
/* TTL */
len = *(p++) << 8;
len += *(p++);
if((class == C_IN) && (type == T_SRV) && !strcmp(rrname, name2))
len = *(p++) << 8;
len += *(p++);
if((class == C_IN) && (type == T_SRV) && !strcmp(rrname, name2))
@@
-935,7
+947,7
@@
static int getsrvrr(char *name, char **host, int *port)
#else
static int getsrvrr(char *name, char **host, int *port)
{
#else
static int getsrvrr(char *name, char **host, int *port)
{
- errno = EOPNOTSUP;
+ errno = EOPNOTSUP
P
;
return(-1);
}
#endif
return(-1);
}
#endif
@@
-1039,7
+1051,7
@@
struct dc_intresp *dc_interpret(struct dc_response *resp)
struct command *cmd;
struct respclass *cls;
int code;
struct command *cmd;
struct respclass *cls;
int code;
-
in
t args;
+
size_
t args;
if((resp->numlines == 0) || (resp->rlines[0].argc == 0) || (resp->curline >= resp->numlines))
return(NULL);
if((resp->numlines == 0) || (resp->rlines[0].argc == 0) || (resp->curline >= resp->numlines))
return(NULL);