TinyPPP
PPP networking over any Arduino Stream
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
IPStack Class Referenceabstract

Minimal IPv4 stack (ICMP echo, UDP, TCP, DNS resolver) for platforms without lwIP. More...

#include <IPStack.h>

Inheritance diagram for IPStack:
TinyPPP_Generic

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.
 

Detailed Description

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.

Member Typedef Documentation

◆ IdleCallback

Callback that is called while a socket method waits.

Constructor & Destructor Documentation

◆ IPStack()

IPStack ( )
inline

◆ ~IPStack()

virtual ~IPStack ( )
inlinevirtual

Member Function Documentation

◆ current()

static IPStack *& current ( )
inlinestatic

The stack used by sockets that were created without an explicit stack.

◆ hostByName()

bool hostByName ( const char *  host,
IPAddress &  result,
uint32_t  timeoutMs = 5000 
)
inline

Resolves a host name (or a dotted IP address) via DNS.

◆ ipBegin()

virtual bool ipBegin ( )
protectedpure virtual

Starts an outgoing IPv4 packet.

Implemented in TinyPPP_Generic.

◆ ipDns()

virtual ip4_t ipDns ( int  n) const
protectedpure virtual

Implemented in TinyPPP_Generic.

◆ ipEnd()

virtual bool ipEnd ( )
protectedpure virtual

Sends the packet.

Implemented in TinyPPP_Generic.

◆ ipInput()

bool ipInput ( const uint8_t *  data,
size_t  len,
bool  reply = true 
)
inlineprotected

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.

◆ ipIsUp()

virtual bool ipIsUp ( ) const
protectedpure virtual

Implemented in TinyPPP_Generic.

◆ ipLinkDown()

void ipLinkDown ( )
inlineprotected

Called when the link goes down: all connections are reset.

◆ ipLocal()

virtual ip4_t ipLocal ( ) const
protectedpure virtual

Implemented in TinyPPP_Generic.

◆ ipMtu()

virtual uint16_t ipMtu ( ) const
protectedpure virtual

Implemented in TinyPPP_Generic.

◆ ipPoll()

virtual void ipPoll ( )
protectedpure virtual

Processes link input: received packets are passed to ipInput()

Implemented in TinyPPP_Generic.

◆ ipWrite()

virtual void ipWrite ( const uint8_t *  data,
size_t  len 
)
protectedpure virtual

Adds data to the outgoing packet.

Implemented in TinyPPP_Generic.

◆ onIdle()

void onIdle ( IdleCallback  cb,
void *  ref = nullptr 
)
inline

Called while a socket method waits (e.g. to run other tasks); ref is passed to the callback

◆ poll()

void poll ( )
inline

Processes the link (input and timers): called by all socket methods.

◆ setRespondToPing()

void setRespondToPing ( bool  flag)
inline

Answer ICMP echo requests addressed to us (default true)

◆ tcpAccept()

int tcpAccept ( uint16_t  port,
bool  withData 
)
inline

Returns a new connection on the port or -1. With withData only connections that have data are returned (also already accepted ones).

◆ tcpAvailable()

int tcpAvailable ( int  s)
inline

Number of received bytes that can be read from socket s.

◆ tcpClose()

void tcpClose ( int  s,
uint32_t  timeoutMs 
)
inline

Closes the connection: waits up to timeoutMs for the close handshake, the rest is completed in the background.

◆ tcpConnect()

int tcpConnect ( ip4_t  ip,
uint16_t  port,
uint32_t  timeoutMs 
)
inline

Opens a connection: returns the socket number or -1.

◆ tcpFlush()

void tcpFlush ( int  s,
uint32_t  timeoutMs 
)
inline

Waits until all queued data was acknowledged.

◆ tcpGen()

uint8_t tcpGen ( int  s) const
inline

Generation of socket s: changes each time the socket is reused.

◆ tcpListen()

bool tcpListen ( uint16_t  port)
inline

Starts listening on a port.

◆ tcpLocalPort()

uint16_t tcpLocalPort ( int  s) const
inline

Local port of socket s.

◆ tcpPeek()

int tcpPeek ( int  s)
inline

Next received byte of socket s without removing it (-1 if none)

◆ tcpRead()

int tcpRead ( int  s,
uint8_t *  data,
size_t  len 
)
inline

Reads up to len received bytes from socket s.

◆ tcpRemoteIP()

ip4_t tcpRemoteIP ( int  s) const
inline

Remote address of socket s.

◆ tcpRemotePort()

uint16_t tcpRemotePort ( int  s) const
inline

Remote port of socket s.

◆ tcpState()

TCPState tcpState ( int  s) const
inline

Connection state of socket s.

◆ tcpUnlisten()

void tcpUnlisten ( uint16_t  port)
inline

Stops listening on a port.

◆ tcpValid()

bool tcpValid ( int  s,
uint8_t  gen 
) const
inline

true if socket s is open and still has the generation gen

◆ tcpWrite()

size_t tcpWrite ( int  s,
const uint8_t *  data,
size_t  len,
uint32_t  timeoutMs 
)
inline

Queues data for sending (waits for buffer space up to timeoutMs)

◆ tcpWriteAll()

size_t tcpWriteAll ( uint16_t  port,
const uint8_t *  data,
size_t  len,
uint32_t  timeoutMs 
)
inline

Sends data to all connected clients of a server port.

◆ udpAvailable()

int udpAvailable ( int  s) const
inline

Unread bytes of the current datagram.

◆ udpClose()

void udpClose ( int  s)
inline

Closes UDP socket s.

◆ udpDiscard()

void udpDiscard ( int  s)
inline

Discards the rest of the current datagram.

◆ udpLocalPort()

uint16_t udpLocalPort ( int  s) const
inline

Local port of UDP socket s.

◆ udpOpen()

int udpOpen ( uint16_t  port)
inline

Opens a UDP socket on the port (0: ephemeral): returns it or -1.

◆ udpParsePacket()

int udpParsePacket ( int  s,
ip4_t &  ip,
uint16_t &  port 
)
inline

Moves to the next datagram: returns its size (0 if none)

◆ udpPeek()

int udpPeek ( int  s) const
inline

Next byte of the current datagram without removing it (-1 if none)

◆ udpRead()

int udpRead ( int  s,
uint8_t *  data,
size_t  len 
)
inline

Reads from the current datagram.

◆ udpSend()

bool udpSend ( int  s,
ip4_t  ip,
uint16_t  port,
const uint8_t *  data,
size_t  len 
)
inline

Sends a datagram.

Member Data Documentation

◆ IP_ICMP

constexpr uint8_t IP_ICMP = 1
staticconstexpr

◆ IP_TCP

constexpr uint8_t IP_TCP = 6
staticconstexpr

◆ IP_UDP

constexpr uint8_t IP_UDP = 17
staticconstexpr

◆ TCP_ACK

constexpr uint8_t TCP_ACK = 0x10
staticconstexpr

◆ TCP_FIN

constexpr uint8_t TCP_FIN = 0x01
staticconstexpr

◆ TCP_PSH

constexpr uint8_t TCP_PSH = 0x08
staticconstexpr

◆ TCP_RST

constexpr uint8_t TCP_RST = 0x04
staticconstexpr

◆ TCP_SYN

constexpr uint8_t TCP_SYN = 0x02
staticconstexpr

The documentation for this class was generated from the following file: