#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#ifdef __linux__
#include <unistd.h>
#else
#include <windows.h>
#endif
{
{
}
}
void ReceivePacket (const char *device_key,
int packet_length,
unsigned char *packet_buffer_ptr,
const char *received_from_ip_address,
unsigned short recieved_from_port)
{
printf("Data\t%s\n", (char *)packet_buffer_ptr + 5);
}
int AcceptConnection (const char *listener_device_key,
const char *server_device_key,
const char *connected_ip_address,
unsigned short connected_port)
{
printf("Info\tConnection request from IP address: %s and port: %d\n",
connected_ip_address,connected_port);
}
void DropConnection (const char *disconnected_client_device_key,
const char *disconnected_remote_ip_address,
unsigned short disconnected_remote_port)
{
printf("Info\tConnection dropped from IP address: %s and port: %d\n",
disconnected_remote_ip_address,disconnected_remote_port);
return;
}
void CreateDataPackets(unsigned char *packet1_ptr,
unsigned char *packet2_ptr,
unsigned char *packet3_ptr,
unsigned char *packet4_ptr,
unsigned short *length1_ptr,
unsigned short *length2_ptr,
unsigned short *length3_ptr,
unsigned short *length4_ptr)
{
unsigned short tester= 1;
unsigned char tester_byte[1];
unsigned char sync_pattern[3];
unsigned short big_endian_order = 1;
memcpy(tester_byte,&tester,1);
if (tester_byte[0] == 0x01)
{
big_endian_order = 0;
}
memset(packet1_ptr,0x00,50);
memset(packet2_ptr,0x00,50);
memset(packet3_ptr,0x00,50);
memset(packet4_ptr,0x00,50);
strcpy((char *)packet1_ptr+5,"Mary had a little lamb");
strcpy((char *)packet2_ptr+5,"Its feet were black as soot");
strcpy((char *)packet3_ptr+5,"And into Mary's bread and jam ");
strcpy((char *)packet4_ptr+5,"Its sooty foot it put");
*length1_ptr = strlen((char *)packet1_ptr+5) + 6;
*length2_ptr = strlen((char *)packet2_ptr+5) + 6;
*length3_ptr = strlen((char *)packet3_ptr+5) + 6;
*length4_ptr = strlen((char *)packet4_ptr+5) + 6;
if (big_endian_order == 1)
{
memmove(packet1_ptr+3,length1_ptr,2);
memmove(packet2_ptr+3,length2_ptr,2);
memmove(packet3_ptr+3,length3_ptr,2);
memmove(packet4_ptr+3,length4_ptr,2);
}
else
{
memmove(packet1_ptr+4,length1_ptr,1);
memmove(packet2_ptr+4,length2_ptr,1);
memmove(packet3_ptr+4,length3_ptr,1);
memmove(packet4_ptr+4,length4_ptr,1);
}
sync_pattern[0] = 0xfa;
sync_pattern[1] = 0xfb;
sync_pattern[2] = 0xfc;
memcpy(packet1_ptr,sync_pattern,3);
memcpy(packet2_ptr,sync_pattern,3);
memcpy(packet3_ptr,sync_pattern,3);
memcpy(packet4_ptr,sync_pattern,3);
return;
}
void PrintAvailableIPAddesses()
{
unsigned int number_of_ip_address_structs;
unsigned int i;
&ip_address_struct_array_ptr);
printf("\nIP Addresses:\n\n");
for (i=0; i<number_of_ip_address_structs; i++)
{
ip_address_struct = ip_address_struct_array_ptr[i];
if (ip_address_struct_array_ptr[i].ip_address_version ==
IPV4)
{
printf("IPv4 address: %s\n",
ip_address_struct_array_ptr[i].ip_address);
}
else
{
switch (ip_address_struct_array_ptr[i].ip_address_v6_category)
{
printf("IPv6 address: %s\tIPv6 category: GLOBAL_FIXED\n",
ip_address_struct_array_ptr[i].ip_address);
break;
printf("IPv6 address: %s\tIPv6 category: GLOBAL_TEMPORARY\n",
ip_address_struct_array_ptr[i].ip_address);
break;
printf("IPv6 address: %s\tIPv6 category: LINK_LOCAL\n",
ip_address_struct_array_ptr[i].ip_address);
break;
printf("IPv6 address: %s\tIPv6 category: TAREDO_TUNNELING\n",
ip_address_struct_array_ptr[i].ip_address);
break;
printf("IPv6 address: %s\tIPv6 category: IPV6_TO_IPV4_TUNNELING\n",
ip_address_struct_array_ptr[i].ip_address);
break;
printf("IPv6 address: %s\tIPv6 category: MULTICAST\n",
ip_address_struct_array_ptr[i].ip_address);
break;
printf("IPv6 address: %s\tIPv6 category: OTHER\n",
ip_address_struct_array_ptr[i].ip_address);
break;
default:
printf("IPv6 address: %s\tIPv6 category: UNDEFINED_IP_ADDRESS_V6_CATEGORY\n",
ip_address_struct_array_ptr[i].ip_address);
break;
}
}
}
}
int main(int argc, char *argv[])
{
char ip_address[50];
unsigned short source_port;
unsigned short receive_port;
unsigned int receive_queue_size;
unsigned int receive_buffer_size;
char source_device_key[50];
char source_device_name[50];
char receive_device_key[50];
char receive_device_name[50];
unsigned char packet1[50];
unsigned char packet2[50];
unsigned char packet3[50];
unsigned char packet4[50];
unsigned char packets1_thru_4[200];
unsigned short length1;
unsigned short length2;
unsigned short length3;
unsigned short length4;
unsigned int key_buffer_size;
unsigned int byte_offset;
unsigned int bit_offset;
unsigned int length_in_bits;
long size_offset_value;
char log_path[256];
char log_filename[256];
char sync_hex_pattern[10];
char php_name[10];
unsigned long keepalive_time;
unsigned long keepalive_interval;
unsigned long keepalive_probes;
unsigned int connection_timeout_msec = 2100;
PrintAvailableIPAddesses();
CreateDataPackets(packet1,
packet2,
packet3,
packet4,
&length1,
&length2,
&length3,
&length4);
printf("\nNetwork TCP\n\n");
strcpy(log_path,"");
strcpy(log_filename,"network_tcp_log_file");
log_filename,
strcpy(log_path,"");
strcpy(log_filename,"network_tcp_statistics_file");
log_filename,
strcpy(ip_address,"127.0.0.1");
source_port = 20170;
receive_queue_size = 0;
receive_buffer_size = 0;
key_buffer_size = sizeof(source_device_key);
source_port,
receive_queue_size,
receive_buffer_size,
&key_buffer_size,
{
return 0;
}
strcpy(source_device_name,"TCP_client");
{
return 0;
}
keepalive_time= 3600;
keepalive_interval = 300;
keepalive_probes = 10;
keepalive_time,
keepalive_interval,
{
return 0;
}
receive_port = 20180;
receive_queue_size = 100;
receive_buffer_size = 100;
key_buffer_size = sizeof(receive_device_key);
receive_port,
receive_queue_size,
receive_buffer_size,
&key_buffer_size,
{
return 0;
}
strcpy(receive_device_name,"TCP_listener");
{
return 0;
}
keepalive_time,
keepalive_interval,
{
return 0;
}
byte_offset = 3;
bit_offset = 0;
length_in_bits = 16;
size_offset_value = 0;
strcpy(sync_hex_pattern,"fafbfc");
strcpy(php_name,"EXAMPLE");
sync_hex_pattern,
start_of_packet_sync_flag) !=
SUCCESS)
{
return 0;
}
byte_offset,
bit_offset,
length_in_bits,
size_offset_value,
{
return 0;
}
{
return 0;
}
{
return 0;
}
{
return 0;
}
{
return 0;
}
ip_address,
receive_port,
connection_timeout_msec) !=
SUCCESS)
{
return 0;
}
#ifdef __linux__
sleep(1);
#else
Sleep(1000);
#endif
memcpy(packets1_thru_4,packet1,length1);
memcpy(packets1_thru_4+length1,packet2,length2);
memcpy(packets1_thru_4+length1+length2,packet3,length3);
memcpy(packets1_thru_4+length1+length2+length3,packet4,length4);
length1+
length2+
length3/2,
{
return 0;
}
#ifdef __linux__
sleep(1);
#else
Sleep(1000);
#endif
length3/2+length4,
packets1_thru_4+
length1+
length2+
{
return 0;
}
#ifdef __linux__
sleep(1);
#else
Sleep(1000);
#endif
#ifdef __linux__
sleep(1);
#else
Sleep(1000);
#endif
return 0;
}
Message codes and structure definition for the Device Service library.
endian_byte_order
Byte order enumeration.
Definition: ds_shared.h:97
@ BIG_ENDIAN_ORDER
Also known as network byte order. Most significant byte is first.
Definition: ds_shared.h:98
@ GLOBAL_FIXED
Global fixed.
Definition: ds_shared.h:130
@ MULTICAST
Multicast.
Definition: ds_shared.h:135
@ TAREDO_TUNNELING
Taredo tunneling.
Definition: ds_shared.h:133
@ IPV6_TO_IPV4_TUNNELING
IPv6 to IPv4 tunneling.
Definition: ds_shared.h:134
@ LINK_LOCAL
Link local.
Definition: ds_shared.h:132
@ OTHER
Other.
Definition: ds_shared.h:136
@ GLOBAL_TEMPORARY
GLobal temporary.
Definition: ds_shared.h:131
boolean_type
Boolean enumeration.
Definition: ds_shared.h:104
@ FALSE_OR_NO
False.
Definition: ds_shared.h:105
@ TRUE_OR_YES
True.
Definition: ds_shared.h:106
@ IPV4
IP version 4 address.
Definition: ds_shared.h:112
Structure of parameters needed for IP address identification.
Definition: ds_shared.h:180
Structure of parameters needed for message support.
Definition: trek_toolkit_common_api_ansi_c.h:74
char message[MAX_MESSAGE_SIZE]
Message.
Definition: trek_toolkit_common_api_ansi_c.h:77
enum message_category category
Message category (e.g., MSG_CAT_ERROR, MSG_CAT_ERROR_ALERT, MSG_CAT_WARNING, MSG_CAT_WARNING_ALERT,...
Definition: trek_toolkit_common_api_ansi_c.h:76
#define SUCCESS
The function completed successfully.
Definition: trek_error.h:8