Loading...
Searching...
No Matches
uhcp.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
9#pragma once
10
31
32#include <stdint.h>
33#include <stddef.h>
34#include <arpa/inet.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
41#define UHCP_MAGIC (0x55484350) /* "UHCP" in hex */
42
44#define UHCP_VER (0)
45
47#define UHCP_PORT (12345U)
48
50#define UHCP_PORT_STR "12345"
51
57
61typedef struct __attribute__((packed)) {
62 uint32_t uhcp_magic;
63 uint8_t ver_type;
66
72typedef struct __attribute__((packed)) {
74 uint8_t prefix_len;
76
82typedef struct __attribute__((packed)) {
84 uint8_t prefix_len;
86 uint8_t prefix[];
88
90typedef unsigned uhcp_iface_t;
91
104void uhcp_handle_udp(uint8_t *buf, size_t len, uint8_t *src, uint16_t port, uhcp_iface_t iface);
105
119void uhcp_handle_req(uhcp_req_t *req, uint8_t *src, uint16_t port, uhcp_iface_t iface);
120
134void uhcp_handle_push(uhcp_push_t *req, uint8_t *src, uint16_t port, uhcp_iface_t iface);
135
154void uhcp_handle_prefix(uint8_t *prefix, uint8_t prefix_len, uint16_t lifetime, uint8_t *src, uhcp_iface_t iface);
155
164static inline void uhcp_hdr_set(uhcp_hdr_t *hdr, uhcp_type_t type)
165{
167 hdr->ver_type = (UHCP_VER << 4) | (type & 0xF);
168}
169
181int udp_sendto(uint8_t *buf, size_t len, uint8_t *dst, uint16_t dst_port, uhcp_iface_t dst_iface);
182
183#ifdef __cplusplus
184}
185#endif
186
static uint32_t htonl(uint32_t v)
Convert from host byte order to network byte order, 32 bit.
Definition byteorder.h:525
void uhcp_handle_udp(uint8_t *buf, size_t len, uint8_t *src, uint16_t port, uhcp_iface_t iface)
handle incoming UDP packet
#define UHCP_VER
UHCP version of this header.
Definition uhcp.h:44
void uhcp_handle_prefix(uint8_t *prefix, uint8_t prefix_len, uint16_t lifetime, uint8_t *src, uhcp_iface_t iface)
handle incoming prefix (as parsed from push packet)
uhcp_type_t
Enum containing possible UHCP packet types.
Definition uhcp.h:53
unsigned uhcp_iface_t
typedef for interface handle
Definition uhcp.h:90
void uhcp_handle_push(uhcp_push_t *req, uint8_t *src, uint16_t port, uhcp_iface_t iface)
handle incoming UHCP push packet
static void uhcp_hdr_set(uhcp_hdr_t *hdr, uhcp_type_t type)
function to set constant values in UHCP header
Definition uhcp.h:164
int udp_sendto(uint8_t *buf, size_t len, uint8_t *dst, uint16_t dst_port, uhcp_iface_t dst_iface)
UDP send function used by UHCP client / server.
void uhcp_handle_req(uhcp_req_t *req, uint8_t *src, uint16_t port, uhcp_iface_t iface)
handle incoming UHCP request packet
#define UHCP_MAGIC
UHCP magic number.
Definition uhcp.h:41
@ UHCP_REQ
packet is a request packet
Definition uhcp.h:54
@ UHCP_PUSH
packet is a push / answer packet
Definition uhcp.h:55
Definitions for internet operations.
UHCP packet header struct.
Definition uhcp.h:61
uint32_t uhcp_magic
always contains UHCP in hex
Definition uhcp.h:62
uint8_t ver_type
four bits version number, four bits packet type (see uchp_type_t)
Definition uhcp.h:63
struct for push packets
Definition uhcp.h:82
uint8_t prefix[]
contains the assigned prefix
Definition uhcp.h:86
uhcp_hdr_t hdr
member holding parent type
Definition uhcp.h:83
uint8_t prefix_len
contains the prefix length of assigned prefix
Definition uhcp.h:84
struct for request packets
Definition uhcp.h:72
uint8_t prefix_len
contains the requested prefix length
Definition uhcp.h:74
uhcp_hdr_t hdr
member holding parent type
Definition uhcp.h:73