EtherSia
A minimal IPv6 Ethernet library for Arduino.
|
Abstract base class for a IP socket. More...
#include <Socket.h>
Public Member Functions | |
Socket (EtherSia ðer) | |
Construct a socket The local port number will be set to a random port number. More... | |
Socket (EtherSia ðer, uint16_t localPort) | |
Construct a socket, with a listening port defined. More... | |
boolean | setRemoteAddress (const char *remoteAddress, uint16_t remotePort) |
Set the remote address (as a string) and port to send packets to. More... | |
boolean | setRemoteAddress (const __FlashStringHelper *remoteAddress, uint16_t remotePort) |
Set the remote address (as a string in flash memory) and port to send packets to. More... | |
boolean | setRemoteAddress (IPv6Address &remoteAddress, uint16_t remotePort) |
Set the remote address and port to send packets to. More... | |
IPv6Address & | remoteAddress () |
Get the remote address that packets are being sent to. More... | |
uint16_t | remotePort () |
Get the remote port number that packets are being sent to. More... | |
uint16_t | localPort () |
Get the local port number that packets are being sent to. More... | |
IPv6Address & | packetSource () |
Get the IPv6 source address of the last packet received. More... | |
IPv6Address & | packetDestination () |
Get the IPv6 destination address of the last packet received. More... | |
void | send (boolean isReply=false) |
Send out a packet. More... | |
void | send (uint16_t length, boolean isReply=false) |
Send the contents of the packet payload buffer. More... | |
void | send (const char *data, boolean isReply=false) |
Send a packet containing a string from socket. More... | |
void | send (const void *data, uint16_t length, boolean isReply=false) |
Send a packet containing an array of bytes from socket. More... | |
void | sendReply () |
Send a reply to an incoming packet. More... | |
void | sendReply (uint16_t length) |
Send a reply to the last packet received. More... | |
void | sendReply (const char *data) |
Send a reply to the last packet received. More... | |
void | sendReply (const void *data, uint16_t length) |
Send a reply to the last packet received. More... | |
virtual uint8_t * | payload ()=0 |
Get a pointer to the payload of the current packet in the buffer. More... | |
virtual uint16_t | payloadLength ()=0 |
Get the length (in bytes) of the payload of the packet. More... | |
boolean | payloadEquals (const char *str) |
Check if the current payload equals a string. More... | |
virtual uint8_t * | transmitPayload () |
Get a pointer to the next packet payload to be sent. More... | |
virtual size_t | write (uint8_t chr) |
Write a single character into the packet buffer. More... | |
Abstract base class for a IP socket.
Socket::Socket | ( | EtherSia & | ether | ) |
Construct a socket The local port number will be set to a random port number.
ether | The Ethernet interface to attach the socket to |
Socket::Socket | ( | EtherSia & | ether, |
uint16_t | localPort | ||
) |
Construct a socket, with a listening port defined.
ether | The Ethernet interface to attach the socket to |
localPort | The local port number to listen on |
References localPort(), and IPv6Address::setZero().
uint16_t Socket::localPort | ( | ) |
Get the local port number that packets are being sent to.
IPv6Address & Socket::packetDestination | ( | ) |
Get the IPv6 destination address of the last packet received.
References IPv6Packet::destination(), and EtherSia::packet().
IPv6Address & Socket::packetSource | ( | ) |
Get the IPv6 source address of the last packet received.
References EtherSia::packet(), and IPv6Packet::source().
|
pure virtual |
Get a pointer to the payload of the current packet in the buffer.
Implemented in TCPServer, UDPSocket, and PingClient.
boolean Socket::payloadEquals | ( | const char * | str | ) |
Check if the current payload equals a string.
str | The null-terminated string to compare to |
References payload(), and payloadLength().
|
pure virtual |
Get the length (in bytes) of the payload of the packet.
Implemented in TCPServer, UDPSocket, and PingClient.
IPv6Address & Socket::remoteAddress | ( | ) |
Get the remote address that packets are being sent to.
uint16_t Socket::remotePort | ( | ) |
Get the remote port number that packets are being sent to.
void Socket::send | ( | boolean | isReply = false | ) |
Send out a packet.
Before calling this, the payload should have been written to the packet buffer using the print() and println() methods.
isReply | true if the sent packet is a reply to the packet current in the buffer |
void Socket::send | ( | uint16_t | length, |
boolean | isReply = false |
||
) |
Send the contents of the packet payload buffer.
Place the data in the payload() buffer before calling this method.
length | The length of the payload |
isReply | true if the sent packet is a reply to the packet current in the buffer |
References EtherSia::packet(), EtherSia::prepareReply(), EtherSia::prepareSend(), IPv6Packet::setDestination(), and IPv6Packet::setEtherDestination().
void Socket::send | ( | const char * | data, |
boolean | isReply = false |
||
) |
Send a packet containing a string from socket.
data | The null-terminated string to send |
isReply | true if the sent packet is a reply to the packet current in the buffer |
References send().
void Socket::send | ( | const void * | data, |
uint16_t | length, | ||
boolean | isReply = false |
||
) |
Send a packet containing an array of bytes from socket.
data | The data to send as the payload |
length | The length (in bytes) of the data to send |
isReply | true if the sent packet is a reply to the packet current in the buffer |
References payload(), send(), and transmitPayload().
void Socket::sendReply | ( | ) |
Send a reply to an incoming packet.
Before calling this, the payload should have been written to the packet buffer using the print() and println() methods.
References send().
void Socket::sendReply | ( | uint16_t | length | ) |
void Socket::sendReply | ( | const char * | data | ) |
Send a reply to the last packet received.
data | The null-terminated string to send |
References send().
void Socket::sendReply | ( | const void * | data, |
uint16_t | length | ||
) |
Send a reply to the last packet received.
data | A pointer to the data to send |
length | The length (in bytes) of the data to send |
References send().
boolean Socket::setRemoteAddress | ( | const char * | remoteAddress, |
uint16_t | remotePort | ||
) |
Set the remote address (as a string) and port to send packets to.
If the remote address looks like a hostname, it will be looked up using DNS.
remoteAddress | The remote address or hostname |
remotePort | The port number to send packets to |
References containsColon(), IPv6Address::fromString(), EtherSia::lookupHostname(), remoteAddress(), and remotePort().
boolean Socket::setRemoteAddress | ( | const __FlashStringHelper * | remoteAddress, |
uint16_t | remotePort | ||
) |
Set the remote address (as a string in flash memory) and port to send packets to.
If the remote address looks like a hostname, it will be looked up using DNS.
remoteAddress | The remote address or hostname (as a flash string - use the F() macro) |
remotePort | The port number to send packets to |
References remoteAddress(), remotePort(), and setRemoteAddress().
boolean Socket::setRemoteAddress | ( | IPv6Address & | remoteAddress, |
uint16_t | remotePort | ||
) |
Set the remote address and port to send packets to.
remoteAddress | The remote address as a 16-byte array |
remotePort | The remote port number to send packets to |
References EtherSia::discoverNeighbour(), EtherSia::inOurSubnet(), remoteAddress(), remotePort(), and EtherSia::routerMac().
|
virtual |
|
virtual |
Write a single character into the packet buffer.
chr | The character to write |
References payload(), and transmitPayload().