NetSim Source Code Help
Loading...
Searching...
No Matches
IP_Addressing.h
Go to the documentation of this file.
1/************************************************************************************
2 * Copyright (C) 2020 *
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 * Author: ,~~. *
12 ( 6 )-_,
13 (\___ )=='-'
14 \ . ) )
15 \ `-' /
16 ~'`~'`~'`~'`~ Shashi kant suman
17 * *
18 * ---------------------------------------------------------------------------------*/
19#ifndef _NETSIM_IPADDRESSING_H_
20#define _NETSIM_IPADDRESSING_H_
21#ifdef __cplusplus
22extern "C" {
23#endif
24#ifdef _WIN32
25#else
26 #include "Linux.h"
27// #define _declspec(dllexport) extern
28#endif
29#define _NETSIM_IP_LEN 50
30#define _NETSIM_BIN_IP_LEN 130 //128+1(\0)+1(precaution) for IPv6
31#define MAX_TTL 255
32 typedef struct stru_ip* NETSIM_IPAddress;
33
34struct stru_ip
35{
36 int type;
37 union
38 {
39 struct ipv4
40 {
41 unsigned int byte1;
42 unsigned int byte2;
43 unsigned int byte3;
44 unsigned int byte4;
46 struct ipv6
47 {
48 unsigned int byte[8];
51 unsigned int int_ip[4];
52
53 //The following are stored to do fast calculation
55 char bin_ip[130];
56 void *nets;
58};
59
60#define IP_COMPARE6(ip1,ip2) (ip1->int_ip[0]==ip2->int_ip[0] \
61 ?(ip1->int_ip[1]==ip2->int_ip[1] \
62 ?(ip1->int_ip[2]==ip2->int_ip[2] \
63 ?(ip1->int_ip[3]==ip2->int_ip[3]?0:1) :1) :1) :1)
64
65#define IP_COMPARE4(ip1,ip2) (ip1->int_ip[0]==ip2->int_ip[0]?0:1)
66
67#define IP_COMPARE(ip1,ip2) ((ip1)->type==(ip2)->type \
68 ? ((ip1)->type==4?IP_COMPARE4((ip1),(ip2)):IP_COMPARE6((ip1),(ip2))) \
69 :1)
70
71#define IP_TO_STR(ip,ipstr) ((ip)?(strcpy((ipstr),((ip)->str_ip))):strcpy(ipstr,"0.0.0.0"))
72
73
74_declspec(dllexport) NETSIM_IPAddress STR_TO_IP(char* ipStr,int type);
75
80_declspec(dllexport) void IP_TO_BINARY(NETSIM_IPAddress ip,char* binary);
81_declspec(dllexport) unsigned int IP_ADD_TO_LIST(NETSIM_IPAddress** pipList,unsigned int* count,const NETSIM_IPAddress ip);
82_declspec(dllexport) unsigned int IP_REMOVE_FROM_LIST(NETSIM_IPAddress* pipList,unsigned int* count,const NETSIM_IPAddress ip);
83_declspec(dllexport) int IP_CHECK_IN_LIST(const NETSIM_IPAddress* ipList,unsigned int count,const NETSIM_IPAddress ip);
84_declspec(dllexport) int IP_IS_IN_SAME_NETWORK(NETSIM_IPAddress ip1,NETSIM_IPAddress ip2,NETSIM_IPAddress subnet,unsigned int prefix_len);
87
88_declspec(dllexport) int IP_FREE_ALL(); //Free all IP. Used only by NetworkStack.dll after simulation
89//Validate all configured ip. return 1 if all ip is valid else return 0
90/** Very costly function. Use only for debugging **/
92
93_declspec(dllexport) int STR_GET_IP_TYPE(char* ip);
94#define STR_TO_IP4(ipstr) STR_TO_IP(ipstr,4)
95#define STR_TO_IP6(ipstr) STR_TO_IP(ipstr,6)
96
97#define IP_IS_IN_SAME_NETWORK_IPV4(ip1,ip2,subnet) IP_IS_IN_SAME_NETWORK(ip1,ip2,subnet,0)
98#define IP_IS_IN_SAME_NETWORK_IPV6(ip1,ip2,prefix) IP_IS_IN_SAME_NETWORK(ip1,ip2,NULL,prefix)
99
100#define IP_NETWORK_ADDRESS_IPV4(ip,subnet) IP_NETWORK_ADDRESS(ip,subnet,0)
101#define IP_NETWORK_ADDRESS_IPV6(ip,prefix) IP_NETWORK_ADDRESS(ip,NULL,prefix)
102
105_declspec(dllexport) bool isValidIPAddress(char* ip);
107
108#ifdef __cplusplus
109}
110#endif
111#endif
bool isValidIPAddress(char *ip)
NETSIM_IPAddress IP_COPY(NETSIM_IPAddress ip)
#define _NETSIM_IP_LEN
Definition: IP_Addressing.h:29
int IP_CHECK_IN_LIST(const NETSIM_IPAddress *ipList, unsigned int count, const NETSIM_IPAddress ip)
struct stru_ip * NETSIM_IPAddress
Definition: IP_Addressing.h:32
void IP_TO_BINARY(NETSIM_IPAddress ip, char *binary)
NETSIM_IPAddress STR_TO_IP(char *ipStr, int type)
unsigned int IP_ADD_TO_LIST(NETSIM_IPAddress **pipList, unsigned int *count, const NETSIM_IPAddress ip)
int IP_FREE_ALL()
NETSIM_IPAddress IP_COPY_FORCE(NETSIM_IPAddress ip)
NETSIM_IPAddress GET_BROADCAST_IP(int type)
int STR_GET_IP_TYPE(char *ip)
int IP_VALIDATE_ALL_IP()
unsigned int IP_REMOVE_FROM_LIST(NETSIM_IPAddress *pipList, unsigned int *count, const NETSIM_IPAddress ip)
bool isBroadcastIP(NETSIM_IPAddress ip)
NETSIM_IPAddress IP_NETWORK_ADDRESS(NETSIM_IPAddress ip, NETSIM_IPAddress subnet, unsigned int prefix_len)
void IP_FREE_FORCE(NETSIM_IPAddress ip)
int IP_find_match_length(NETSIM_IPAddress ip1, NETSIM_IPAddress ip2)
void IP_FREE(NETSIM_IPAddress ip)
int IP_IS_IN_SAME_NETWORK(NETSIM_IPAddress ip1, NETSIM_IPAddress ip2, NETSIM_IPAddress subnet, unsigned int prefix_len)
bool isMulticastIP(NETSIM_IPAddress ip)
#define _declspec(dllexport)
This function is used to trigger the update.
Definition: Linux.h:41
unsigned int byte4
Definition: IP_Addressing.h:44
unsigned int byte3
Definition: IP_Addressing.h:43
char str_ip[_NETSIM_IP_LEN]
Definition: IP_Addressing.h:54
unsigned int int_ip[4]
Definition: IP_Addressing.h:51
unsigned int byte1
Definition: IP_Addressing.h:41
char bin_ip[130]
Definition: IP_Addressing.h:55
void * macAddress
Definition: IP_Addressing.h:57
unsigned int byte2
Definition: IP_Addressing.h:42
struct stru_ip::@5::ipv4 IPV4
void * nets
Definition: IP_Addressing.h:56
struct stru_ip::@5::ipv6 IPV6
union stru_ip::@5 IP