Some quick code to use UDP-only (no TCP) with mBed. Echos received packets and sends packets when a button is pressed
dhcp.c File Reference
Dynamic Host Configuration Protocol client. More...
Go to the source code of this file.
Functions | |
static void | dhcp_handle_ack (struct netif *netif) |
Handle a DHCP ACK packet. | |
static void | dhcp_handle_nak (struct netif *netif) |
Back-off the DHCP client (because of a received NAK response). | |
static void | dhcp_handle_offer (struct netif *netif) |
Remember the configuration offered by a DHCP server. | |
static err_t | dhcp_discover (struct netif *netif) |
Start the DHCP process, discover a DHCP server. | |
static err_t | dhcp_select (struct netif *netif) |
Select a DHCP server offer out of all offers. | |
static void | dhcp_bind (struct netif *netif) |
Bind the interface to the offered IP address. | |
static void | dhcp_check (struct netif *netif) |
Checks if the offered IP address is already in use. | |
static err_t | dhcp_decline (struct netif *netif) |
Decline an offered lease. | |
static err_t | dhcp_rebind (struct netif *netif) |
Rebind with a DHCP server for an existing DHCP lease. | |
static err_t | dhcp_reboot (struct netif *netif) |
Enter REBOOTING state to verify an existing lease. | |
static void | dhcp_recv (void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port) |
If an incoming DHCP message is in response to us, then trigger the state machine. | |
static err_t | dhcp_unfold_reply (struct dhcp *dhcp, struct pbuf *p) |
Extract the DHCP message and the DHCP options. | |
static u8_t * | dhcp_get_option_ptr (struct dhcp *dhcp, u8_t option_type) |
Find the offset of a DHCP option inside the DHCP message. | |
static u8_t | dhcp_get_option_byte (u8_t *ptr) |
Return the byte of DHCP option data. | |
static u16_t | dhcp_get_option_short (u8_t *ptr) |
Return the 16-bit value of DHCP option data. | |
static u32_t | dhcp_get_option_long (u8_t *ptr) |
Return the 32-bit value of DHCP option data. | |
static void | dhcp_free_reply (struct dhcp *dhcp) |
Free the incoming DHCP message including contiguous copy of its DHCP options. | |
static void | dhcp_timeout (struct netif *netif) |
A DHCP negotiation transaction, or ARP request, has timed out. | |
static void | dhcp_t1_timeout (struct netif *netif) |
The renewal period has timed out. | |
static void | dhcp_t2_timeout (struct netif *netif) |
The rebind period has timed out. | |
static err_t | dhcp_create_request (struct netif *netif) |
Create a DHCP request, fill in common headers. | |
static void | dhcp_delete_request (struct netif *netif) |
Free previously allocated memory used to send a DHCP request. | |
static void | dhcp_option_trailer (struct dhcp *dhcp) |
Add a DHCP message trailer. | |
void | dhcp_coarse_tmr () |
The DHCP timer that checks for lease renewal/rebind timeouts. | |
void | dhcp_fine_tmr () |
DHCP transaction timeout handling. | |
err_t | dhcp_start (struct netif *netif) |
Start DHCP negotiation for a network interface. | |
void | dhcp_inform (struct netif *netif) |
Inform a DHCP server of our manual configuration. | |
void | dhcp_network_changed (struct netif *netif) |
Handle a possible change in the network configuration. | |
void | dhcp_arp_reply (struct netif *netif, struct ip_addr *addr) |
Match an ARP reply with the offered IP address. | |
err_t | dhcp_renew (struct netif *netif) |
Renew an existing DHCP lease at the involved DHCP server. | |
err_t | dhcp_release (struct netif *netif) |
Release a DHCP lease. | |
void | dhcp_stop (struct netif *netif) |
Remove the DHCP client from the interface. |
Detailed Description
Dynamic Host Configuration Protocol client.
Definition in file dhcp.c.
Function Documentation
void dhcp_arp_reply | ( | struct netif * | netif, |
struct ip_addr * | addr | ||
) |
static void dhcp_bind | ( | struct netif * | netif ) | [static] |
static void dhcp_check | ( | struct netif * | netif ) | [static] |
Checks if the offered IP address is already in use.
It does so by sending an ARP request for the offered address and entering CHECKING state. If no ARP reply is received within a small interval, the address is assumed to be free for use by us.
- Parameters:
-
netif the netif under DHCP control
void dhcp_coarse_tmr | ( | void | ) |
static err_t dhcp_create_request | ( | struct netif * | netif ) | [static] |
Create a DHCP request, fill in common headers.
- Parameters:
-
netif the netif under DHCP control
default global transaction identifier starting value (easy to match with a packet analyser). We simply increment for each new request. Predefine DHCP_GLOBAL_XID to a better value or a function call to generate one at runtime, any supporting function prototypes can be defined in DHCP_GLOBAL_XID_HEADER
static err_t dhcp_decline | ( | struct netif * | netif ) | [static] |
static void dhcp_delete_request | ( | struct netif * | netif ) | [static] |
static err_t dhcp_discover | ( | struct netif * | netif ) | [static] |
void dhcp_fine_tmr | ( | void | ) |
static void dhcp_free_reply | ( | struct dhcp * | dhcp ) | [static] |
static u8_t dhcp_get_option_byte | ( | u8_t * | ptr ) | [static] |
Return the byte of DHCP option data.
- Parameters:
-
client DHCP client. ptr pointer obtained by dhcp_get_option_ptr().
- Returns:
- byte value at the given address.
static u32_t dhcp_get_option_long | ( | u8_t * | ptr ) | [static] |
Return the 32-bit value of DHCP option data.
- Parameters:
-
client DHCP client. ptr pointer obtained by dhcp_get_option_ptr().
- Returns:
- byte value at the given address.
static u8_t * dhcp_get_option_ptr | ( | struct dhcp * | dhcp, |
u8_t | option_type | ||
) | [static] |
static u16_t dhcp_get_option_short | ( | u8_t * | ptr ) | [static] |
Return the 16-bit value of DHCP option data.
- Parameters:
-
client DHCP client. ptr pointer obtained by dhcp_get_option_ptr().
- Returns:
- byte value at the given address.
static void dhcp_handle_ack | ( | struct netif * | netif ) | [static] |
static void dhcp_handle_nak | ( | struct netif * | netif ) | [static] |
Back-off the DHCP client (because of a received NAK response).
Back-off the DHCP client because of a received NAK. Receiving a NAK means the client asked for something non-sensible, for example when it tries to renew a lease obtained on another network.
We clear any existing set IP address and restart DHCP negotiation afresh (as per RFC2131 3.2.3).
- Parameters:
-
netif the netif under DHCP control
static void dhcp_handle_offer | ( | struct netif * | netif ) | [static] |
void dhcp_inform | ( | struct netif * | netif ) |
Inform a DHCP server of our manual configuration.
inform server of our manual IP address
This informs DHCP servers of our fixed IP address configuration by sending an INFORM message. It does not involve DHCP address configuration, it is just here to be nice to the network.
- Parameters:
-
netif The lwIP network interface
void dhcp_network_changed | ( | struct netif * | netif ) |
static void dhcp_option_trailer | ( | struct dhcp * | dhcp ) | [static] |
static err_t dhcp_rebind | ( | struct netif * | netif ) | [static] |
static err_t dhcp_reboot | ( | struct netif * | netif ) | [static] |
static void dhcp_recv | ( | void * | arg, |
struct udp_pcb * | pcb, | ||
struct pbuf * | p, | ||
struct ip_addr * | addr, | ||
u16_t | port | ||
) | [static] |
err_t dhcp_release | ( | struct netif * | netif ) |
Release a DHCP lease.
release the DHCP lease, usually called before dhcp_stop()
- Parameters:
-
netif network interface which must release its lease
err_t dhcp_renew | ( | struct netif * | netif ) |
static err_t dhcp_select | ( | struct netif * | netif ) | [static] |
err_t dhcp_start | ( | struct netif * | netif ) |
Start DHCP negotiation for a network interface.
start DHCP configuration
If no DHCP client instance was attached to this interface, a new client is created first. If a DHCP client instance was already present, it restarts negotiation.
- Parameters:
-
netif The lwIP network interface
- Returns:
- lwIP error code
- ERR_OK - No error
- ERR_MEM - Out of memory
void dhcp_stop | ( | struct netif * | netif ) |
static void dhcp_t1_timeout | ( | struct netif * | netif ) | [static] |
static void dhcp_t2_timeout | ( | struct netif * | netif ) | [static] |
static void dhcp_timeout | ( | struct netif * | netif ) | [static] |
static err_t dhcp_unfold_reply | ( | struct dhcp * | dhcp, |
struct pbuf * | p | ||
) | [static] |
Extract the DHCP message and the DHCP options.
Extract the DHCP message and the DHCP options, each into a contiguous piece of memory. As a DHCP message is variable sized by its options, and also allows overriding some fields for options, the easy approach is to first unfold the options into a conitguous piece of memory, and use that further on.
copy the DHCP message without options
copy the DHCP options
Generated on Tue Jul 12 2022 19:17:24 by 1.7.2