NetSim Source Code Help
Loading...
Searching...
No Matches
NetSim_utility.h
Go to the documentation of this file.
1/************************************************************************************
2* Copyright (C) 2022 *
3* TETCOS, Bangalore. India *
4* *
5* Tetcos owns the intellectual property rights in the Product and its content. *
6* The copying, redistribution, reselling or publication of any or all of the *
7* Product or its content without express prior written consent of Tetcos is *
8* prohibited. Ownership and / or any other right relating to the software and all *
9* intellectual property rights therein shall remain at all times with Tetcos. *
10* *
11* This source code is licensed per the NetSim license agreement. *
12* *
13* No portion of this source code may be used as the basis for a derivative work, *
14* or used, for any purpose other than its intended use per the NetSim license *
15* agreement. *
16* *
17* This source code and the algorithms contained within it are confidential trade *
18* secrets of TETCOS and may not be used as the basis for any other software, *
19* hardware, product or service. *
20* *
21* Author: Shashi Kant Suman *
22* *
23* ----------------------------------------------------------------------------------*/
24
25
26
27#ifndef _NETSIM_UTILITY_H_
28#define _NETSIM_UTILITY_H_
29#ifndef _CRT_SECURE_NO_DEPRECATE
30#define _CRT_SECURE_NO_DEPRECATE
31#endif
32#ifndef _CRT_SECURE_NO_WARNINGS
33#define _CRT_SECURE_NO_WARNINGS
34#endif
35
36#include <stdio.h>
37#include <stdlib.h>
38#include <string.h>
39#include <stdbool.h>
40#ifdef _WIN32
41#include <Windows.h>
42#else
43#include "stdarg.h"
44#include "Linux.h"
45#endif
46#include <time.h>
47#include <stdint.h>
48
49
50#ifdef __cplusplus
51extern "C" {
52#endif
53
54#ifdef _WIN32
55#ifndef _NETSIM_UTILITY_CODE_
56#pragma comment(lib,"NetSim_utility.lib")
57#define NETSIM_UTILITY_EXPORT _declspec(dllimport)
58#else
59#define NETSIM_UTILITY_EXPORT _declspec(dllexport)
60#endif
61#else
62#ifndef _NETSIM_UTILITY_CODE_
63#define NETSIM_UTILITY_EXPORT extern
64#else
65#define NETSIM_UTILITY_EXPORT
66#endif
67#endif
68
69 typedef struct stru_pcap_writer
70 {
71 FILE* pFile;
72 time_t start_time;
75
76 typedef struct stru_wireshark_trace
77 {
79 void (*convert_sim_to_real_packet)(void* netsim_packet,void* pcap_handle,double dTime);
81
83
84 //Function prototype
85
86 //Used to get path for any file
87 _declspec(dllexport) void fnGetFilePath(char* name, char* path);
88
89 //Used to get options index form command
90 _declspec(dllexport) int fnParseOption(int count,char* arg[],char* opt);
91
92 //Used to get current time in string
93 _declspec(dllexport) void GetTimeStr(char* date, int len);
94
95 //Used to print the log file with thread id and time
96 _declspec(dllexport) FILE* open_log_file(char* filename,char* mode);
97 _declspec(dllexport) int close_log_file(FILE* fp);
98 _declspec(dllexport) int ReportLog(FILE* fp, const char* msg,...);
99
100 /* Strip whitespace chars off end of given string, in place. Return s. */
101 _declspec(dllexport) char* rstrip(char* s);
102
103 /* Return pointer to first non-whitespace char in given string. */
104 _declspec(dllexport) char* lskip(const char* s);
105
106 /* Return pointer to first char c or ';' comment in given string, or pointer to
107 null at end of string if neither found. ';' must be prefixed by a whitespace
108 character to register as a comment. */
109 _declspec(dllexport) char* find_char_or_comment(const char* s, char c);
110
111 /* Version of strncpy that ensures dest (size bytes) is null-terminated. */
112 _declspec(dllexport) char* strncpy0(char* dest, const char* src, size_t size);
113
114 /* Strip the word out of string*/
115 _declspec(dllexport) char* find_word(char** s);
116
117 /* To check whether a string is start with specified string*/
118 _declspec(dllexport) bool startsWith(const char *str, const char *pre);
119
120 /* Used to init the start_time. Must be called once */
121 _declspec(dllexport) void init_time();
122
123 /* Used to get current time in microsecond */
124 _declspec(dllexport) uint64_t em_current_time();
125
126 /* Used to initialize the start time*/
127 _declspec(dllexport) void em_init_time(void);
128
129 /* Used to get start time */
130 _declspec(dllexport) struct tm get_start_time();
131
132 /* Sleep for microsec */
133 _declspec(dllexport) void usleep(__int64 usec);
134
135 /* used to get file name without extension */
136 _declspec(dllexport) char* get_filename_without_extension(char* filename);
137
138 /* Used to prepare filter string for wireshark */
139 _declspec(dllexport) void create_wireshark_filter(__out char* filter,__in int len,__in char* src_ip,__in char* dst_ip);
140
141 /* Call wireshark */
142 _declspec(dllexport) void call_wireshark(int duration,char* filter_string);
143
144 /* open pcap file for writing */
145 _declspec(dllexport) void* open_pcap_file(const char *filename,char* pipename,uint32_t network);
146
147 /* write packet to pcap file */
148 _declspec(dllexport) void write_to_pcap(void* handle,unsigned char* packet,unsigned int len,double* dTime);
149
150 /* close the pcap write */
151 _declspec(dllexport) void close_pcap_file(void* pcap_handle);
152
153 /*Bit wise Operation*/
154#define SET_BIT(val, bitIndex) ((val) |= (1 << (bitIndex)))
155#define SET_BIT_64(val, bitIndex) ((val) |= (1i64 << (bitIndex)))
156#define CLEAR_BIT(val, bitIndex) ((val) &= ~(1 << (bitIndex)))
157#define CLEAR_BIT_64(val, bitIndex) ((val) &= ~(1i64 << (bitIndex)))
158#define TOGGLE_BIT(val, bitIndex) ((val) ^= (1 << (bitIndex)))
159#define TOGGLE_BIT_64(val, bitIndex) ((val) ^= (1i64 << (bitIndex)))
160#define BIT_IS_SET(val, bitIndex) ((val) & (1 << (bitIndex)))
161#define BIT_IS_SET_64(val, bitIndex) ((val) & (1i64 << (bitIndex)))
162#define LSHIFTCHAR(x,eposition) ((UINT8)(x << (8 - eposition)))
163#define RSHIFTCHAR(x,eposition) ((UINT8)(x >> (8 - eposition)))
164
165#define htonll(x) ((1==htonl(1)) ? (x) : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
166 _declspec(dllexport) int isBitSet(unsigned int num, int index);
167 _declspec(dllexport) unsigned int setBit(unsigned int num, int index);
168 _declspec(dllexport) unsigned int unsetBit(unsigned int num, int index);
169 _declspec(dllexport) UINT64 hex_to_decimal(char hex[]);
170 _declspec(dllexport) char* hex_to_binary(char* hex, char* bin);
171 _declspec(dllexport) void binary_to_hex(char* bin, char* hex);
172 _declspec(dllexport) UINT64 binary_to_decimal(char bin[]);
173 _declspec(dllexport) UINT8 maskChar(UINT8 sposition, UINT8 eposition);
174
175 _declspec(dllexport) bool find_interaction(double arg1[2],
176 double arg2[2],
177 double intersection[2]);
178
179 //MatLab interface
180 _declspec(dllexport) void netsim_matlab_interface_configure(char* appPath);
182 _declspec(dllexport) void netsim_matlab_send_command(void* command,int len); //Don't use. Under development
183 _declspec(dllexport) void netsim_matlab_send_ascii_command(char* format, ...);
184 _declspec(dllexport) bool netsim_matlab_get_value(char* out, int outLen, char* name, char* type);
185
186#ifdef __cplusplus
187}
188#endif
189#endif //_NETSIM_UTILITY_H_
static ANIM_HANDLE handle
Definition: BatteryModel.c:197
#define c
#define UINT64
Definition: Linux.h:37
#define __in
Definition: Linux.h:113
#define _declspec(dllexport)
This function is used to trigger the update.
Definition: Linux.h:41
#define HANDLE
Definition: Linux.h:73
#define __out
Definition: Linux.h:114
#define UINT8
Definition: Linux.h:31
UINT64 binary_to_decimal(char bin[])
void netsim_matlab_send_command(void *command, int len)
void netsim_matlab_interface_close()
void netsim_matlab_send_ascii_command(char *format,...)
struct stru_pcap_writer * PPCAP_WRITER
char * strncpy0(char *dest, const char *src, size_t size)
char * hex_to_binary(char *hex, char *bin)
struct stru_pcap_writer PCAP_WRITER
void close_pcap_file(void *pcap_handle)
FILE * open_log_file(char *filename, char *mode)
struct stru_wireshark_trace WIRESHARKTRACE
void GetTimeStr(char *date, int len)
void init_time()
unsigned int unsetBit(unsigned int num, int index)
struct tm get_start_time()
int isBitSet(unsigned int num, int index)
#define NETSIM_UTILITY_EXPORT
void em_init_time(void)
void write_to_pcap(void *handle, unsigned char *packet, unsigned int len, double *dTime)
UINT8 maskChar(UINT8 sposition, UINT8 eposition)
int fnParseOption(int count, char *arg[], char *opt)
char * get_filename_without_extension(char *filename)
unsigned int setBit(unsigned int num, int index)
void * open_pcap_file(const char *filename, char *pipename, uint32_t network)
void create_wireshark_filter(__out char *filter, __in int len, __in char *src_ip, __in char *dst_ip)
char * find_char_or_comment(const char *s, char c)
char * rstrip(char *s)
bool netsim_matlab_get_value(char *out, int outLen, char *name, char *type)
void netsim_matlab_interface_configure(char *appPath)
bool startsWith(const char *str, const char *pre)
uint64_t em_current_time()
NETSIM_UTILITY_EXPORT WIRESHARKTRACE wireshark_trace
void fnGetFilePath(char *name, char *path)
void usleep(__int64 usec)
void binary_to_hex(char *bin, char *hex)
UINT64 hex_to_decimal(char hex[])
bool find_interaction(double arg1[2], double arg2[2], double intersection[2])
int ReportLog(FILE *fp, const char *msg,...)
char * find_word(char **s)
void call_wireshark(int duration, char *filter_string)
char * lskip(const char *s)
struct stru_wireshark_trace * PWIRESHARKTRACE
int close_log_file(FILE *fp)
PPCAP_WRITER ** pcapWriterlist
void(* convert_sim_to_real_packet)(void *netsim_packet, void *pcap_handle, double dTime)