Function description
This function is used to initialize TOA fetcher.
bool InitUpToaFetcher(char *ncard_ip_str, char *svr_ip_str, u_short svr_port[], u_short svr_port_num, u_short cache_secs=TIMER_CACHE_SECS)
Input parameters description
svr_port
or port_range_ptr
must be configured.svr_port
or port_range_ptr
must be configured.toa_fetcher.h: TIMER_CACHE_SECS
. The TOA will no longer be saved after the cache expires.Returned value
Function description
This function is used to get the TOA value. After the tcp-syn packet interacts, TOA can be obtained after 1 ms. Normally, a three-way handshake takes more than 1 ms.
bool FetchToaValue(u_long fake_client_ip_addr, u_short fake_client_port, u_long &real_client_ip_addr, u_short &real_client_port)
Input parameters description
accept
function of the server.accept
function of the server.Returned value
Function description
This function is used to stop TOA fetcher.
void StopToaFetcher()
Input parameters description
-
3. Returned value
-
Function description
This function is used to obtain the Fetcher status.
int GetFetcherStatus()
Input parameters description
-
3. Returned value
0: initial status. An instance will be in this status after it is created. During fetcher initialization, this status will remain unchanged. If an error occurs, -1 will be returned. If the execution succeeds, 1 will be returned.
-1: an exception occurs.
1: normal operation.
Function description
This function is used to obtain the TOA additional thread handler.
HANDLE FetchThreadHandler()
Input parameters description
-
3. Returned value
The TOA additional thread handler. When ToaFetcher instance is terminated, this handler will be closed.
Function description
This function is used to obtain the error code.
bool FetchErrorInfo(int* err_code_ptr, char* err_msg_ptr)
Input parameters description
Returned value
Error Code | Error Message | Description |
---|---|---|
0 | Ok | Normal |
-1001 | Exceed max server port number | The maximum number of ports is exceeded. Please check InitUpToaFetcher: svr_port_num . |
-1002 | Invalid IP address | Invalid IPv4 address |
-1003 | No suitable network interface | No suitable network interface found |
-1004 | System Error: find dev error | System error: no dev can be found. Please contact the lib developer. |
-1005 | System Error: start timer error | System error: an error occurs when starting the timer. Please contact the lib developer. |
-1006 | System Error: compile filter error | System error: an error occurs when compiling the filter rule. Please contact the lib developer. |
-1007 | System Error: set filter error | System error: an error occurs when configuring the filter rule. Please contact the lib developer. |
-1008 | System Error: open pcap error | System error: an error occurs when opening dev . Please contact the lib developer. |
-1009 | System Error: start pcap error | System error: an error occurs when starting the listener. Please contact the lib developer. |
-1010 | System Error: begin thread error | System error: an error occurs when starting the thread. Please contact the lib developer. |
-1999 | Unknown error | Unknown error. Please contact the lib developer. |
Initialize ToaFetcher:
char ncard_ip_str[] = "1.1.1.1";
char svr_ip_str[] = "1.1.1.1";
char port_range[3][100] = {"10001-10005", "20001-20005", "30001-30005"};
char* port_range_ptr[3] = {port_range[0], port_range[1], port_range[2]};
u_short svr_port_list[3] = {1111, 2222, 3333};
ToaFetcher inst = ToaFetcher();
inst.InitUpToaFetcher((char*)ncard_ip_str, (char*)svr_ip_str, svr_port_list, 3);
Obtain TOA:
void GetToa(SOCKADDR_IN client_addr, ToaFetcher * toa_fetcher_ptr)
{
u_long fake_client_ip_addr = 0;
u_short fake_client_port = 0;
u_long real_client_ip_addr = 0;
u_short real_client_port = 0;
memcpy(&fake_client_ip_addr, &client_addr.sin_addr, 4);
memcpy(&fake_client_port, &client_addr.sin_port, 2);
bool ret = toa_fetcher_ptr->FetchToaValue(fake_client_ip_addr, fake_client_port, real_client_ip_addr, real_client_port);
if(ret == FALSE){
printf("No toa found\n");
}else{
//fpp: Custom print function
fpp("real_client_ip_addr", &real_client_ip_addr, 4);
fpp("real_client_port", &real_client_port, 2);
}
}
TOA obtaining program obtains the real IP address from toa_win.exe through UDP communication.
| ID(4Bytes)| FakeIPAddress(4Bytes)| FakePort(2Bytes)|
The fields are described as follows:
ID: The unique ID of the request and will be returned as it is in the response. It contains 4 bytes of data.
FakeIPAddrss: The fake IP address of the client stored in the network byte order and can be obtained from the opposite address returned by the accept
function of the server. It contains 4 bytes of data.
FakePort: The fake port number of the client stored in the network byte order and can be obtained from the opposite address returned by the accept
function of the server. It contains 2 bytes of data.
Response: | ID(4Bytes)| Code(1Byte)| RealIPAddress(4Bytes)| RealPort(2Bytes)|
The fields are described as follows:
Code
is 0, it indicates the real client IP address. It contains 4 bytes of data in network byte order.Code
is 0, it indicates the real client port. It contains 2 bytes of data in network byte order.For more information, see demo.go. You can develop a TOA obtaining client on your own, or use the queryToa
function in demo.go to obtain TOA.
Function description
func queryToa(serverAddr string, fakeIp string, fakePort uint16)(int32, string, uint16)
Input parameters description
fakeIP
or fakePort
is incorrect or the cache has expired.
Was this page helpful?