Commit 6b6c4f45 authored by Niels Möller's avatar Niels Möller
Browse files

* src/io.h (fd_listen_callback): New class.

* src/io.c (tcp_addr): Moved this function from tcpforward.c.
(listen_callback): Pass the peer address to the listen callback.

Rev: src/io.c:1.51
Rev: src/io.h:1.30
parent cd794df3
......@@ -361,7 +361,8 @@ static void listen_callback(struct lsh_fd *fd)
werror("io.c: accept() failed, %z", strerror(errno));
return;
}
res = FD_CALLBACK(self->callback, conn);
res = FD_LISTEN_CALLBACK(self->callback, conn,
addr_len, (struct sockaddr *) &peer);
if (LSH_ACTIONP(res))
{
werror("Strange: Accepted a connection, "
......@@ -564,6 +565,31 @@ get_inaddr(struct sockaddr_in * addr,
return 1;
}
/* FIXME: IPv6 support */
/* FIXME: The host name lookup may block. We would need an asyncronous
* get_inaddr function. As a work around, we could let the client do
* all lookups, so that the server ned only deal with ip-numbers. And
* optionally refuse requests with dns names. */
int tcp_addr(struct sockaddr_in *sin,
UINT32 length,
UINT8 *addr,
UINT32 port)
{
char *c = alloca(length + 1);
int res;
memcpy(c, addr, length);
c[length] = '\0';
res = get_inaddr(sin, c, NULL, "tcp");
if (!res)
return 0;
sin->sin_port = htons(port);
return 1;
}
/* For fd:s in blocking mode. */
int write_raw(int fd, UINT32 length, UINT8 *data)
{
......@@ -697,7 +723,7 @@ struct connect_fd *io_connect(struct io_backend *b,
struct listen_fd *io_listen(struct io_backend *b,
struct sockaddr_in *local,
struct fd_callback *callback)
struct fd_listen_callback *callback)
{
int s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
......
......@@ -33,6 +33,7 @@
#include <time.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define CLASS_DECLARE
......@@ -117,15 +118,29 @@
(buffer object write_buffer)))
*/
/* CLASS:
(class
(name fd_listen_callback)
(vars
(f method int int "size_t" "struct sockaddr *")))
*/
#define FD_LISTEN_CALLBACK(c, fd, s, a) ((c)->f((c), (fd), (s), (a)))
/* CLASS:
(class
(name listen_fd)
(super lsh_fd)
(vars
(callback object fd_callback)))
(callback object fd_listen_callback)))
*/
#define connect_fd listen_fd
/* CLASS:
(class
(name connect_fd)
(super lsh_fd)
(vars
(callback object fd_callback)))
*/
#if 0
struct callout
......@@ -161,6 +176,11 @@ int get_inaddr(struct sockaddr_in * addr,
const char * service,
const char * protocol);
int tcp_addr(struct sockaddr_in *sin,
UINT32 length,
UINT8 *addr,
UINT32 port);
int write_raw(int fd, UINT32 length, UINT8 *data);
int write_raw_with_poll(int fd, UINT32 length, UINT8 *data);
......@@ -175,7 +195,7 @@ struct connect_fd *io_connect(struct io_backend *b,
struct listen_fd *io_listen(struct io_backend *b,
struct sockaddr_in *local,
struct fd_callback *callback);
struct fd_listen_callback *callback);
struct io_fd *io_read_write(struct io_backend *b,
......
Supports Markdown
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