📄 nat_api.c
字号:
/******************************************************************************* * natTcpXlatShow - display all TCP translation lists* * This routine displays the TCP translation lists.** RETURNS* * OK (success) always.**/STATUS natTcpXlatShow(){ char local_addr[INET_ADDR_LEN]; char global_addr[INET_ADDR_LEN]; int entry_num; struct in_addr iaddr; IP_TRANSLATION_ENTRY* ip_entry; TCP_TRANSLATION_ENTRY* tcp_entry; if(nat.single_global_address_enabled == TRUE) /* NAPT */ { /* Dynamic List (may contain both static and dynamic entries) */ tcp_entry = (TCP_TRANSLATION_ENTRY *)DLL_FIRST( (DL_LIST *) &nat.nats.tcp_translation_list); natTcpXlatListShow(tcp_entry, TRUE); /* show port-based translations */ /* Static List (static entries only) */ for(entry_num=0;entry_num<MAXIMUM_NUMBER_OF_TCP_STATIC_ENTRIES;entry_num++) { if (entry_num==0) { printf("\n"); printf("Static TCP Server Translation Entries\n"); printf("-------------------------------------\n"); } if (nat.tcp_static_entries[entry_num].local_address == 0) /* End of list */ { /* don't print anything */ } else { iaddr.s_addr = htonl (nat.tcp_static_entries[entry_num].local_address); inet_ntoa_b(iaddr, local_addr); printf("Global IP Port: %-5d Local IP Port: %-5d Address: %s\n" ,nat.tcp_static_entries[entry_num].global_port_number ,nat.tcp_static_entries[entry_num].local_port_number ,local_addr); } } } /* Basic NAT */ entry_num = 0; ip_entry = (IP_TRANSLATION_ENTRY *) DLL_FIRST( (DL_LIST *) &nat.natg.ip_translation_list); while (ip_entry != NULL) { printf("\n"); printf("NAT IP Translation Entries\n"); printf("--------------------------\n"); printf("# %-*s " "%-*s Static TimeStamp\n" ,15,"Private Address" ,15,"Global Address"); entry_num++; iaddr.s_addr = htonl (ip_entry->sa_local_address); inet_ntoa_b(iaddr, local_addr); iaddr.s_addr = htonl (ip_entry->sa_global_address); inet_ntoa_b(iaddr, global_addr); if (ip_entry->static_entry == TRUE) { ip_entry->time_stamp = 0; /* time stamp not applicable */ } printf("%-3d %-*s %-*s " "%-6s %9lu\n", entry_num, 15,local_addr, 15,global_addr, ip_entry->static_entry ? "Yes" : "No", ip_entry->time_stamp ); tcp_entry = (TCP_TRANSLATION_ENTRY *)DLL_FIRST( (DL_LIST *) &ip_entry->tcp_translation_list); natTcpXlatListShow(tcp_entry, FALSE); /* show address-based translations */ ip_entry = (IP_TRANSLATION_ENTRY *) DLL_NEXT( (DL_NODE *) ip_entry); } return(OK);}/******************************************************************************* * natUdpXlatShow - display all UDP translation lists* * This routine displays the UDP translation lists.** RETURNS* * OK (success), or ERROR (failure). **/STATUS natUdpXlatShow(){ char local_addr[INET_ADDR_LEN]; char remote_addr[INET_ADDR_LEN]; int entry_num; UDP_TRANSLATION_ENTRY* udp_entry; struct in_addr iaddr; if(nat.single_global_address_enabled == TRUE) /* NAPT */ { entry_num = 0; udp_entry = (UDP_TRANSLATION_ENTRY *) DLL_FIRST( (DL_LIST *) &nat.nats.udp_translation_list); /* Dynamic List (may contain static or dynamic entries) */ while (udp_entry != NULL) { if(entry_num==0) { printf("\n"); printf("NAT UDP Client Translation List\n"); printf("-------------------------------\n"); printf("# %-*s Port Spoof " " %-*s Port Timer Static\n" ,15,"Local Address" ,15,"Remote Address"); } entry_num++; iaddr.s_addr = htonl (udp_entry->local_address); inet_ntoa_b(iaddr, local_addr); iaddr.s_addr = htonl (udp_entry->remote_address); inet_ntoa_b(iaddr, remote_addr); printf("%-3d %-*s %5d %5d " " %-*s %5d %5lu %s\n", entry_num, 15,local_addr, udp_entry->local_port, udp_entry->spoofed_local_port, 15,remote_addr, udp_entry->remote_port, udp_entry->udp_translation_entry_timer, udp_entry->static_entry ? "Yes" : "No" ); udp_entry = (UDP_TRANSLATION_ENTRY *) DLL_NEXT( (DL_NODE *) udp_entry); } /* Static List (static entries only) */ for(entry_num=0;entry_num<MAXIMUM_NUMBER_OF_UDP_STATIC_ENTRIES;entry_num++) { if (entry_num==0) { printf("\n"); printf("Static UDP Server Translation Entries\n"); printf("-------------------------------------\n"); } if (nat.udp_static_entries[entry_num].local_address == 0) { /* don't print anything */ } else { iaddr.s_addr = htonl(nat.udp_static_entries[entry_num].local_address); inet_ntoa_b(iaddr, local_addr); printf("Global IP Port: %-5d Server IP Port: %-5d Address: %s\n" ,nat.udp_static_entries[entry_num].global_port_number ,nat.udp_static_entries[entry_num].local_port_number ,local_addr); } } return (OK); } /* Basic NAT */ return(ERROR); /* Use natXlatShow instead */}/******************************************************************************* * natIcmpXlatShow - display all ICMP translation lists* * This routine displays the Internet Control Message Protocol (ICMP)* translation lists.** 'Note:' This routine is accessible in NAPT mode only.** RETURNS* * OK (success), or ERROR (failure). **/STATUS natIcmpXlatShow(){ char local_addr[INET_ADDR_LEN]; int entry_num; ICMP_TRANSLATION_ENTRY* icmp_entry; struct in_addr iaddr; if(nat.single_global_address_enabled == TRUE) /* NAPT */ { entry_num = 0; icmp_entry = (ICMP_TRANSLATION_ENTRY *) DLL_FIRST( (DL_LIST *) &nat.nats.icmp_translation_list); while (icmp_entry != NULL) { if(entry_num==0) { printf("\n"); printf("NAT ICMP Client Translation List\n"); printf("--------------------------------\n"); printf("# %-*s ID Spoof Timer\n" ,15,"Local Address"); } entry_num++; iaddr.s_addr = htonl(icmp_entry->local_address); inet_ntoa_b(iaddr, local_addr); printf("%-3d %-*s %5d %5d %5lu\n" , entry_num, 15,local_addr, icmp_entry->icmp_identifier, icmp_entry->spoofed_icmp_identifier, icmp_entry->icmp_translation_entry_timer ); icmp_entry = (ICMP_TRANSLATION_ENTRY *) DLL_NEXT( (DL_NODE *) icmp_entry); } return (OK); } /* Basic NAT */ return(ERROR); /* Use natXlatShow instead */}#ifdef NAT_PASS_THRU_ENABLE/************************************************************************Description: Add an address/mask pair to the pass through list. Outbound packets destined to this address/mask will not be translated by NAT.************************************************************************/STATUS natPassThruListAdd(char *address, char *mask){ IP_ADDRESS addr, msk; NAT_PASSTHRU_PAIR *p_pair; addr = ntohl(inet_addr(address)); msk = ntohl(inet_addr(mask)); p_pair = (NAT_PASSTHRU_PAIR *) lstFirst(&nat.passthru_list); while (p_pair != NULL) { if ((p_pair->address & p_pair->mask) == (addr & msk)) { printf("Entry already exists in pass through list.\n"); return (ERROR); } p_pair = (NAT_PASSTHRU_PAIR *)lstNext((NODE*)p_pair); } /* new entry, add to container */ p_pair = (NAT_PASSTHRU_PAIR *) malloc (sizeof (NAT_PASSTHRU_PAIR)); if (p_pair == NULL) { printf("Can't allocate memory!\n"); return(ERROR); } p_pair->address = addr; p_pair->mask = msk; lstAdd (&nat.passthru_list, (NODE *) p_pair); return(OK);}/************************************************************************Description: Delete an address/mask pair to the pass through list.************************************************************************/STATUS natPassThruListDelete(char *address, char *mask){ IP_ADDRESS addr, msk; NAT_PASSTHRU_PAIR *p_pair; addr = ntohl(inet_addr(address)); msk = ntohl(inet_addr(mask)); p_pair = (NAT_PASSTHRU_PAIR *) lstFirst(&nat.passthru_list); while (p_pair != NULL) { if ((p_pair->address & p_pair->mask) == (addr & msk)) { lstDelete (&nat.passthru_list, (NODE*) p_pair); free (p_pair); return (OK); } p_pair = (NAT_PASSTHRU_PAIR *) lstNext((NODE*) p_pair); } printf("Can't find match in the pass through list.\n"); return(ERROR);}/************************************************************************Description: Show the list of address/mask pairs in the pass through list. Outbound packets sent to these addresses will not be translated by NAT.************************************************************************/STATUS natPassThruListShow(){ NAT_PASSTHRU_PAIR *p_pair; struct in_addr iaddr; char address[INET_ADDR_LEN]; char mask[INET_ADDR_LEN]; printf("NAT Pass Through List\n"); printf("=====================\n"); printf("Address\t\t\tMask\n"); p_pair = (NAT_PASSTHRU_PAIR *) lstFirst(&nat.passthru_list); while (p_pair != NULL) { if (p_pair->address != 0) { iaddr.s_addr = htonl(p_pair->address); inet_ntoa_b (iaddr, address); iaddr.s_addr = htonl(p_pair->mask); inet_ntoa_b (iaddr, mask); printf ("%s\t\t%s\n", address, mask); } p_pair = (NAT_PASSTHRU_PAIR *) lstNext((NODE*) p_pair); } return (OK);}#endif/*************************************************************************Description: Get the translated global address of the given local address.*************************************************************************//******************************************************************************* * natGetGlobalAddr - display global (external) address of specified local host* * Use this routine to display the external address that binds to the specified * host in the private (or local) network realm. Although it can be called in * NAPT mode, this information is more useful in Basic NAT. ** RETURNS* * OK (success), or ERROR (failure). **/STATUS natGetGlobalAddr ( char *localAddr /* Local address of host whose global address is sought. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -