* derivatives without specific, written prior permission.
*/
+#include <config.h>
#include "vconn.h"
#include <assert.h>
#include <errno.h>
+#include <inttypes.h>
#include <netdb.h>
#include <poll.h>
#include <sys/types.h>
#include "util.h"
#include "openflow.h"
#include "ofp-print.h"
+#include "packets.h"
#include "poll-loop.h"
#include "vlog.h"
static int
new_tcp_vconn(const char *name, int fd, int connect_status,
- struct vconn **vconnp)
+ const struct sockaddr_in *sin, struct vconn **vconnp)
{
struct tcp_vconn *tcp;
int on = 1;
tcp = xmalloc(sizeof *tcp);
tcp->vconn.class = &tcp_vconn_class;
tcp->vconn.connect_status = connect_status;
+ tcp->vconn.ip = sin->sin_addr.s_addr;
tcp->fd = fd;
tcp->txbuf = NULL;
tcp->tx_waiter = NULL;
host_name = strtok_r(suffix, "::", &save_ptr);
port_string = strtok_r(NULL, "::", &save_ptr);
if (!host_name) {
- fatal(0, "%s: bad peer name format", name);
+ error(0, "%s: bad peer name format", name);
+ return EAFNOSUPPORT;
}
memset(&sin, 0, sizeof sin);
retval = connect(fd, (struct sockaddr *) &sin, sizeof sin);
if (retval < 0) {
if (errno == EINPROGRESS) {
- return new_tcp_vconn(name, fd, EAGAIN, vconnp);
+ return new_tcp_vconn(name, fd, EAGAIN, &sin, vconnp);
} else {
int error = errno;
VLOG_ERR("%s: connect: %s", name, strerror(error));
return error;
}
} else {
- return new_tcp_vconn(name, fd, 0, vconnp);
+ return new_tcp_vconn(name, fd, 0, &sin, vconnp);
}
}
return 0;
}
}
- buffer_reserve_tailroom(rx, want_bytes);
+ buffer_prealloc_tailroom(rx, want_bytes);
retval = read(tcp->fd, buffer_tail(rx), want_bytes);
if (retval > 0) {
ptcp_accept(struct vconn *vconn, struct vconn **new_vconnp)
{
struct ptcp_vconn *ptcp = ptcp_vconn_cast(vconn);
+ struct sockaddr_in sin;
+ socklen_t sin_len = sizeof sin;
+ char name[128];
int new_fd;
int error;
- new_fd = accept(ptcp->fd, NULL, NULL);
+ new_fd = accept(ptcp->fd, &sin, &sin_len);
if (new_fd < 0) {
int error = errno;
if (error != EAGAIN) {
return error;
}
- return new_tcp_vconn("tcp" /* FIXME */, new_fd, 0, new_vconnp);
+ sprintf(name, "tcp:"IP_FMT, IP_ARGS(&sin.sin_addr));
+ if (sin.sin_port != htons(OFP_TCP_PORT)) {
+ sprintf(strchr(name, '\0'), ":%"PRIu16, ntohs(sin.sin_port));
+ }
+ return new_tcp_vconn(name, new_fd, 0, &sin, new_vconnp);
}
static void