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
 

Typedefs

struct {
   uint8_t   op
 
   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
 DHCP message. More...
 
struct {
   uint8_t   code
 
   uint8_t   length
 
   uint8_t   value []
 
DhcpOption
 DHCP option. More...
 

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_MESSAGE_TYPE_DISCOVER = 1, DHCP_MESSAGE_TYPE_OFFER = 2, DHCP_MESSAGE_TYPE_REQUEST = 3, DHCP_MESSAGE_TYPE_DECLINE = 4,
  DHCP_MESSAGE_TYPE_ACK = 5, DHCP_MESSAGE_TYPE_NAK = 6, DHCP_MESSAGE_TYPE_RELEASE = 7, DHCP_MESSAGE_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_ADDRESS = 28, DHCP_OPT_PERFORM_MASK_DISCOVERY = 29, DHCP_OPT_MASK_SUPPLIER = 30, DHCP_OPT_PERFORM_ROUTER_DISCOVERY = 31,
  DHCP_OPT_ROUTER_SOLICITATION_ADDRESS = 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_ADDRESS = 50, DHCP_OPT_IP_ADDRESS_LEASE_TIME = 51,
  DHCP_OPT_OPTION_OVERLOAD = 52, DHCP_OPT_DHCP_MESSAGE_TYPE = 53, DHCP_OPT_SERVER_IDENTIFIER = 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_IDENTIFIER = 60, DHCP_OPT_CLIENT_IDENTIFIER = 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_STREETTALK_SERVER = 75, DHCP_OPT_STDA_SERVER = 76, DHCP_OPT_RAPID_COMMIT = 80,
  DHCP_OPT_END = 255
}
 DHCP option codes. More...
 

Functions

void dhcpAddOption (DhcpMessage *message, 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)
 Find the specified option in a DHCP message. More...
 

Detailed Description

Definitions common to DHCP client and server.

License

Copyright (C) 2010-2018 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
1.9.0

Definition in file dhcp_common.h.

Macro Definition Documentation

◆ DHCP_CLIENT_PORT

#define DHCP_CLIENT_PORT   68

Definition at line 39 of file dhcp_common.h.

◆ DHCP_HARDWARE_TYPE_ETH

#define DHCP_HARDWARE_TYPE_ETH   1

Definition at line 47 of file dhcp_common.h.

◆ DHCP_INFINITE_TIME

#define DHCP_INFINITE_TIME   0xFFFFFFFF

Definition at line 51 of file dhcp_common.h.

◆ DHCP_MAGIC_COOKIE

#define DHCP_MAGIC_COOKIE   0x63825363

Definition at line 49 of file dhcp_common.h.

◆ DHCP_MAX_MSG_SIZE

#define DHCP_MAX_MSG_SIZE   548

Definition at line 44 of file dhcp_common.h.

◆ DHCP_MIN_MSG_SIZE

#define DHCP_MIN_MSG_SIZE   300

Definition at line 42 of file dhcp_common.h.

◆ DHCP_SERVER_PORT

#define DHCP_SERVER_PORT   67

Definition at line 38 of file dhcp_common.h.

Typedef Documentation

◆ DhcpMessage

typedef { ... } DhcpMessage

DHCP message.

◆ DhcpOption

typedef { ... } DhcpOption

DHCP option.

Enumeration Type Documentation

◆ DhcpFlags

enum DhcpFlags

DHCP flags.

Enumerator
DHCP_FLAG_UNICAST 
DHCP_FLAG_BROADCAST 

Definition at line 74 of file dhcp_common.h.

◆ DhcpMessageType

DHCP message types.

Enumerator
DHCP_MESSAGE_TYPE_DISCOVER 
DHCP_MESSAGE_TYPE_OFFER 
DHCP_MESSAGE_TYPE_REQUEST 
DHCP_MESSAGE_TYPE_DECLINE 
DHCP_MESSAGE_TYPE_ACK 
DHCP_MESSAGE_TYPE_NAK 
DHCP_MESSAGE_TYPE_RELEASE 
DHCP_MESSAGE_TYPE_INFORM 

Definition at line 85 of file dhcp_common.h.

◆ DhcpOpcode

enum DhcpOpcode

DHCP opcodes.

Enumerator
DHCP_OPCODE_BOOTREQUEST 
DHCP_OPCODE_BOOTREPLY 

Definition at line 63 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_ADDRESS 
DHCP_OPT_PERFORM_MASK_DISCOVERY 
DHCP_OPT_MASK_SUPPLIER 
DHCP_OPT_PERFORM_ROUTER_DISCOVERY 
DHCP_OPT_ROUTER_SOLICITATION_ADDRESS 
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_ADDRESS 
DHCP_OPT_IP_ADDRESS_LEASE_TIME 
DHCP_OPT_OPTION_OVERLOAD 
DHCP_OPT_DHCP_MESSAGE_TYPE 
DHCP_OPT_SERVER_IDENTIFIER 
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_IDENTIFIER 
DHCP_OPT_CLIENT_IDENTIFIER 
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_STREETTALK_SERVER 
DHCP_OPT_STDA_SERVER 
DHCP_OPT_RAPID_COMMIT 
DHCP_OPT_END 

Definition at line 102 of file dhcp_common.h.

Function Documentation

◆ dhcpAddOption()

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

Append an option to a DHCP message.

Parameters
[in]messagePointer to the DHCP message
[in]optionCodeOption code
[in]optionValueOption value
[in]optionLenLength of the option value

Definition at line 49 of file dhcp_common.c.

◆ dhcpGetOption()

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

Find the specified option in a DHCP message.

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 106 of file dhcp_common.c.

Variable Documentation

◆ chaddr

MacAddr chaddr

Definition at line 207 of file dhcp_common.h.

◆ ciaddr

Ipv4Addr ciaddr

Definition at line 203 of file dhcp_common.h.

◆ code

uint8_t code

Definition at line 222 of file dhcp_common.h.

◆ file

uint8_t file[128]

Definition at line 210 of file dhcp_common.h.

◆ flags

uint16_t flags

Definition at line 202 of file dhcp_common.h.

◆ giaddr

Ipv4Addr giaddr

Definition at line 206 of file dhcp_common.h.

◆ hlen

uint8_t hlen

Definition at line 198 of file dhcp_common.h.

◆ hops

uint8_t hops

Definition at line 199 of file dhcp_common.h.

◆ htype

uint8_t htype

Definition at line 197 of file dhcp_common.h.

◆ length

uint8_t length

Definition at line 223 of file dhcp_common.h.

◆ magicCookie

uint32_t magicCookie

Definition at line 211 of file dhcp_common.h.

◆ op

uint8_t op

Definition at line 196 of file dhcp_common.h.

◆ options

uint8_t options[]

Definition at line 212 of file dhcp_common.h.

◆ secs

uint16_t secs

Definition at line 201 of file dhcp_common.h.

◆ siaddr

Ipv4Addr siaddr

Definition at line 205 of file dhcp_common.h.

◆ sname

uint8_t sname[64]

Definition at line 209 of file dhcp_common.h.

◆ unused

uint8_t unused[10]

Definition at line 208 of file dhcp_common.h.

◆ value

uint8_t value[]

Definition at line 224 of file dhcp_common.h.

◆ xid

uint32_t xid

Definition at line 200 of file dhcp_common.h.

◆ yiaddr

Ipv4Addr yiaddr

Definition at line 204 of file dhcp_common.h.