Don't use sendto on connected sockets.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@3211 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1997-08-28 00:06:55 +00:00
parent 6a23550fd9
commit 0c50fc2317

View File

@@ -43,21 +43,20 @@ RCSID("$Id$");
static int static int
send_and_recv (int fd, send_and_recv (int fd,
time_t tmout, time_t tmout,
struct sockaddr_in *addr, int udp,
const krb5_data *send, const krb5_data *req,
krb5_data *recv) krb5_data *rep)
{ {
struct fd_set fdset; struct fd_set fdset;
struct timeval timeout; struct timeval timeout;
int ret; int ret;
int nbytes; int nbytes;
if (sendto (fd, send->data, send->length, 0, if (send (fd, req->data, req->length, 0) < 0)
(struct sockaddr *)addr, sizeof(*addr)) < 0)
return -1; return -1;
recv->data = NULL; rep->data = NULL;
recv->length = 0; rep->length = 0;
while(1){ do{
FD_ZERO(&fdset); FD_ZERO(&fdset);
FD_SET(fd, &fdset); FD_SET(fd, &fdset);
timeout.tv_sec = tmout; timeout.tv_sec = tmout;
@@ -73,22 +72,21 @@ send_and_recv (int fd,
if(nbytes == 0) if(nbytes == 0)
return 0; return 0;
recv->data = realloc(recv->data, recv->length + nbytes); rep->data = realloc(rep->data, rep->length + nbytes);
ret = recvfrom (fd, (char *)recv->data + recv->length, ret = recv (fd, (char*)rep->data + rep->length, nbytes, 0);
nbytes, 0, NULL, &len);
if (ret < 0) { if (ret < 0) {
free (recv->data); free (rep->data);
return -1; return -1;
} }
recv->length += ret; rep->length += ret;
} }
} }while(!udp);
return 0;
} }
static int static int
send_and_recv_http(int fd, send_and_recv_http(int fd,
time_t tmout, time_t tmout,
struct sockaddr_in *addr,
const krb5_data *send, const krb5_data *send,
krb5_data *recv) krb5_data *recv)
{ {
@@ -103,7 +101,7 @@ send_and_recv_http(int fd,
free(str); free(str);
r.data = request; r.data = request;
r.length = strlen(request); r.length = strlen(request);
ret = send_and_recv(fd, tmout, addr, &r, recv); ret = send_and_recv(fd, tmout, 0, &r, recv);
free(request); free(request);
if(ret) if(ret)
return ret; return ret;
@@ -187,11 +185,11 @@ krb5_sendto_kdc (krb5_context context,
if(http_flag) if(http_flag)
ret = send_and_recv_http(fd, context->kdc_timeout, ret = send_and_recv_http(fd, context->kdc_timeout,
&a, send, receive); send, receive);
else else
ret = send_and_recv (fd, context->kdc_timeout, ret = send_and_recv (fd, context->kdc_timeout, 1,
&a, send, receive); send, receive);
close (fd); close (fd);
if(ret == 0){ if(ret == 0){
krb5_free_krbhst (context, hostlist); krb5_free_krbhst (context, hostlist);