Commit 4095b364 authored by Michael Graff's avatar Michael Graff
Browse files

try to get the address put into the returned structure, but no go yet

parent 7861b133
......@@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <isc/assertions.h>
#include <isc/memcluster.h>
......@@ -12,6 +13,10 @@
#include <isc/result.h>
#include <isc/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
isc_memctx_t mctx = NULL;
volatile int tasks_done = 0;
......@@ -75,6 +80,8 @@ my_recv(isc_task_t task, isc_event_t event)
(char *)(event->arg), sock,
dev->region.base, dev->region.length,
dev->n, dev->result);
printf("\tFrom: %s port %d\n", inet_ntoa(dev->address.type.sin.sin_addr),
ntohs(dev->address.type.sin.sin_port));
if (dev->result != ISC_R_SUCCESS) {
isc_socket_detach(&sock);
......@@ -152,7 +159,7 @@ main(int argc, char *argv[])
isc_socketmgr_t socketmgr;
isc_socket_t so1, so2;
struct isc_sockaddr sockaddr;
int addrlen;
unsigned int addrlen;
memset(&sockaddr, 0, sizeof(sockaddr));
sockaddr.type.sin.sin_port = htons(5544);
......
/* $Id: socket.h,v 1.5 1998/11/11 00:43:14 explorer Exp $ */
/* $Id: socket.h,v 1.6 1998/11/15 11:48:21 explorer Exp $ */
#ifndef ISC_SOCKET_H
#define ISC_SOCKET_H 1
......@@ -79,13 +79,15 @@ typedef struct isc_socketevent {
unsigned int n; /* bytes read or written */
struct isc_region region; /* the region info */
struct isc_sockaddr address; /* source address */
int addrlength; /* length of address */
unsigned int addrlength; /* length of address */
} *isc_socketevent_t;
typedef struct isc_socket_newconev {
struct isc_event common;
isc_socket_t newsocket;
isc_result_t result; /* OK, EOF, whatever else */
struct isc_sockaddr address; /* source address */
unsigned int addrlength; /* length of address */
} *isc_socket_newconnev_t;
#define ISC_SOCKEVENT_ANYEVENT (0)
......@@ -413,7 +415,7 @@ isc_socket_send(isc_socket_t socket, isc_region_t region,
isc_result_t
isc_socket_sendto(isc_socket_t socket, isc_region_t region,
isc_task_t task, isc_taskaction_t action, void *arg,
isc_sockaddr_t address, int addrlength);
isc_sockaddr_t address, unsigned int addrlength);
/*
* Send the contents of 'region' to the socket's peer.
*
......
/* $Id: socket.c,v 1.8 1998/11/11 02:05:36 explorer Exp $ */
/* $Id: socket.c,v 1.9 1998/11/15 11:48:17 explorer Exp $ */
#include "attribute.h"
......@@ -91,7 +91,7 @@ struct isc_socket {
isc_socket_intev_t riev;
isc_socket_intev_t wiev;
struct isc_sockaddr address;
int addrlength;
unsigned int addrlength;
};
#define SOCKET_MANAGER_MAGIC 0x494f6d67U /* IOmg */
......@@ -610,7 +610,7 @@ internal_accept(isc_task_t task, isc_event_t ev)
isc_socket_newconnev_t dev;
isc_socket_ncintev_t iev;
struct sockaddr addr;
int addrlen;
u_int addrlen;
int fd;
sock = ev->sender;
......@@ -645,6 +645,7 @@ internal_accept(isc_task_t task, isc_event_t ev)
* EWOULDBLOCK, simply poke the watcher to watch this socket
* again.
*/
addrlen = sizeof(addr);
fd = accept(sock->fd, &addr, &addrlen);
if (fd < 0) {
if (errno == EWOULDBLOCK) {
......@@ -682,6 +683,11 @@ internal_accept(isc_task_t task, isc_event_t ev)
XTRACE(("internal_accept: newsock %p, fd %d\n",
dev->newsocket, fd));
sock->addrlength = addrlen;
memcpy(&sock->address, &addr, addrlen);
dev->addrlength = addrlen;
memcpy(&dev->address, &addr, addrlen);
UNLOCK(&sock->lock);
/*
......@@ -708,6 +714,8 @@ internal_read(isc_task_t task, isc_event_t ev)
isc_socket_t sock;
int cc;
size_t read_count;
struct sockaddr addr;
u_int addrlen;
/*
* Find out what socket this is and lock it.
......@@ -761,7 +769,21 @@ internal_read(isc_task_t task, isc_event_t ev)
* we can.
*/
read_count = dev->region.length - dev->n;
cc = recv(sock->fd, dev->region.base + dev->n, read_count, 0);
if (sock->type == isc_socket_tcp) {
cc = recv(sock->fd, dev->region.base + dev->n,
read_count, 0);
memcpy(&dev->address, &sock->address,
sock->addrlength);
dev->addrlength = sock->addrlength;
} else {
addrlen = sizeof(addr);
cc = recvfrom(sock->fd, dev->region.base + dev->n,
read_count, 0,
(struct sockaddr *)&addr,
&addrlen);
memcpy(&dev->address, &addr, addrlen);
dev->addrlength = addrlen;
}
XTRACE(("internal_read: read(%d) %d\n", sock->fd, cc));
......@@ -1402,7 +1424,7 @@ isc_socket_send(isc_socket_t sock, isc_region_t region,
isc_result_t
isc_socket_sendto(isc_socket_t sock, isc_region_t region,
isc_task_t task, isc_taskaction_t action, void *arg,
isc_sockaddr_t address, int addrlength)
isc_sockaddr_t address, unsigned int addrlength)
{
isc_socketevent_t ev;
isc_socket_intev_t iev;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment