|
| 1 | +/** @file |
| 2 | + @brief UDP utility functions |
| 3 | + */ |
| 4 | + |
| 5 | +/* |
| 6 | + * Copyright (c) 2017 Intel Corporation |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: Apache-2.0 |
| 9 | + */ |
| 10 | + |
| 11 | +#ifndef __UDP_H |
| 12 | +#define __UDP_H |
| 13 | + |
| 14 | +#include <zephyr/types.h> |
| 15 | + |
| 16 | +#include <net/net_core.h> |
| 17 | +#include <net/net_ip.h> |
| 18 | +#include <net/net_pkt.h> |
| 19 | + |
| 20 | +#ifdef __cplusplus |
| 21 | +extern "C" { |
| 22 | +#endif |
| 23 | + |
| 24 | +#if defined(CONFIG_NET_UDP) |
| 25 | + |
| 26 | +/** |
| 27 | + * @brief Get UDP packet header data from net_pkt. |
| 28 | + * |
| 29 | + * @details The values in the returned header are in network byte order. |
| 30 | + * Note that you must access the UDP header values by the returned pointer, |
| 31 | + * the hdr parameter is just a placeholder for the header data and it might |
| 32 | + * not contain anything if header can fit properly in the first fragment in |
| 33 | + * the network packet. |
| 34 | + * |
| 35 | + * @param pkt Network packet |
| 36 | + * @param hdr Where to place the header if it does not fit in first fragment |
| 37 | + * of the network packet. |
| 38 | + * |
| 39 | + * @return Return pointer to header or NULL if something went wrong. |
| 40 | + */ |
| 41 | +struct net_udp_hdr *net_udp_get_hdr(struct net_pkt *pkt, |
| 42 | + struct net_udp_hdr *hdr); |
| 43 | + |
| 44 | +/** |
| 45 | + * @brief Set UDP packet header data in net_pkt. |
| 46 | + * |
| 47 | + * @details The values in the header must be in network byte order. |
| 48 | + * This function is normally called after a call to net_udp_get_hdr(). |
| 49 | + * The hdr parameter value should be the same that is returned by function |
| 50 | + * net_udp_get_hdr() call. Note that if the UDP header fits in first net_pkt |
| 51 | + * fragment, then this function will not do anything as your hdr parameter |
| 52 | + * was pointing directly to net_pkt. |
| 53 | + * |
| 54 | + * @param pkt Network packet |
| 55 | + * @param hdr Header data pointer that was returned by net_udp_get_hdr(). |
| 56 | + * |
| 57 | + * @return Return pointer to header or NULL if something went wrong. |
| 58 | + */ |
| 59 | +struct net_udp_hdr *net_udp_set_hdr(struct net_pkt *pkt, |
| 60 | + struct net_udp_hdr *hdr); |
| 61 | +#else |
| 62 | +#define net_udp_get_hdr(pkt, frag) NULL |
| 63 | +#define net_udp_set_hdr(pkt, frag) NULL |
| 64 | +#endif /* CONFIG_NET_UDP */ |
| 65 | + |
| 66 | +#ifdef __cplusplus |
| 67 | +} |
| 68 | +#endif |
| 69 | + |
| 70 | +#endif /* __UDP_H */ |
0 commit comments