comm_notify_fn *fn);
typedef bool_t comm_sendmsg_fn(void *commst, struct buffer_if *buf,
const struct comm_addr *dest);
+typedef const char *comm_addr_to_string_fn(void *commst,
+ const struct comm_addr *ca);
+ /* Returned string is in a static buffer. */
struct comm_if {
void *st;
int32_t min_start_pad;
comm_request_notify_fn *request_notify;
comm_release_notify_fn *release_notify;
comm_sendmsg_fn *sendmsg;
+ comm_addr_to_string_fn *addr_to_string;
};
/* LOG interface */
#include <errno.h>
#include <sys/socket.h>
#include <sys/wait.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
#include "util.h"
#include "unaligned.h"
#include "ipaddr.h"
struct sockaddr_in proxy;
};
+static const char *saddr_to_string(const struct sockaddr_in *sin) {
+ static char bufs[2][100];
+ static int b;
+
+ b ^= 1;
+ snprintf(bufs[b], sizeof(bufs[b]), "[%s]:%d",
+ inet_ntoa(sin->sin_addr),
+ ntohs(sin->sin_port));
+ return bufs[b];
+}
+
+static const char *addr_to_string(void *commst, const struct comm_addr *ca) {
+ struct udp *st=commst;
+ static char sbuf[100];
+
+ struct sockaddr_in la;
+ la.sin_addr.s_addr=htonl(st->addr);
+ la.sin_port=htons(st->port);
+
+ snprintf(sbuf, sizeof(sbuf), "udp:%s-%s",
+ saddr_to_string(&la), saddr_to_string(&ca->sin));
+ return sbuf;
+}
+
static int udp_beforepoll(void *state, struct pollfd *fds, int *nfds_io,
int *timeout_io)
{
st->ops.request_notify=request_notify;
st->ops.release_notify=release_notify;
st->ops.sendmsg=udp_sendmsg;
+ st->ops.addr_to_string=addr_to_string;
st->port=0;
st->use_proxy=False;