blob: e5daf7b4d5fc1b57dbea7fa0559c7dffd94e87c0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#pragma once
#include <stdbool.h>
#include <stdint.h>
struct icmpd_received {
uint8_t *data; // points to malloc'd buffer; should be freed by recipient
size_t length; // length of 'data'
uint32_t source_addr;
int id, seqnum;
};
// The interface exposed here is NOT thread-safe. Having multiple threads in
// in the same process working with icmpd is unsafe, since internal communication
// assumes one calling thread.
// This functions as a "connection" with another party. A server should create
// a new connection for each client it communicates with (in addition to a
// single possible client_addr=0 connection for receiving connection requests),
// and likewise a client should create a new connection for each server it
// communicates with.
struct icmpd;
// Pass 0 as client_addr to listen for messages from any IP (this channel
// will then only receive unassigned messages)
// Pass -1 as id to listen for messages with any id
struct icmpd* icmpd_create_server(int id, uint32_t client_addr);
struct icmpd* icmpd_create_client(uint32_t server_addr);
void icmpd_server_set_outstanding(struct icmpd *d, int seqnum);
bool icmpd_peek(struct icmpd *d);
struct icmpd_received icmpd_recv(struct icmpd *d);
void icmpd_send(struct icmpd *d, const void *data, size_t length);
// File descriptor that select(2) reports readable when a message might be ready.
// Do not read from this file descriptor.
// Use icmpd_peek() to verify that a message is actually ready.
int icmpd_get_select_fd(struct icmpd *d);
void icmpd_destroy(struct icmpd *d);
|