dhcp_common.h File Reference

Definitions common to DHCP client and server. More...

#include "core/net.h"
#include "core/ethernet.h"
#include "ipv4/ipv4.h"

Go to the source code of this file.

Macros

#define DHCP_SERVER_PORT   67
 
#define DHCP_CLIENT_PORT   68
 
#define DHCP_MIN_MSG_SIZE   300
 
#define DHCP_MAX_MSG_SIZE   548
 
#define DHCP_HARDWARE_TYPE_ETH   1
 
#define DHCP_MAGIC_COOKIE   0x63825363
 
#define DHCP_INFINITE_TIME   0xFFFFFFFF
 

Enumerations

enum  DhcpOpcode { DHCP_OPCODE_BOOTREQUEST = 1, DHCP_OPCODE_BOOTREPLY = 2 }
 DHCP opcodes. More...
 
enum  DhcpFlags { DHCP_FLAG_UNICAST = 0x0000, DHCP_FLAG_BROADCAST = 0x8000 }
 DHCP flags. More...
 
enum  DhcpMessageType {
  DHCP_MSG_TYPE_DISCOVER = 1, DHCP_MSG_TYPE_OFFER = 2, DHCP_MSG_TYPE_REQUEST = 3, DHCP_MSG_TYPE_DECLINE = 4,
  DHCP_MSG_TYPE_ACK = 5, DHCP_MSG_TYPE_NAK = 6, DHCP_MSG_TYPE_RELEASE = 7, DHCP_MSG_TYPE_INFORM = 8
}
 DHCP message types. More...
 
enum  DhcpOptionCode {
  DHCP_OPT_PAD = 0, DHCP_OPT_SUBNET_MASK = 1, DHCP_OPT_TIME_OFFSET = 2, DHCP_OPT_ROUTER = 3,
  DHCP_OPT_TIME_SERVER = 4, DHCP_OPT_NAME_SERVER = 5, DHCP_OPT_DNS_SERVER = 6, DHCP_OPT_LOG_SERVER = 7,
  DHCP_OPT_COOKIE_SERVER = 8, DHCP_OPT_LPR_SERVER = 9, DHCP_OPT_IMPRESS_SERVER = 10, DHCP_OPT_RESOURCE_LOCATION_SERVER = 11,
  DHCP_OPT_HOST_NAME = 12, DHCP_OPT_BOOT_FILE_SIZE = 13, DHCP_OPT_MERIT_DUMP_FILE = 14, DHCP_OPT_DOMAIN_NAME = 15,
  DHCP_OPT_SWAP_SERVER = 16, DHCP_OPT_ROOT_PATH = 17, DHCP_OPT_EXTENSIONS_PATH = 18, DHCP_OPT_IP_FORWARDING = 19,
  DHCP_OPT_NON_LOCAL_SOURCE_ROUTING = 20, DHCP_OPT_POLICY_FILTER = 21, DHCP_OPT_MAX_DATAGRAM_REASSEMBLY_SIZE = 22, DHCP_OPT_DEFAULT_IP_TTL = 23,
  DHCP_OPT_PATH_MTU_AGING_TIMEOUT = 24, DHCP_OPT_PATH_MTU_PLATEAU_TABLE = 25, DHCP_OPT_INTERFACE_MTU = 26, DHCP_OPT_ALL_SUBNETS_ARE_LOCAL = 27,
  DHCP_OPT_BROADCAST_ADDR = 28, DHCP_OPT_PERFORM_MASK_DISCOVERY = 29, DHCP_OPT_MASK_SUPPLIER = 30, DHCP_OPT_PERFORM_ROUTER_DISCOVERY = 31,
  DHCP_OPT_ROUTER_SOLICITATION_ADDR = 32, DHCP_OPT_STATIC_ROUTE = 33, DHCP_OPT_TRAILER_ENCAPSULATION = 34, DHCP_OPT_ARP_CACHE_TIMEOUT = 35,
  DHCP_OPT_ETHERNET_ENCAPSULATION = 36, DHCP_OPT_TCP_DEFAULT_TTL = 37, DHCP_OPT_TCP_KEEPALIVE_INTERVAL = 38, DHCP_OPT_TCP_KEEPALIVE_GARBAGE = 39,
  DHCP_OPT_NIS_DOMAIN = 40, DHCP_OPT_NIS_SERVER = 41, DHCP_OPT_NTP_SERVER = 42, DHCP_OPT_VENDOR_SPECIFIC_INFO = 43,
  DHCP_OPT_NETBIOS_NBNS_SERVER = 44, DHCP_OPT_NETBIOS_NBDD_SERVER = 45, DHCP_OPT_NETBIOS_NODE_TYPE = 46, DHCP_OPT_NETBIOS_SCOPE = 47,
  DHCP_OPT_X11_FONT_SERVER = 48, DHCP_OPT_X11_DISPLAY_MANAGER = 49, DHCP_OPT_REQUESTED_IP_ADDR = 50, DHCP_OPT_IP_ADDRESS_LEASE_TIME = 51,
  DHCP_OPT_OPTION_OVERLOAD = 52, DHCP_OPT_DHCP_MESSAGE_TYPE = 53, DHCP_OPT_SERVER_ID = 54, DHCP_OPT_PARAM_REQUEST_LIST = 55,
  DHCP_OPT_MESSAGE = 56, DHCP_OPT_MAX_DHCP_MESSAGE_SIZE = 57, DHCP_OPT_RENEWAL_TIME_VALUE = 58, DHCP_OPT_REBINDING_TIME_VALUE = 59,
  DHCP_OPT_VENDOR_CLASS_ID = 60, DHCP_OPT_CLIENT_ID = 61, DHCP_OPT_NISP_DOMAIN = 64, DHCP_OPT_NISP_SERVER = 65,
  DHCP_OPT_TFTP_SERVER_NAME = 66, DHCP_OPT_BOOTFILE_NAME = 67, DHCP_OPT_MOBILE_IP_HOME_AGENT = 68, DHCP_OPT_SMTP_SERVER = 69,
  DHCP_OPT_POP3_SERVER = 70, DHCP_OPT_NNTP_SERVER = 71, DHCP_OPT_DEFAULT_WWW_SERVER = 72, DHCP_OPT_DEFAULT_FINGER_SERVER = 73,
  DHCP_OPT_DEFAULT_IRC_SERVER = 74, DHCP_OPT_STREET_TALK_SERVER = 75, DHCP_OPT_STDA_SERVER = 76, DHCP_OPT_RAPID_COMMIT = 80,
  DHCP_OPT_CLIENT_FQDN = 81, DHCP_OPT_RELAY_AGENT_INFO = 82, DHCP_OPT_CAPTIVE_PORTAL = 114, DHCP_OPT_AUTO_CONFIG = 116,
  DHCP_OPT_NAME_SERVICE_SEARCH = 117, DHCP_OPT_SUBNET_SELECTION = 118, DHCP_OPT_DOMAIN_SEARCH = 119, DHCP_OPT_SIP_SERVER = 120,
  DHCP_OPT_CLASSLESS_STATIC_ROUTE = 121, DHCP_OPT_END = 255
}
 DHCP option codes. More...
 

Functions

error_t dhcpAddOption (DhcpMessage *message, size_t *messageLen, uint8_t optionCode, const void *optionValue, size_t optionLen)
 Append an option to a DHCP message. More...
 
DhcpOptiondhcpGetOption (const DhcpMessage *message, size_t length, uint8_t optionCode)
 Search a DHCP message for a given option. More...
 

Variables

typedef __packed_struct
 DHCP message. More...
 
uint8_t htype
 
uint8_t hlen
 
uint8_t hops
 
uint32_t xid
 
uint16_t secs
 
uint16_t flags
 
Ipv4Addr ciaddr
 
Ipv4Addr yiaddr
 
Ipv4Addr siaddr
 
Ipv4Addr giaddr
 
MacAddr chaddr
 
uint8_t unused [10]
 
uint8_t sname [64]
 
uint8_t file [128]
 
uint32_t magicCookie
 
uint8_t options []
 
 DhcpMessage
 
uint8_t length
 
uint8_t value []
 
 DhcpOption
 

Detailed Description

Definitions common to DHCP client and server.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file dhcp_common.h.

Macro Definition Documentation

◆ DHCP_CLIENT_PORT

#define DHCP_CLIENT_PORT   68

Definition at line 41 of file dhcp_common.h.

◆ DHCP_HARDWARE_TYPE_ETH

#define DHCP_HARDWARE_TYPE_ETH   1

Definition at line 49 of file dhcp_common.h.

◆ DHCP_INFINITE_TIME

#define DHCP_INFINITE_TIME   0xFFFFFFFF

Definition at line 53 of file dhcp_common.h.

◆ DHCP_MAGIC_COOKIE

#define DHCP_MAGIC_COOKIE   0x63825363

Definition at line 51 of file dhcp_common.h.

◆ DHCP_MAX_MSG_SIZE

#define DHCP_MAX_MSG_SIZE   548

Definition at line 46 of file dhcp_common.h.

◆ DHCP_MIN_MSG_SIZE

#define DHCP_MIN_MSG_SIZE   300

Definition at line 44 of file dhcp_common.h.

◆ DHCP_SERVER_PORT

#define DHCP_SERVER_PORT   67

Definition at line 40 of file dhcp_common.h.

Enumeration Type Documentation

◆ DhcpFlags

enum DhcpFlags

DHCP flags.

Enumerator
DHCP_FLAG_UNICAST 
DHCP_FLAG_BROADCAST 

Definition at line 76 of file dhcp_common.h.

◆ DhcpMessageType

DHCP message types.

Enumerator
DHCP_MSG_TYPE_DISCOVER 
DHCP_MSG_TYPE_OFFER 
DHCP_MSG_TYPE_REQUEST 
DHCP_MSG_TYPE_DECLINE 
DHCP_MSG_TYPE_ACK 
DHCP_MSG_TYPE_NAK 
DHCP_MSG_TYPE_RELEASE 
DHCP_MSG_TYPE_INFORM 

Definition at line 87 of file dhcp_common.h.

◆ DhcpOpcode

enum DhcpOpcode

DHCP opcodes.

Enumerator
DHCP_OPCODE_BOOTREQUEST 
DHCP_OPCODE_BOOTREPLY 

Definition at line 65 of file dhcp_common.h.

◆ DhcpOptionCode

DHCP option codes.

Enumerator
DHCP_OPT_PAD 
DHCP_OPT_SUBNET_MASK 
DHCP_OPT_TIME_OFFSET 
DHCP_OPT_ROUTER 
DHCP_OPT_TIME_SERVER 
DHCP_OPT_NAME_SERVER 
DHCP_OPT_DNS_SERVER 
DHCP_OPT_LOG_SERVER 
DHCP_OPT_COOKIE_SERVER 
DHCP_OPT_LPR_SERVER 
DHCP_OPT_IMPRESS_SERVER 
DHCP_OPT_RESOURCE_LOCATION_SERVER 
DHCP_OPT_HOST_NAME 
DHCP_OPT_BOOT_FILE_SIZE 
DHCP_OPT_MERIT_DUMP_FILE 
DHCP_OPT_DOMAIN_NAME 
DHCP_OPT_SWAP_SERVER 
DHCP_OPT_ROOT_PATH 
DHCP_OPT_EXTENSIONS_PATH 
DHCP_OPT_IP_FORWARDING 
DHCP_OPT_NON_LOCAL_SOURCE_ROUTING 
DHCP_OPT_POLICY_FILTER 
DHCP_OPT_MAX_DATAGRAM_REASSEMBLY_SIZE 
DHCP_OPT_DEFAULT_IP_TTL 
DHCP_OPT_PATH_MTU_AGING_TIMEOUT 
DHCP_OPT_PATH_MTU_PLATEAU_TABLE 
DHCP_OPT_INTERFACE_MTU 
DHCP_OPT_ALL_SUBNETS_ARE_LOCAL 
DHCP_OPT_BROADCAST_ADDR 
DHCP_OPT_PERFORM_MASK_DISCOVERY 
DHCP_OPT_MASK_SUPPLIER 
DHCP_OPT_PERFORM_ROUTER_DISCOVERY 
DHCP_OPT_ROUTER_SOLICITATION_ADDR 
DHCP_OPT_STATIC_ROUTE 
DHCP_OPT_TRAILER_ENCAPSULATION 
DHCP_OPT_ARP_CACHE_TIMEOUT 
DHCP_OPT_ETHERNET_ENCAPSULATION 
DHCP_OPT_TCP_DEFAULT_TTL 
DHCP_OPT_TCP_KEEPALIVE_INTERVAL 
DHCP_OPT_TCP_KEEPALIVE_GARBAGE 
DHCP_OPT_NIS_DOMAIN 
DHCP_OPT_NIS_SERVER 
DHCP_OPT_NTP_SERVER 
DHCP_OPT_VENDOR_SPECIFIC_INFO 
DHCP_OPT_NETBIOS_NBNS_SERVER 
DHCP_OPT_NETBIOS_NBDD_SERVER 
DHCP_OPT_NETBIOS_NODE_TYPE 
DHCP_OPT_NETBIOS_SCOPE 
DHCP_OPT_X11_FONT_SERVER 
DHCP_OPT_X11_DISPLAY_MANAGER 
DHCP_OPT_REQUESTED_IP_ADDR 
DHCP_OPT_IP_ADDRESS_LEASE_TIME 
DHCP_OPT_OPTION_OVERLOAD 
DHCP_OPT_DHCP_MESSAGE_TYPE 
DHCP_OPT_SERVER_ID 
DHCP_OPT_PARAM_REQUEST_LIST 
DHCP_OPT_MESSAGE 
DHCP_OPT_MAX_DHCP_MESSAGE_SIZE 
DHCP_OPT_RENEWAL_TIME_VALUE 
DHCP_OPT_REBINDING_TIME_VALUE 
DHCP_OPT_VENDOR_CLASS_ID 
DHCP_OPT_CLIENT_ID 
DHCP_OPT_NISP_DOMAIN 
DHCP_OPT_NISP_SERVER 
DHCP_OPT_TFTP_SERVER_NAME 
DHCP_OPT_BOOTFILE_NAME 
DHCP_OPT_MOBILE_IP_HOME_AGENT 
DHCP_OPT_SMTP_SERVER 
DHCP_OPT_POP3_SERVER 
DHCP_OPT_NNTP_SERVER 
DHCP_OPT_DEFAULT_WWW_SERVER 
DHCP_OPT_DEFAULT_FINGER_SERVER 
DHCP_OPT_DEFAULT_IRC_SERVER 
DHCP_OPT_STREET_TALK_SERVER 
DHCP_OPT_STDA_SERVER 
DHCP_OPT_RAPID_COMMIT 
DHCP_OPT_CLIENT_FQDN 
DHCP_OPT_RELAY_AGENT_INFO 
DHCP_OPT_CAPTIVE_PORTAL 
DHCP_OPT_AUTO_CONFIG 
DHCP_OPT_NAME_SERVICE_SEARCH 
DHCP_OPT_SUBNET_SELECTION 
DHCP_OPT_DOMAIN_SEARCH 
DHCP_OPT_SIP_SERVER 
DHCP_OPT_CLASSLESS_STATIC_ROUTE 
DHCP_OPT_END 

Definition at line 104 of file dhcp_common.h.

Function Documentation

◆ dhcpAddOption()

error_t dhcpAddOption ( DhcpMessage message,
size_t *  messageLen,
uint8_t  optionCode,
const void *  optionValue,
size_t  optionLen 
)

Append an option to a DHCP message.

Parameters
[in]messagePointer to the DHCP message
[in,out]messageLenActual length of the DHCP message
[in]optionCodeOption code
[in]optionValueOption value
[in]optionLenLength of the option value
Returns
Error code

Definition at line 56 of file dhcp_common.c.

◆ dhcpGetOption()

DhcpOption* dhcpGetOption ( const DhcpMessage message,
size_t  length,
uint8_t  optionCode 
)

Search a DHCP message for a given option.

Parameters
[in]messagePointer to the DHCP message
[in]lengthLength of the message
[in]optionCodeCode of the option to find
Returns
If the specified option is found, a pointer to the corresponding option is returned. Otherwise NULL pointer is returned

Definition at line 118 of file dhcp_common.c.

Variable Documentation

◆ __packed_struct

typedef __packed_struct
Initial value:
{
uint8_t op

DHCP message.

DHCP option.

Definition at line 207 of file dhcp_common.h.

◆ chaddr

MacAddr chaddr

Definition at line 220 of file dhcp_common.h.

◆ ciaddr

Ipv4Addr ciaddr

Definition at line 216 of file dhcp_common.h.

◆ DhcpMessage

DhcpMessage

Definition at line 226 of file dhcp_common.h.

◆ DhcpOption

DhcpOption

Definition at line 238 of file dhcp_common.h.

◆ file

uint8_t file[128]

Definition at line 223 of file dhcp_common.h.

◆ flags

uint16_t flags

Definition at line 215 of file dhcp_common.h.

◆ giaddr

Ipv4Addr giaddr

Definition at line 219 of file dhcp_common.h.

◆ hlen

uint8_t hlen

Definition at line 211 of file dhcp_common.h.

◆ hops

uint8_t hops

Definition at line 212 of file dhcp_common.h.

◆ htype

uint8_t htype

Definition at line 210 of file dhcp_common.h.

◆ length

uint8_t length

Definition at line 236 of file dhcp_common.h.

◆ magicCookie

uint32_t magicCookie

Definition at line 224 of file dhcp_common.h.

◆ options

uint8_t options[]

Definition at line 225 of file dhcp_common.h.

◆ secs

uint16_t secs

Definition at line 214 of file dhcp_common.h.

◆ siaddr

Ipv4Addr siaddr

Definition at line 218 of file dhcp_common.h.

◆ sname

uint8_t sname[64]

Definition at line 222 of file dhcp_common.h.

◆ unused

uint32_t unused

Definition at line 221 of file dhcp_common.h.

◆ value

uint8_t value[]

Definition at line 237 of file dhcp_common.h.

◆ xid

uint32_t xid

Definition at line 213 of file dhcp_common.h.

◆ yiaddr

Ipv4Addr yiaddr

Definition at line 217 of file dhcp_common.h.

uint16_t op
Definition: arp.h:156