47 lines
1.3 KiB
C++
47 lines
1.3 KiB
C++
#ifndef COPPINO_UDP_H
|
|
#define COPPINO_UDP_H
|
|
|
|
#include "Arduino.h"
|
|
#include "ipv6.h"
|
|
|
|
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);
|
|
};
|
|
|
|
/* UDP handler for lower layer protocol */
|
|
int handleUDP(char *output_buffer, const char *input_buffer, int len);
|
|
|
|
/* pointer to server handler function */
|
|
extern int (*server_handler)(char *output_buffer, const char *buffer, int size);
|
|
extern uint16_t server_port;
|
|
void set_handler(uint16_t port, int (*handler)(char *output_buffer, const char *input_buffer, int size));
|
|
}
|
|
|
|
#endif
|