Teonet library
0.4.7
|
#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include "ev_mgr.h"
#include "modules/tcp_proxy.h"
Macros | |
#define | ke_emul() |
Emulate ksnetEvMgrClass. More... | |
Functions | |
size_t | ksnTCPProxyPackageCreate (void *buffer, size_t buffer_len, const char *addr, int port, int cmd, const void *data, size_t data_len) |
Create TCP Proxy package. More... | |
uint8_t | get_byte_checksum (const uint8_t *data, size_t data_len) |
int | ksnTCPProxyPackageProcess (ksnTCPProxyPacketData *packet, void *data, size_t data_length) |
Process TCP proxy package. More... | |
void | test_5_1 () |
Initialize/Destroy TCP Proxy module. More... | |
void | test_5_2 () |
Create and Process TCP Proxy Package functions. More... | |
int | add_suite_5_tests (void) |
Add TCP Proxy suite tests. More... | |
Variables | |
CU_pSuite | pSuite |
Teonet TCP Proxy module tests suite
Tests TCP Proxy functions:
cUnit test suite code:
Created on Sep 8, 2015, 11:10:22 AM
#define ke_emul | ( | ) |
Emulate ksnetEvMgrClass.
Referenced by test_5_1(), and test_5_2().
int add_suite_5_tests | ( | void | ) |
Add TCP Proxy suite tests.
References pSuite, test_5_1(), and test_5_2().
Referenced by main().
uint8_t get_byte_checksum | ( | const uint8_t * | data, |
size_t | data_len | ||
) |
Referenced by ksnTCPProxyPackageCreate(), ksnTCPProxyPackageProcess(), teoLNullPacketCheckMiscrypted(), and test_5_2().
size_t ksnTCPProxyPackageCreate | ( | void * | buffer, |
size_t | buffer_length, | ||
const char * | addr, | ||
int | port, | ||
int | cmd, | ||
const void * | data, | ||
size_t | data_length | ||
) |
Create TCP Proxy package.
Create TCP Proxy package from peers UDP address and port, data buffer and its length
buffer | The buffer to create package in |
buffer_length | Package data length |
addr | String with peer UDP address |
port | UDP port number |
cmd | TCP Proxy protocol command |
data | Package data |
data_length | Package data length |
> | 0 - size of created package |
-1 | - error: The output buffer less than packet header |
-2 | - error: The output buffer less than packet header + data |
References ksnTCPProxyHeader::addr_length, ksnTCPProxyHeader::checksum, ksnTCPProxyHeader::command, get_byte_checksum(), ksnTCPProxyHeader::packet_checksum, ksnTCPProxyHeader::packet_length, ksnTCPProxyHeader::port, TCP_PROXY_VERSION, and ksnTCPProxyHeader::version.
Referenced by cmd_udpp_read_cb(), ksnTCPProxySendTo(), and test_5_2().
int ksnTCPProxyPackageProcess | ( | ksnTCPProxyPacketData * | packet, |
void * | data, | ||
size_t | data_length | ||
) |
Process TCP proxy package.
Read tcp data from input buffer to tp->buffer until end of tcp proxy package, check checksum, take UDP address, port number and UDP package data.
packet | Pointer to ksnTCPProxyPacketData |
data | Pointer to received TCP data |
data_length | TCP data length |
>0 | - receiving done, the return value contain length of packet, the packet saved to ksnTCPProxyClass::buffer |
0 | - continue reading current packet |
-1 | - wrong process package stage |
-2 | - wrong packet header checksum |
-3 | - wrong packet checksum |
References ksnTCPProxyHeader::addr_length, ksnTCPProxyPacketData::buffer, ksnTCPProxyHeader::checksum, get_byte_checksum(), ksnTCPProxyPacketData::header, ksnTCPProxyPackageProcess(), ksnTCPProxyPacketData::length, ksnTCPProxyHeader::packet_checksum, ksnTCPProxyHeader::packet_length, ksnTCPProxyHeader::port, PROCESS_PACKET, ksnTCPProxyPacketData::ptr, ksnTCPProxyPacketData::stage, WAIT_FOR_END, and WAIT_FOR_START.
Referenced by _cmd_tcpp_read_cb(), ksnTCPProxyPackageProcess(), and test_5_2().
void test_5_1 | ( | ) |
Initialize/Destroy TCP Proxy module.
References ke, ke_emul, ksnTCPProxyDestroy(), and ksnTCPProxyInit().
Referenced by add_suite_5_tests().
void test_5_2 | ( | ) |
Create and Process TCP Proxy Package functions.
References ksnTCPProxyHeader::addr_length, ksnTCPProxyPacketData::buffer, ksnTCPProxyHeader::checksum, CMD_TCPP_PROXY, data, get_byte_checksum(), ksnTCPProxyPacketData::header, ke, ke_emul, KSN_BUFFER_DB_SIZE, ksnTCPProxyDestroy(), ksnTCPProxyInit(), ksnTCPProxyPackageCreate(), ksnTCPProxyPackageProcess(), ksnTCPProxyPacketData::length, ksnTCPProxyData::packet, ksnTCPProxyHeader::packet_length, ksnTCPProxyHeader::port, ksnTCPProxyPacketData::ptr, ksnTCPProxyPacketData::stage, and WAIT_FOR_START.
Referenced by add_suite_5_tests().
CU_pSuite pSuite |
Referenced by add_suite_5_tests().