summaryrefslogtreecommitdiffstats
path: root/src/fastd.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-02-28 18:56:11 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-02-28 18:56:11 +0100
commitac0c534866ae9f4613143d2894631492d7df2e82 (patch)
tree259f8d54c9dba4f183bdaf1e4f7b941524889fd7 /src/fastd.c
parent34320ea5a34e53ede384dd408f3484cb872337cc (diff)
downloadfastd-ac0c534866ae9f4613143d2894631492d7df2e82.tar
fastd-ac0c534866ae9f4613143d2894631492d7df2e82.zip
Allow receiving from multiple peers
Diffstat (limited to 'src/fastd.c')
-rw-r--r--src/fastd.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/fastd.c b/src/fastd.c
index 7bcfdd8..876975f 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -237,6 +237,8 @@ static void init_peers(fastd_context *ctx) {
}
}
+
+
static void* get_source_address(const fastd_context *ctx, void *buffer) {
switch (ctx->conf->protocol) {
case PROTOCOL_ETHERNET:
@@ -375,21 +377,29 @@ static void handle_input(fastd_context *ctx) {
if (len < 0)
pr_warn(ctx, "recvfrom: %s", strerror(errno));
- // TODO get correct peer
- fastd_peer *peer = ctx->peers;
-
+ fastd_peer *peer;
+ for (peer = ctx->peers; peer; peer = peer->next) {
+ if (recvaddr.sin_addr.s_addr == peer->address && recvaddr.sin_port == peer->port)
+ break;
+ }
- switch (packet_type) {
- case 0:
- buffer.len = len - 1;
- ctx->conf->method->method_handle_recv(ctx, peer, buffer);
- break;
+ if (peer) {
+ switch (packet_type) {
+ case 0:
+ buffer.len = len - 1;
+ ctx->conf->method->method_handle_recv(ctx, peer, buffer);
+ break;
- case 1:
- fastd_handshake_handle(ctx, peer, buffer);
- break;
+ case 1:
+ fastd_handshake_handle(ctx, peer, buffer);
+ break;
- default:
+ default:
+ fastd_buffer_free(buffer);
+ }
+ }
+ else {
+ pr_debug(ctx, "received packet from unknown peer");
fastd_buffer_free(buffer);
}
}