mirror of
https://git.robbyzambito.me/zaprus
synced 2025-12-20 16:24:50 +00:00
51 lines
1.1 KiB
C
51 lines
1.1 KiB
C
// client
|
|
|
|
#include<stdint.h>
|
|
#include<stdlib.h>
|
|
|
|
int zaprus_init(void);
|
|
|
|
int zaprus_deinit(void);
|
|
|
|
int zaprus_send_relay(const char* payload, size_t len, char dest[4]);
|
|
|
|
int zaprus_send_initial_connection(const char* payload, size_t len, uint16_t initial_port);
|
|
|
|
struct SaprusMessage* zaprus_connect(const char* payload, size_t len);
|
|
|
|
// message
|
|
#define SAPRUS_RELAY_MESSAGE_TYPE 0x003C
|
|
#define SAPRUS_FILE_TRANSFER_MESSAGE_TYPE 0x8888
|
|
#define SAPRUS_CONNECTION_MESSAGE_TYPE 0x00E9
|
|
|
|
struct SaprusMessage {
|
|
uint16_t packet_type;
|
|
union {
|
|
struct {
|
|
struct {
|
|
char dest[4];
|
|
};
|
|
char *payload;
|
|
} relay;
|
|
struct {
|
|
struct {
|
|
uint16_t src_port;
|
|
uint16_t dest_port;
|
|
uint32_t seq_num;
|
|
uint32_t msg_id;
|
|
char _reserved;
|
|
char options;
|
|
};
|
|
char *payload;
|
|
} connection;
|
|
};
|
|
};
|
|
|
|
// ptr should be freed by the caller.
|
|
int zaprus_message_to_bytes(struct SaprusMessage msg, char** ptr, size_t* len);
|
|
|
|
// Return value should be destroyed with zaprus_message_deinit.
|
|
struct SaprusMessage* zaprus_message_from_bytes(const char* bytes, size_t len);
|
|
|
|
void zaprus_message_deinit(struct SaprusMessage* msg);
|