mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #16879 from benpicco/tools/zep_dispatch-sniffer
tools/zep_dispatch: add support for foren6 sniffer
This commit is contained in:
commit
a5c5a5d284
7
dist/tools/zep_dispatch/main.c
vendored
7
dist/tools/zep_dispatch/main.c
vendored
@ -79,7 +79,12 @@ static void _send_topology(void *ctx, void *buffer, size_t len,
|
||||
uint8_t mac_src_len;
|
||||
|
||||
if (zep_parse_mac(buffer, len, mac_src, &mac_src_len)) {
|
||||
topology_add(ctx, mac_src, mac_src_len, src_addr);
|
||||
/* a sniffer node has no MAC address and will receive every packet */
|
||||
if (mac_src_len == 0) {
|
||||
topology_set_sniffer(ctx, src_addr);
|
||||
} else {
|
||||
topology_add(ctx, mac_src, mac_src_len, src_addr);
|
||||
}
|
||||
}
|
||||
topology_send(ctx, sock, src_addr, buffer, len);
|
||||
}
|
||||
|
20
dist/tools/zep_dispatch/topology.c
vendored
20
dist/tools/zep_dispatch/topology.c
vendored
@ -201,6 +201,11 @@ void topology_send(const topology_t *t, int sock,
|
||||
const struct sockaddr_in6 *src_addr,
|
||||
void *buffer, size_t len)
|
||||
{
|
||||
if (t->has_sniffer) {
|
||||
sendto(sock, buffer, len, 0,
|
||||
(struct sockaddr *)&t->sniffer_addr, sizeof(t->sniffer_addr));
|
||||
}
|
||||
|
||||
for (list_node_t *edge = t->edges.next; edge; edge = edge->next) {
|
||||
struct edge *super = container_of(edge, struct edge, next);
|
||||
|
||||
@ -277,3 +282,18 @@ bool topology_add(topology_t *t, const uint8_t *mac, uint8_t mac_len,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void topology_set_sniffer(topology_t *t, struct sockaddr_in6 *addr)
|
||||
{
|
||||
if (t->has_sniffer) {
|
||||
return;
|
||||
}
|
||||
|
||||
char addr_str[INET6_ADDRSTRLEN];
|
||||
getnameinfo((struct sockaddr*)addr, sizeof(*addr),
|
||||
addr_str, sizeof(addr_str), 0, 0, NI_NUMERICHOST);
|
||||
printf("adding sniffer %s\n", addr_str);
|
||||
|
||||
memcpy(&t->sniffer_addr, addr, sizeof(t->sniffer_addr));
|
||||
t->has_sniffer = true;
|
||||
}
|
||||
|
15
dist/tools/zep_dispatch/topology.h
vendored
15
dist/tools/zep_dispatch/topology.h
vendored
@ -9,6 +9,7 @@
|
||||
#define TOPOLOGY_H
|
||||
|
||||
#include "list.h"
|
||||
#include <netinet/in.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -18,9 +19,11 @@ extern "C" {
|
||||
* @brief Struct describing a graph of nodes and their connections
|
||||
*/
|
||||
typedef struct {
|
||||
bool flat; /**< flat topology, all nodes are connected to each other */
|
||||
list_node_t nodes; /**< list of nodes */
|
||||
list_node_t edges; /**< list of connections between nodes. Unused if topology is flat */
|
||||
struct sockaddr_in6 sniffer_addr; /**< address of sniffer node. Unused if topology is flat */
|
||||
bool has_sniffer; /**< true if a sniffer node is connected. Unused if topology is flat */
|
||||
bool flat; /**< flat topology, all nodes are connected to each other */
|
||||
} topology_t;
|
||||
|
||||
/**
|
||||
@ -58,6 +61,16 @@ int topology_print(const char *file_out, const topology_t *t);
|
||||
bool topology_add(topology_t *t, const uint8_t *mac, uint8_t mac_len,
|
||||
struct sockaddr_in6 *addr);
|
||||
|
||||
/**
|
||||
* @brief Add a sniffer to the topology
|
||||
* A sniffer node will receive every packet but won't be able to
|
||||
* send packets on it's own.
|
||||
*
|
||||
* @param[in, out] t topology to configure
|
||||
* @param[in] addr real address of the sniffer
|
||||
*/
|
||||
void topology_set_sniffer(topology_t *t, struct sockaddr_in6 *addr);
|
||||
|
||||
/**
|
||||
* @brief Send a buffer to all nodes connected to a source node
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user