#include "dccp_recv.cmdline.h"
-/* needed by getaddrinfo */
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-
/** the size of the output buffer */
#define DCCP_BUFSIZE 40960
{
struct private_dccp_recv_data *pdd;
struct dccp_recv_args_info *conf = rn->conf;
- int ret;
- struct addrinfo *ai;
- char *tmp;
+ int ret = makesock(AF_UNSPEC, IPPROTO_DCCP, 0, conf->host_arg, conf->port_arg);
- rn->buf = para_calloc(DCCP_BUFSIZE);
- rn->private_data = para_calloc(sizeof(struct private_dccp_recv_data));
- pdd = rn->private_data;
- ret = dccp_get_socket();
if (ret < 0)
- goto err_out;
- pdd->fd = ret;
+ return ret;
- tmp = make_message("%d", conf->port_arg);
- ret = getaddrinfo(conf->host_arg, tmp, NULL, &ai);
- free(tmp);
- if (ret) {
- ret = -E_ADDR_INFO;
- goto err_out;
- }
- ret = dccp_set_socket(pdd->fd);
- if (ret < 0)
- goto err_out;
- PARA_NOTICE_LOG("connecting to %s:%d\n", conf->host_arg, conf->port_arg);
- ret = PARA_CONNECT(pdd->fd, ai->ai_addr);
- freeaddrinfo(ai);
- if (ret < 0) {
- ret = -E_DCCP_CONNECT;
- goto err_out;
- }
+ rn->buf = para_calloc(DCCP_BUFSIZE);
+ rn->private_data = pdd = para_calloc(sizeof(struct private_dccp_recv_data));
+
+ pdd->fd = ret;
mark_fd_nonblocking(pdd->fd);
return 1;
-err_out:
- dccp_recv_close(rn);
- return ret;
}
static void dccp_shutdown(void)
struct dccp_client {
/** the dccp socket */
int fd;
- /** address information about the client */
- struct sockaddr_in addr;
+ /** The socket `name' of the client. */
+ char *name;
/** the position of this client in the client list */
struct list_head node;
/** non-zero if audio file header has been sent */
if (!FD_ISSET(listen_fd, rfds))
return;
- dc = para_calloc(sizeof(struct dccp_client));
- ret = para_accept(listen_fd, &dc->addr, sizeof(struct sockaddr_in));
+ ret = para_accept(listen_fd, NULL, 0);
if (ret < 0) {
PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
return;
}
- PARA_NOTICE_LOG("connection from %s\n", inet_ntoa(dc->addr.sin_addr));
+ dc = para_calloc(sizeof(struct dccp_client));
dc->fd = ret;
+ dc->name = make_message("%s", remote_name(dc->fd));
+ PARA_NOTICE_LOG("connection from %s\n", dc->name);
para_list_add(&dc->node, &clients);
add_close_on_fork_list(dc->fd);
mark_fd_nonblocking(dc->fd);
static int dccp_open(void)
{
- struct sockaddr_in servaddr;
- int ret;
+ int ret = para_listen(AF_UNSPEC, IPPROTO_DCCP, conf.dccp_port_arg);
- ret = dccp_get_socket();
if (ret < 0)
return ret;
listen_fd = ret;
-
- memset(&servaddr, 0, sizeof(servaddr));
- servaddr.sin_family = AF_INET;
- servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
- servaddr.sin_port = htons(conf.dccp_port_arg);
- ret = bind(listen_fd, (struct sockaddr *)&servaddr, sizeof(servaddr));
- if (ret < 0)
- return -E_DCCP_BIND;
- ret = dccp_set_socket(listen_fd);
- if (ret < 0)
- return ret;
- ret = listen(listen_fd, 0);
- if (ret < 0) {
- PARA_ERROR_LOG("%s\n", strerror(errno));
- return -E_DCCP_LISTEN;
- }
- PARA_DEBUG_LOG("listening on fd %d\n", listen_fd);
add_close_on_fork_list(listen_fd);
mark_fd_nonblocking(listen_fd);
return 1;
static void dccp_shutdown_client(struct dccp_client *dc)
{
- PARA_DEBUG_LOG("shutting down %s (fd %d)\n", inet_ntoa(dc->addr.sin_addr),
- dc->fd);
+ PARA_DEBUG_LOG("shutting down %s (fd %d)\n", dc->name, dc->fd);
+ free(dc->name);
close(dc->fd);
del_close_on_fork_list(dc->fd);
cq_destroy(dc->cq);
#define DCCP_RECV_ERRORS \
- PARA_ERROR(ADDR_INFO, "getaddrinfo error"), \
PARA_ERROR(DCCP_OVERRUN, "dccp output buffer buffer overrun"), \
- PARA_ERROR(DCCP_CONNECT, "dccp connect error"), \
PARA_ERROR(DCCP_RECV_EOF, "dccp_recv: end of file"), \
#define DCCP_SEND_ERRORS \
- PARA_ERROR(DCCP_BIND, "dccp bind error"), \
- PARA_ERROR(DCCP_LISTEN, "dccp listen error"), \
PARA_ERROR(DCCP_WRITE, "dccp write error"), \