91 lines
2.2 KiB
C
91 lines
2.2 KiB
C
/** @file
|
|
@brief UDP data handler
|
|
|
|
This is not to be included by the application.
|
|
*/
|
|
|
|
/*
|
|
* Copyright (c) 2016 Intel Corporation
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#ifndef __UDP_H
|
|
#define __UDP_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <net/net_core.h>
|
|
#include <net/net_ip.h>
|
|
#include <net/nbuf.h>
|
|
|
|
#include "connection.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/**
|
|
* @brief Register a callback to be called when UDP packet
|
|
* is received corresponding to received packet.
|
|
*
|
|
* @param remote_addr Remote address of the connection end point.
|
|
* @param local_addr Local address of the connection end point.
|
|
* @param remote_port Remote port of the connection end point.
|
|
* @param local_port Local port of the connection end point.
|
|
* @param cb Callback to be called
|
|
* @param user_data User data supplied by caller.
|
|
* @param handle UDP handle that can be used when unregistering
|
|
*
|
|
* @return Return 0 if the registration succeed, <0 otherwise.
|
|
*/
|
|
static inline int net_udp_register(const struct sockaddr *remote_addr,
|
|
const struct sockaddr *local_addr,
|
|
uint16_t remote_port,
|
|
uint16_t local_port,
|
|
net_conn_cb_t cb,
|
|
void *user_data,
|
|
void **handle)
|
|
{
|
|
return net_conn_register(IPPROTO_UDP, remote_addr, local_addr,
|
|
remote_port, local_port, cb, user_data,
|
|
handle);
|
|
}
|
|
|
|
/**
|
|
* @brief Unregister UDP handler.
|
|
*
|
|
* @param handle Handle from registering.
|
|
*
|
|
* @return Return 0 if the unregistration succeed, <0 otherwise.
|
|
*/
|
|
static inline int net_udp_unregister(void *handle)
|
|
{
|
|
return net_conn_unregister(handle);
|
|
}
|
|
|
|
#if defined(CONFIG_NET_UDP)
|
|
static inline void net_udp_init(void)
|
|
{
|
|
return;
|
|
}
|
|
#else
|
|
#define net_udp_init(...)
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* __UDP_H */
|