summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2013-03-13 13:04:54 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2013-03-13 13:15:51 +0100
commit3f0dfe5fbb4f8217fe6e022fdf41a361f3a1cf8c (patch)
treece88c081521d096a96c46ec4530173182cd1ac3a
parentc86a48ce405f5aa8911ffb290c3e0d03077b5cae (diff)
downloadecon-3f0dfe5fbb4f8217fe6e022fdf41a361f3a1cf8c.zip
econ-3f0dfe5fbb4f8217fe6e022fdf41a361f3a1cf8c.tar.gz
econ-3f0dfe5fbb4f8217fe6e022fdf41a361f3a1cf8c.tar.bz2
econfind: Beamer IP has to be optained from recvmsg directly
The econ_header IPaddress field holds only our client ip. econpacket needs to store the addr in the packet.
-rw-r--r--econfind.c10
-rw-r--r--econpacket.c24
-rw-r--r--econpacket.h5
3 files changed, 26 insertions, 13 deletions
diff --git a/econfind.c b/econfind.c
index 29f9651..c806446 100644
--- a/econfind.c
+++ b/econfind.c
@@ -30,10 +30,12 @@
static void
parse_clientinfo(struct econ_packet *pkt)
{
- struct in_addr beamer;
-
- beamer.s_addr = *(uint32_t*)pkt->hdr.IPaddress;
- printf("%s", inet_ntoa(beamer));
+ /* Clientinfo has our ip in the packet header,
+ * and the record has the ip 16.0.32.0,
+ * none of them are the acutal beamer ip,
+ * so we retreive that from the up packet directly. */
+ printf("%s", inet_ntoa(pkt->addr.sin_addr));
+
if (pkt->hdr.datasize > 0) {
char *name = pkt->cmd.command.clientinfo.projName;
int state = pkt->cmd.command.clientinfo.projState;
diff --git a/econpacket.c b/econpacket.c
index 0eac748..9477cf7 100644
--- a/econpacket.c
+++ b/econpacket.c
@@ -81,9 +81,9 @@ epkt_send(int fd, struct econ_packet *pkt)
}
static int
-iov_max_read(struct iovec *iov, int *iovcnt, size_t size)
+iov_max_read(struct iovec *iov, size_t *iovcnt, size_t size)
{
- int i;
+ size_t i;
for (i = 0; i < *iovcnt; ++i) {
if (iov[i].iov_len > size) {
@@ -106,9 +106,11 @@ epkt_read(int fd, struct econ_packet *pkt)
union { ssize_t s; size_t u; } len, len2;
int type;
socklen_t length = sizeof(int);
- int iovcnt;
+ struct msghdr msg;
+ memset(&msg, 0, sizeof msg);
init_iov(pkt);
+ msg.msg_iov = pkt->iov;
pkt->long_data_size = 0;
if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &type, &length) < 0)
@@ -117,16 +119,18 @@ epkt_read(int fd, struct econ_packet *pkt)
/* FIXME Do we get the diffs between udp and tcp handled a bit nicer? */
switch (type) {
case SOCK_STREAM:
- iovcnt = 1;
+ msg.msg_iovlen = 1;
break;
case SOCK_DGRAM:
- iovcnt = 4;
+ msg.msg_iovlen = 4;
+ msg.msg_name = &pkt->addr;
+ msg.msg_namelen = sizeof pkt->addr;
break;
default:
return -1;
}
- len.s = readv(fd, pkt->iov, iovcnt);
+ len.s = recvmsg(fd, &msg, 0);
if (len.s < 0)
return -1;
@@ -148,12 +152,14 @@ epkt_read(int fd, struct econ_packet *pkt)
return -1;
if (type == SOCK_STREAM) {
- iovcnt = 3;
- if (iov_max_read(&pkt->iov[1], &iovcnt, pkt->hdr.datasize) < 0)
+ msg.msg_iovlen = 3;
+ msg.msg_iov = &pkt->iov[1];
+ if (iov_max_read(msg.msg_iov, &msg.msg_iovlen,
+ pkt->hdr.datasize) < 0)
return -1;
/* Yes, this may write up to long_data[1024]. */
- len2.s = readv(fd, &pkt->iov[1], iovcnt);
+ len2.s = recvmsg(fd, &msg, 0);
if (len2.s < 0 || len2.u != pkt->hdr.datasize)
return -1;
diff --git a/econpacket.h b/econpacket.h
index fc4aea4..cde0734 100644
--- a/econpacket.h
+++ b/econpacket.h
@@ -19,6 +19,8 @@
#define _ECONPACKET_H_
#include <stddef.h>
+#include <netinet/in.h>
+
#include "econproto.h"
struct econ_packet {
@@ -34,6 +36,9 @@ struct econ_packet {
/* Holding the previous elements */
struct iovec iov[4];
+
+ /* For packets that are received via udp. */
+ struct sockaddr_in addr;
};
void