NAT (IP Network Address Translator) More...
Go to the source code of this file.
| Macros | |
| #define | TRACE_LEVEL NAT_TRACE_LEVEL | 
| Functions | |
| void | natGetDefaultSettings (NatSettings *settings) | 
| Initialize settings with default values.  More... | |
| error_t | natInit (NatContext *context, const NatSettings *settings) | 
| NAT initialization.  More... | |
| error_t | natSetPublicInterface (NatContext *context, NetInterface *publicInterface) | 
| Specify the NAT public interface.  More... | |
| error_t | natSetPortFwdRule (NatContext *context, uint_t index, Ipv4Protocol protocol, uint16_t publicPort, NetInterface *privateInterface, Ipv4Addr privateIpAddr, uint16_t privatePort) | 
| Add port redirection rule.  More... | |
| error_t | natSetPortRangeFwdRule (NatContext *context, uint_t index, Ipv4Protocol protocol, uint16_t publicPortMin, uint16_t publicPortMax, NetInterface *privateInterface, Ipv4Addr privateIpAddr, uint16_t privatePortMin) | 
| Add port range redirection rule.  More... | |
| error_t | natClearPortFwdRule (NatContext *context, uint_t index) | 
| Remove port redirection rule.  More... | |
| error_t | natStart (NatContext *context) | 
| Start NAT operation.  More... | |
| error_t | natStop (NatContext *context) | 
| Stop NAT operation.  More... | |
| void | natDeinit (NatContext *context) | 
| Release NAT context.  More... | |
Detailed Description
NAT (IP Network Address Translator)
License
SPDX-License-Identifier: GPL-2.0-or-later
Copyright (C) 2010-2025 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.
Description
Network Address Translation (NAT) is a method of mapping one IP address space to another by modifying network address information in the IP header of packets. Refer to the following RFCs for complete details:
- RFC 2663: NAT Terminology and Considerations
- RFC 3022: Traditional IP Network Address Translator (Traditional NAT)
- RFC 4787: NAT Behavioral Requirements for Unicast UDP
- RFC 5382: NAT Behavioral Requirements for TCP
- RFC 5508: NAT Behavioral Requirements for ICMP
- Version
- 2.5.4
Definition in file nat.c.
Macro Definition Documentation
◆ TRACE_LEVEL
Function Documentation
◆ natClearPortFwdRule()
| error_t natClearPortFwdRule | ( | NatContext * | context, | 
| uint_t | index | ||
| ) | 
◆ natDeinit()
| void natDeinit | ( | NatContext * | context | ) | 
◆ natGetDefaultSettings()
| void natGetDefaultSettings | ( | NatSettings * | settings | ) | 
◆ natInit()
| error_t natInit | ( | NatContext * | context, | 
| const NatSettings * | settings | ||
| ) | 
◆ natSetPortFwdRule()
| error_t natSetPortFwdRule | ( | NatContext * | context, | 
| uint_t | index, | ||
| Ipv4Protocol | protocol, | ||
| uint16_t | publicPort, | ||
| NetInterface * | privateInterface, | ||
| Ipv4Addr | privateIpAddr, | ||
| uint16_t | privatePort | ||
| ) | 
Add port redirection rule.
- Parameters
- 
  [in] context Pointer to the NAT context [in] index Zero-based index identifying a given entry [in] protocol Transport protocol (IPV4_PROTOCOL_TCP or IPV4_PROTOCOL_UDP) [in] publicPort Public port to be redirected [in] privateInterface Destination interface [in] privateIpAddr Destination IP address [in] privatePort Destination port 
- Returns
- Error code
◆ natSetPortRangeFwdRule()
| error_t natSetPortRangeFwdRule | ( | NatContext * | context, | 
| uint_t | index, | ||
| Ipv4Protocol | protocol, | ||
| uint16_t | publicPortMin, | ||
| uint16_t | publicPortMax, | ||
| NetInterface * | privateInterface, | ||
| Ipv4Addr | privateIpAddr, | ||
| uint16_t | privatePortMin | ||
| ) | 
Add port range redirection rule.
- Parameters
- 
  [in] context Pointer to the NAT context [in] index Zero-based index identifying a given entry [in] protocol Transport protocol (IPV4_PROTOCOL_TCP or IPV4_PROTOCOL_UDP) [in] publicPortMin Public port range to be redirected (lower value) [in] publicPortMax Public port range to be redirected (upper value) [in] privateInterface Destination interface [in] privateIpAddr Destination IP address [in] privatePortMin Destination port (lower value) 
- Returns
- Error code
◆ natSetPublicInterface()
| error_t natSetPublicInterface | ( | NatContext * | context, | 
| NetInterface * | publicInterface | ||
| ) | 
◆ natStart()
| error_t natStart | ( | NatContext * | context | ) | 
◆ natStop()
| error_t natStop | ( | NatContext * | context | ) | 
