#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);
}
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);
}
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 receive_device_key[50];
unsigned char packet1[50];
unsigned char packet2[50];
unsigned char packet3[50];
unsigned char packet4[50];
unsigned short length1;
unsigned short length2;
unsigned short length3;
unsigned short length4;
unsigned int key_buffer_size;
char log_path[256];
char log_filename[256];
PrintAvailableIPAddesses();
CreateDataPackets(packet1,
packet2,
packet3,
packet4,
&length1,
&length2,
&length3,
&length4);
printf("\nNetwork UDP\n\n");
strcpy(log_path,"");
strcpy(log_filename,"network_udp_log_file");
log_filename,
strcpy(ip_address,"127.0.0.1");
source_port = 20130;
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;
}
receive_port = 20140;
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;
}
{
return 0;
}
length1,packet1,
ip_address,
{
length2,
packet2,
ip_address,
{
length3,
packet3,
ip_address,
{
length4,
packet4,
ip_address,
receive_port);
}
}
}
#ifdef __linux__
sleep(1);
#else
Sleep(1000);
#endif
return 0;
}
Message codes and structure definition for the Device Service library.
@ 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
@ FALSE_OR_NO
False.
Definition: ds_shared.h:105
@ 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