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
30#ifndef NET_UHCP_H
31#define NET_UHCP_H
32
33#include <stdint.h>
34#include <stddef.h>
35#include <arpa/inet.h>
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
42#define UHCP_MAGIC (0x55484350) /* "UHCP" in hex */
43
45#define UHCP_VER (0)
46
48#define UHCP_PORT (12345U)
49
51#define UHCP_PORT_STR "12345"
52
58
62typedef struct __attribute__((packed)) {
63 uint32_t uhcp_magic;
64 uint8_t ver_type;
67
73typedef struct __attribute__((packed)) {
75 uint8_t prefix_len;
77
83typedef struct __attribute__((packed)) {
85 uint8_t prefix_len;
87 uint8_t prefix[];
89
91typedef unsigned uhcp_iface_t;
92
105void uhcp_handle_udp(uint8_t *buf, size_t len, uint8_t *src, uint16_t port, uhcp_iface_t iface);
106
120void uhcp_handle_req(uhcp_req_t *req, uint8_t *src, uint16_t port, uhcp_iface_t iface);
121
135void uhcp_handle_push(uhcp_push_t *req, uint8_t *src, uint16_t port, uhcp_iface_t iface);
136
155void uhcp_handle_prefix(uint8_t *prefix, uint8_t prefix_len, uint16_t lifetime, uint8_t *src, uhcp_iface_t iface);
156
165static inline void uhcp_hdr_set(uhcp_hdr_t *hdr, uhcp_type_t type)
166{
168 hdr->ver_type = (UHCP_VER << 4) | (type & 0xF);
169}
170
182int udp_sendto(uint8_t *buf, size_t len, uint8_t *dst, uint16_t dst_port, uhcp_iface_t dst_iface);
183
184#ifdef __cplusplus
185}
186#endif
187
188#endif /* NET_UHCP_H */
static uint32_t htonl(uint32_t v)
Convert from host byte order to network byte order, 32 bit.
Definition byteorder.h:526
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:45
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:54
unsigned uhcp_iface_t
typedef for interface handle
Definition uhcp.h:91
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:165
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:42
@ UHCP_REQ
packet is a request packet
Definition uhcp.h:55
@ UHCP_PUSH
packet is a push / answer packet
Definition uhcp.h:56
Definitions for internet operations.
UHCP packet header struct.
Definition uhcp.h:62
uint32_t uhcp_magic
always contains UHCP in hex
Definition uhcp.h:63
uint8_t ver_type
four bits version number, four bits packet type (see uchp_type_t)
Definition uhcp.h:64
struct for push packets
Definition uhcp.h:83
uhcp_hdr_t hdr
member holding parent type
Definition uhcp.h:84
uint8_t prefix_len
contains the prefix length of assigned prefix
Definition uhcp.h:85
struct for request packets
Definition uhcp.h:73
uint8_t prefix_len
contains the requested prefix length
Definition uhcp.h:75
uhcp_hdr_t hdr
member holding parent type
Definition uhcp.h:74