coppino/src/udp.h

47 lines
1.3 KiB
C
Raw Normal View History

2019-12-24 13:47:32 +00:00
#ifndef COPPINO_UDP_H
#define COPPINO_UDP_H
#include "Arduino.h"
#include "ipv6.h"
2021-12-26 17:24:23 +00:00
namespace udp
{
class UDPPacket
{
private:
char packet[ipv6::LEN - 40];
public:
void setSrcPort(uint16_t port);
uint16_t getSrcPort();
void setDstPort(uint16_t port);
uint16_t getDstPort();
const char *UDPPacket::getPayload();
void setPayload(const char *payload, int len); /* also sets proper length */
void computeChecksum(const ipv6::IPv6Addr *src_addr, const ipv6::IPv6Addr *dst_addr, int len); /* computes and updates checksum in the packet */
};
class UDPClient
{
private:
const ipv6::IPv6Addr &srcaddr;
const ipv6::IPv6Addr &dstaddr;
const uint16_t srcport;
const uint16_t dstport;
public:
UDPClient(const ipv6::IPv6Addr &srcaddr, ipv6::IPv6Addr &dstaddr, const uint16_t srcport, const uint16_t dstport);
void send_datagram(const uint8_t *payload, size_t len);
2019-12-24 13:47:32 +00:00
};
2019-12-24 22:51:00 +00:00
/* UDP handler for lower layer protocol */
2021-12-26 17:24:23 +00:00
int handleUDP(char *output_buffer, const char *input_buffer, int len);
2019-12-24 15:54:16 +00:00
2019-12-24 22:51:00 +00:00
/* pointer to server handler function */
2021-12-26 17:24:23 +00:00
extern int (*server_handler)(char *output_buffer, const char *buffer, int size);
2019-12-24 15:54:16 +00:00
extern uint16_t server_port;
2021-12-26 17:24:23 +00:00
void set_handler(uint16_t port, int (*handler)(char *output_buffer, const char *input_buffer, int size));
}
2019-12-24 13:47:32 +00:00
#endif