|
TinyPPP
PPP networking over any Arduino Stream
|
Minimal IPv4 stack (ICMP echo, UDP, TCP, DNS resolver) for platforms without lwIP. More...
#include <IPStack.h>
Public Types | |
| using | IdleCallback = void(*)(void *ref) |
| Callback that is called while a socket method waits. | |
Public Member Functions | |
| IPStack () | |
| virtual | ~IPStack () |
| bool | hostByName (const char *host, IPAddress &result, uint32_t timeoutMs=5000) |
| Resolves a host name (or a dotted IP address) via DNS. | |
| void | onIdle (IdleCallback cb, void *ref=nullptr) |
| void | poll () |
| Processes the link (input and timers): called by all socket methods. | |
| void | setRespondToPing (bool flag) |
| Answer ICMP echo requests addressed to us (default true) | |
| int | tcpAccept (uint16_t port, bool withData) |
| int | tcpAvailable (int s) |
| Number of received bytes that can be read from socket s. | |
| void | tcpClose (int s, uint32_t timeoutMs) |
| int | tcpConnect (ip4_t ip, uint16_t port, uint32_t timeoutMs) |
| Opens a connection: returns the socket number or -1. | |
| void | tcpFlush (int s, uint32_t timeoutMs) |
| Waits until all queued data was acknowledged. | |
| uint8_t | tcpGen (int s) const |
| Generation of socket s: changes each time the socket is reused. | |
| bool | tcpListen (uint16_t port) |
| Starts listening on a port. | |
| uint16_t | tcpLocalPort (int s) const |
| Local port of socket s. | |
| int | tcpPeek (int s) |
| Next received byte of socket s without removing it (-1 if none) | |
| int | tcpRead (int s, uint8_t *data, size_t len) |
| Reads up to len received bytes from socket s. | |
| ip4_t | tcpRemoteIP (int s) const |
| Remote address of socket s. | |
| uint16_t | tcpRemotePort (int s) const |
| Remote port of socket s. | |
| TCPState | tcpState (int s) const |
| Connection state of socket s. | |
| void | tcpUnlisten (uint16_t port) |
| Stops listening on a port. | |
| bool | tcpValid (int s, uint8_t gen) const |
| true if socket s is open and still has the generation gen | |
| size_t | tcpWrite (int s, const uint8_t *data, size_t len, uint32_t timeoutMs) |
| Queues data for sending (waits for buffer space up to timeoutMs) | |
| size_t | tcpWriteAll (uint16_t port, const uint8_t *data, size_t len, uint32_t timeoutMs) |
| Sends data to all connected clients of a server port. | |
| int | udpAvailable (int s) const |
| Unread bytes of the current datagram. | |
| void | udpClose (int s) |
| Closes UDP socket s. | |
| void | udpDiscard (int s) |
| Discards the rest of the current datagram. | |
| uint16_t | udpLocalPort (int s) const |
| Local port of UDP socket s. | |
| int | udpOpen (uint16_t port) |
| Opens a UDP socket on the port (0: ephemeral): returns it or -1. | |
| int | udpParsePacket (int s, ip4_t &ip, uint16_t &port) |
| Moves to the next datagram: returns its size (0 if none) | |
| int | udpPeek (int s) const |
| Next byte of the current datagram without removing it (-1 if none) | |
| int | udpRead (int s, uint8_t *data, size_t len) |
| Reads from the current datagram. | |
| bool | udpSend (int s, ip4_t ip, uint16_t port, const uint8_t *data, size_t len) |
| Sends a datagram. | |
Static Public Member Functions | |
| static IPStack *& | current () |
| The stack used by sockets that were created without an explicit stack. | |
Static Public Attributes | |
| static constexpr uint8_t | IP_ICMP = 1 |
| static constexpr uint8_t | IP_TCP = 6 |
| static constexpr uint8_t | IP_UDP = 17 |
| static constexpr uint8_t | TCP_ACK = 0x10 |
| static constexpr uint8_t | TCP_FIN = 0x01 |
| static constexpr uint8_t | TCP_PSH = 0x08 |
| static constexpr uint8_t | TCP_RST = 0x04 |
| static constexpr uint8_t | TCP_SYN = 0x02 |
Protected Member Functions | |
| virtual bool | ipBegin ()=0 |
| Starts an outgoing IPv4 packet. | |
| virtual ip4_t | ipDns (int n) const =0 |
| virtual bool | ipEnd ()=0 |
| Sends the packet. | |
| bool | ipInput (const uint8_t *data, size_t len, bool reply=true) |
| virtual bool | ipIsUp () const =0 |
| void | ipLinkDown () |
| Called when the link goes down: all connections are reset. | |
| virtual ip4_t | ipLocal () const =0 |
| virtual uint16_t | ipMtu () const =0 |
| virtual void | ipPoll ()=0 |
| Processes link input: received packets are passed to ipInput() | |
| virtual void | ipWrite (const uint8_t *data, size_t len)=0 |
| Adds data to the outgoing packet. | |
Minimal IPv4 stack (ICMP echo, UDP, TCP, DNS resolver) for platforms without lwIP.
The link layer (e.g. TinyPPP) derives from this class and implements the ip* methods. The socket methods are used by PPPClient, PPPServer and PPPUDP; sockets are identified by their index in the socket table.
| using IdleCallback = void (*)(void *ref) |
Callback that is called while a socket method waits.
|
inline |
The stack used by sockets that were created without an explicit stack.
Resolves a host name (or a dotted IP address) via DNS.
Starts an outgoing IPv4 packet.
Implemented in TinyPPP_Generic.
Implemented in TinyPPP_Generic.
Sends the packet.
Implemented in TinyPPP_Generic.
Processes a received IPv4 packet: returns false if it was not consumed by the stack (the caller can handle it). With reply set to false, unconsumed packets are not answered with TCP reset.
Implemented in TinyPPP_Generic.
|
inlineprotected |
Called when the link goes down: all connections are reset.
Implemented in TinyPPP_Generic.
Implemented in TinyPPP_Generic.
Processes link input: received packets are passed to ipInput()
Implemented in TinyPPP_Generic.
Adds data to the outgoing packet.
Implemented in TinyPPP_Generic.
|
inline |
Called while a socket method waits (e.g. to run other tasks); ref is passed to the callback
|
inline |
Processes the link (input and timers): called by all socket methods.
Returns a new connection on the port or -1. With withData only connections that have data are returned (also already accepted ones).
Closes the connection: waits up to timeoutMs for the close handshake, the rest is completed in the background.
Opens a connection: returns the socket number or -1.
Generation of socket s: changes each time the socket is reused.
Reads up to len received bytes from socket s.
true if socket s is open and still has the generation gen
Queues data for sending (waits for buffer space up to timeoutMs)
Sends data to all connected clients of a server port.
Opens a UDP socket on the port (0: ephemeral): returns it or -1.
Moves to the next datagram: returns its size (0 if none)
Next byte of the current datagram without removing it (-1 if none)
Sends a datagram.