This chapter contains a description of all NetX Duo NAT API services (listed below) in alphabetical order.
Note: In the Return Values section in the following API descriptions, values in BOLD are not affected by the NX_DISABLE_ERROR_CHECKING define that is used to disable API error checking, while non-bold values are completely disabled.
Create a NAT Server
UINT nx_nat_create(
NX_NAT_DEVICE *nat_ptr,
NX_IP *ip_ptr,
UINT global_interface_index,
VOID *dynamic_cache_memory,
UINT dynamic_cache_size);
This service creates an instance of the NAT server.
Application code
#define NX_NAT_ENTRY_CACHE_SIZE 20480
static UCHAR nat_cache[NX_NAT_ENTRY_CACHE_SIZE];
UINT global_interface_index = 0;
/* Create a NAT Server and cache with a global interface index. */
status = nx_nat_create(nat_ptr, ip_ptr, global_interface_index,
nat_cache, NX_NAT_ENTRY_CACHE_SIZE);
/* If status = NX_SUCCESS, the NAT instance was successfully
created. */
Delete a NAT Server
UINT nx_nat_delete(NX_NAT_DEVICE *nat_ptr);
This service deletes a previously created NAT Server.
Application code
/* Delete the NAT instance. */
status = nx_nat_delete (nat_ptr);
/* If the NAT instance was successfully deleted, status = NX_SUCCESS. */
Enable the IP instance for NAT
UINT nx_nat_enable(NX_NAT_DEVICE *nat_ptr);
This service enables the IP instance for NAT (e.g. forward received packets to the NAT server).
Application code
/* Enable the NAT server. */
status = nx_nat_enable (nat_ptr);
/* If status = NX_SUCCESS, the IP instance was successfully enabled for NAT. */
Disable the IP instance for NAT
UINT nx_nat_disable(NX_NAT_DEVICE *nat_ptr);
This service disables NAT on the IP instance.
Application code
/* Disable the NAT server. */
status = nx_nat_disable (nat_ptr);
/* If status = NX_SUCCESS the NAT operation successfully disable. */
Set a cache full notify callback function
UINT nx_nat_cache_notify_set(
NX_NAT_DEVICE *nat_ptr,
VOID (*cache_full_notify_cb)(NX_NAT_DEVICE *nat_ptr)));
This service registers the cache full callback with the input function pointer cache_full_notify_cb which points to a user defined cache full notify function.
Application code
/* Set the cache full notify callback function to the NAT instance. */
status = nx_nat_cache_notify_set(nat_ptr, cache_full_notify_cb);
/* If status = NX_SUCCESS the callback function was successfully set. */
Create an inbound entry in the NAT translation table
UINT nx_nat_inbound_entry_create(
NX_NAT_DEVICE *nat_ptr,
NX_NAT_TRANSLATION_ENTRY *entry_ptr
ULONG local_ip_address,
USHORT external_port,
USHORT local_port,
UCHAR protocol);
This service creates an inbound entry as static (permanent entry, never expires) and adds it to the NAT translation table. These entries are usually created for local host servers where a connection is initiated from a host on the outside network. The NAT server checks that the external port is not already in use in the translation table or bound by a previously existing NetX Duo socket of the same protocol.
Application code
/* Create an entry for an inbound TCP packet. */
status = nx_nat_inbound_entry_create(nat_ptr, entry_ptr,
IP_ADDRESS(192,168,2,2), 5001, 5001,
NX_PROTOCOL_TCP);
/* If status = NX_SUCCESS the entry was successfully created. */
Delete an inbound entry in the NAT translation table
UINT nx_nat_inbound_entry_delete(
NX_NAT_DEVICE *nat_ptr,
NX_NAT_TRANSLATION_ENTRY *delete_entry_ptr)
This service deletes the specified inbound entry from the translation table.
Application code
/* Delete the specified static entry from the translation table. */
status = nx_nat_inbound_entry_delete(nat_ptr, delete_entry_ptr);
/* If status = NX_SUCCESS the entry was successfully deleted. */