function_name
stringlengths 1
80
| function
stringlengths 14
10.6k
| comment
stringlengths 12
8.02k
| normalized_comment
stringlengths 6
6.55k
|
|---|---|---|---|
GetTableInt
|
UINT GetTableInt(char *name)
{
char *str;
// Validate arguments
if (name == NULL)
{
return 0;
}
str = GetTableStr(name);
return ToInt(str);
}
|
/* Load the integer value from the table*/
|
Load the integer value from the table
|
GetTableUniStr
|
wchar_t *GetTableUniStr(char *name)
{
TABLE *t;
// Validate arguments
if (name == NULL)
{
// Debug("%s: ************\n", name);
return L"";
}
// Search
t = FindTable(name);
if (t == NULL)
{
//Debug("%s: UNICODE STRING NOT FOUND\n", name);
return L"";
}
return t->unistr;
}
|
/* Load a Unicode string from the table*/
|
Load a Unicode string from the table
|
GetTableStr
|
char *GetTableStr(char *name)
{
TABLE *t;
// Validate arguments
if (name == NULL)
{
return "";
}
#ifdef OS_WIN32
if (StrCmpi(name, "DEFAULT_FONT") == 0)
{
if (_II("LANG") == 2)
{
UINT os_type = GetOsType();
if (OS_IS_WINDOWS_9X(os_type) ||
GET_KETA(os_type, 100) <= 4)
{
// Use the SimSun font in Windows 9x, Windows NT 4.0, Windows 2000, Windows XP, and Windows Server 2003
return "SimSun";
}
}
}
#endif // OS_WIN32
// Search
t = FindTable(name);
if (t == NULL)
{
//Debug("%s: ANSI STRING NOT FOUND\n", name);
return "";
}
return t->str;
}
|
/* Load the string from the table*/
|
Load the string from the table
|
FindTable
|
TABLE *FindTable(char *name)
{
TABLE *t, tt;
// Validate arguments
if (name == NULL || TableList == NULL)
{
return NULL;
}
tt.name = CopyStr(name);
t = Search(TableList, &tt);
Free(tt.name);
return t;
}
|
/* Search the table*/
|
Search the table
|
CmpTableName
|
int CmpTableName(void *p1, void *p2)
{
TABLE *t1, *t2;
if (p1 == NULL || p2 == NULL)
{
return 0;
}
t1 = *(TABLE **)p1;
t2 = *(TABLE **)p2;
if (t1 == NULL || t2 == NULL)
{
return 0;
}
return StrCmpi(t1->name, t2->name);
}
|
/* A function that compares the table name*/
|
A function that compares the table name
|
FreeTable
|
void FreeTable()
{
UINT i, num;
TABLE **tables;
if (TableList == NULL)
{
return;
}
num = LIST_NUM(TableList);
tables = ToArray(TableList);
for (i = 0;i < num;i++)
{
TABLE *t = tables[i];
Free(t->name);
Free(t->str);
Free(t->unistr);
Free(t);
}
ReleaseList(TableList);
TableList = NULL;
Free(tables);
Zero(old_table_name, sizeof(old_table_name));
}
|
/* Release the table*/
|
Release the table
|
GetDynValueOrDefault
|
UINT64 GetDynValueOrDefault(char *name, UINT64 default_value, UINT64 min_value, UINT64 max_value)
{
UINT64 ret = GetDynValue(name);
if (ret == 0)
{
return default_value;
}
if (ret < min_value)
{
ret = min_value;
}
if (ret > max_value)
{
ret = max_value;
}
return ret;
}
|
/* Get a value from a dynamic value list (Returns a default value if the value is not found)*/
|
Get a value from a dynamic value list (Returns a default value if the value is not found)
|
GetDynValueOrDefaultSafe
|
UINT64 GetDynValueOrDefaultSafe(char *name, UINT64 default_value)
{
return GetDynValueOrDefault(name, default_value, default_value / (UINT64)5, default_value * (UINT64)50);
}
|
/* The value is limited to 1/5 to 50 times of the default value for safety*/
|
The value is limited to 1/5 to 50 times of the default value for safety
|
GetDynValue
|
UINT64 GetDynValue(char *name)
{
UINT64 ret = 0;
// Validate arguments
if (name == NULL)
{
return 0;
}
if (g_dyn_value_list == NULL)
{
return 0;
}
LockList(g_dyn_value_list);
{
UINT i;
for (i = 0; i < LIST_NUM(g_dyn_value_list);i++)
{
DYN_VALUE *vv = LIST_DATA(g_dyn_value_list, i);
if (StrCmpi(vv->Name, name) == 0)
{
ret = vv->Value;
break;
}
}
}
UnlockList(g_dyn_value_list);
return ret;
}
|
/* Get a value from a dynamic value list*/
|
Get a value from a dynamic value list
|
ExtractAndApplyDynList
|
void ExtractAndApplyDynList(PACK *p)
{
BUF *b;
// Validate arguments
if (p == NULL)
{
return;
}
b = PackGetBuf(p, "DynList");
if (b == NULL)
{
return;
}
AddDynList(b);
FreeBuf(b);
}
|
/* Apply by extracting dynamic value list from the specified PACK*/
|
Apply by extracting dynamic value list from the specified PACK
|
AddDynList
|
void AddDynList(BUF *b)
{
PACK *p;
TOKEN_LIST *t;
// Validate arguments
if (b == NULL)
{
return;
}
SeekBufToBegin(b);
p = BufToPack(b);
if (p == NULL)
{
return;
}
t = GetPackElementNames(p);
if (t != NULL)
{
UINT i;
for (i = 0;i < t->NumTokens;i++)
{
char *name = t->Token[i];
UINT64 v = PackGetInt64(p, name);
SetDynListValue(name, v);
}
FreeToken(t);
}
FreePack(p);
}
|
/* Insert the data to the dynamic value list*/
|
Insert the data to the dynamic value list
|
InitDynList
|
void InitDynList()
{
g_dyn_value_list = NewList(NULL);
}
|
/* Initialization of the dynamic value list*/
|
Initialization of the dynamic value list
|
FreeDynList
|
void FreeDynList()
{
UINT i;
if (g_dyn_value_list == NULL)
{
return;
}
for (i = 0;i < LIST_NUM(g_dyn_value_list);i++)
{
DYN_VALUE *d = LIST_DATA(g_dyn_value_list, i);
Free(d);
}
ReleaseList(g_dyn_value_list);
g_dyn_value_list = NULL;
}
|
/* Solution of dynamic value list*/
|
Solution of dynamic value list
|
DisableRDUPServerGlobally
|
void DisableRDUPServerGlobally()
{
g_no_rudp_server = true;
}
|
/* Disable NAT-T function globally*/
|
Disable NAT-T function globally
|
GetCurrentTimezone
|
int GetCurrentTimezone()
{
int ret = 0;
#ifdef OS_WIN32
ret = GetCurrentTimezoneWin32();
#else // OS_WIN32
{
#if defined(UNIX_MACOS) || defined(UNIX_BSD)
struct timeval tv;
struct timezone tz;
Zero(&tv, sizeof(tv));
Zero(&tz, sizeof(tz));
gettimeofday(&tv, &tz);
ret = tz.tz_minuteswest;
#else // defined(UNIX_MACOS) || defined(UNIX_BSD)
tzset();
ret = timezone / 60;
#endif // defined(UNIX_MACOS) || defined(UNIX_BSD)
}
#endif // OS_WIN32
return ret;
}
|
/* Get the current time zone*/
|
Get the current time zone
|
IsUseDnsProxy
|
bool IsUseDnsProxy()
{
return false;
}
|
/* Flag of whether to use the DNS proxy*/
|
Flag of whether to use the DNS proxy
|
IsUseAlternativeHostname
|
bool IsUseAlternativeHostname()
{
return false;
}
|
/* Flag of whether to use an alternate host name*/
|
Flag of whether to use an alternate host name
|
GetCurrentTimezoneWin32
|
int GetCurrentTimezoneWin32()
{
TIME_ZONE_INFORMATION info;
Zero(&info, sizeof(info));
if (GetTimeZoneInformation(&info) == TIME_ZONE_ID_INVALID)
{
return 0;
}
return info.Bias;
}
|
/* Get the current time zone (Win32)*/
|
Get the current time zone (Win32)
|
SetCurrentDDnsFqdn
|
void SetCurrentDDnsFqdn(char *name)
{
// Validate arguments
if (name == NULL)
{
return;
}
Lock(current_fqdn_lock);
{
StrCpy(current_fqdn, sizeof(current_fqdn), name);
}
Unlock(current_fqdn_lock);
}
|
/* Set the current FQDN of the DDNS*/
|
Set the current FQDN of the DDNS
|
GetCurrentDDnsFqdnHash
|
UINT GetCurrentDDnsFqdnHash()
{
UINT ret;
UCHAR hash[SHA1_SIZE];
char name[MAX_SIZE];
ClearStr(name, sizeof(name));
GetCurrentDDnsFqdn(name, sizeof(name));
Trim(name);
StrUpper(name);
Sha1(hash, name, StrLen(name));
Copy(&ret, hash, sizeof(UINT));
return ret;
}
|
/* Get the current DDNS FQDN hash*/
|
Get the current DDNS FQDN hash
|
GetCurrentDDnsFqdn
|
void GetCurrentDDnsFqdn(char *name, UINT size)
{
ClearStr(name, size);
// Validate arguments
if (name == NULL || size == 0)
{
return;
}
Lock(current_fqdn_lock);
{
StrCpy(name, size, current_fqdn);
}
Unlock(current_fqdn_lock);
Trim(name);
}
|
/* Get the current DDNS FQDN*/
|
Get the current DDNS FQDN
|
IsMacAddressLocalFast
|
bool IsMacAddressLocalFast(void *addr)
{
bool ret = false;
// Validate arguments
if (addr == NULL)
{
return false;
}
Lock(local_mac_list_lock);
{
if (local_mac_list == NULL)
{
// First enumeration
RefreshLocalMacAddressList();
}
ret = IsMacAddressLocalInner(local_mac_list, addr);
}
Unlock(local_mac_list_lock);
return ret;
}
|
/* Check whether the specified MAC address exists on the local host (high speed)*/
|
Check whether the specified MAC address exists on the local host (high speed)
|
RefreshLocalMacAddressList
|
void RefreshLocalMacAddressList()
{
Lock(local_mac_list_lock);
{
if (local_mac_list != NULL)
{
FreeNicList(local_mac_list);
}
local_mac_list = GetNicList();
}
Unlock(local_mac_list_lock);
}
|
/* Update the local MAC address list*/
|
Update the local MAC address list
|
IsMacAddressLocalInner
|
bool IsMacAddressLocalInner(LIST *o, void *addr)
{
bool ret = false;
UINT i;
// Validate arguments
if (o == NULL || addr == NULL)
{
return false;
}
for (i = 0;i < LIST_NUM(o);i++)
{
NIC_ENTRY *e = LIST_DATA(o, i);
if (Cmp(e->MacAddress, addr, 6) == 0)
{
ret = true;
break;
}
}
return ret;
}
|
/* Check whether the specified MAC address exists on the local host*/
|
Check whether the specified MAC address exists on the local host
|
GetNicList
|
LIST *GetNicList()
{
LIST *o = NULL;
#ifdef OS_WIN32
o = Win32GetNicList();
if (o != NULL)
{
return o;
}
#endif // OS_WIN32
return NewListFast(NULL);
}
|
/* Get a list of the NICs on the computer*/
|
Get a list of the NICs on the computer
|
FreeNicList
|
void FreeNicList(LIST *o)
{
UINT i;
// Validate arguments
if (o == NULL)
{
return;
}
for (i = 0;i < LIST_NUM(o);i++)
{
NIC_ENTRY *e = LIST_DATA(o, i);
Free(e);
}
ReleaseList(o);
}
|
/* Release the NIC list*/
|
Release the NIC list
|
DetectFletsType
|
UINT DetectFletsType()
{
UINT ret = 0;
//LIST *o = GetHostIPAddressList();
// UINT i;
/*
for (i = 0;i < LIST_NUM(o);i++)
{
IP *ip = LIST_DATA(o, i);
if (IsIP6(ip))
{
char ip_str[MAX_SIZE];
IPToStr(ip_str, sizeof(ip_str), ip);
if (IsInSameNetwork6ByStr(ip_str, "2001:c90::", "/32"))
{
// NTT East B-FLETs
ret |= FLETS_DETECT_TYPE_EAST_BFLETS_PRIVATE;
}
if (IsInSameNetwork6ByStr(ip_str, "2408:200::", "/23"))
{
// Wrapping in network of NTT East NGN
ret |= FLETS_DETECT_TYPE_EAST_NGN_PRIVATE;
}
if (IsInSameNetwork6ByStr(ip_str, "2001:a200::", "/23"))
{
// Wrapping in network of NTT West NGN
ret |= FLETS_DETECT_TYPE_WEST_NGN_PRIVATE;
}
}
}
FreeHostIPAddressList(o);
*/
return ret;
}
|
/* If the computer is connected to the FLET'S line currently, detect the type of the line (obsolete)*/
|
If the computer is connected to the FLET'S line currently, detect the type of the line (obsolete)
|
ListenRUDP
|
SOCK *ListenRUDP(char *svc_name, RUDP_STACK_INTERRUPTS_PROC *proc_interrupts, RUDP_STACK_RPC_RECV_PROC *proc_rpc_recv, void *param, UINT port, bool no_natt_register, bool over_dns_mode)
{
return ListenRUDPEx(svc_name, proc_interrupts, proc_rpc_recv, param, port, no_natt_register, over_dns_mode, NULL, 0, NULL);
}
|
/* Start a socket for R-UDP Listening*/
|
Start a socket for R-UDP Listening
|
RUDPProcessAck
|
void RUDPProcessAck(RUDP_STACK *r, RUDP_SESSION *se, UINT64 seq)
{
RUDP_SEGMENT t;
RUDP_SEGMENT *s;
// Validate arguments
if (r == NULL || se == NULL || seq == 0)
{
return;
}
Zero(&t, sizeof(t));
t.SeqNo = seq;
s = Search(se->SendSegmentList, &t);
if (s == NULL)
{
return;
}
Delete(se->SendSegmentList, s);
Free(s);
}
|
/* Process the incoming ACK*/
|
Process the incoming ACK
|
RUDPGetCurrentSendingMinSeqNo
|
UINT64 RUDPGetCurrentSendingMinSeqNo(RUDP_SESSION *se)
{
RUDP_SEGMENT *s;
// Validate arguments
if (se == NULL)
{
return 0;
}
if (LIST_NUM(se->SendSegmentList) == 0)
{
return 0;
}
s = LIST_DATA(se->SendSegmentList, 0);
return s->SeqNo;
}
|
/* Get the minimum sequence number which is trying to send*/
|
Get the minimum sequence number which is trying to send
|
RUDPGetCurrentSendingMaxSeqNo
|
UINT64 RUDPGetCurrentSendingMaxSeqNo(RUDP_SESSION *se)
{
RUDP_SEGMENT *s;
// Validate arguments
if (se == NULL)
{
return 0;
}
if (LIST_NUM(se->SendSegmentList) == 0)
{
return 0;
}
s = LIST_DATA(se->SendSegmentList, (LIST_NUM(se->SendSegmentList) - 1));
return s->SeqNo;
}
|
/* Get the maximum sequence number which is trying to send*/
|
Get the maximum sequence number which is trying to send
|
RUDPSendSegment
|
void RUDPSendSegment(RUDP_STACK *r, RUDP_SESSION *se, void *data, UINT size)
{
RUDP_SEGMENT *s;
// Validate arguments
if (r == NULL || se == NULL || (size != 0 && data == NULL) || (size > RUDP_MAX_SEGMENT_SIZE))
{
return;
}
s = ZeroMalloc(sizeof(RUDP_SEGMENT));
Copy(s->Data, data, size);
s->Size = size;
s->SeqNo = se->NextSendSeqNo++;
Insert(se->SendSegmentList, s);
}
|
/* R-UDP segment transmission (only put into the queue)*/
|
R-UDP segment transmission (only put into the queue)
|
RUDPSearchSession
|
RUDP_SESSION *RUDPSearchSession(RUDP_STACK *r, IP *my_ip, UINT my_port, IP *your_ip, UINT your_port)
{
RUDP_SESSION t;
RUDP_SESSION *se;
// Validate arguments
if (r == NULL || my_ip == NULL || your_ip == NULL)
{
return NULL;
}
Copy(&t.MyIp, my_ip, sizeof(IP));
t.MyPort = my_port;
Copy(&t.YourIp, your_ip, sizeof(IP));
t.YourPort = your_port;
se = Search(r->SessionList, &t);
return se;
}
|
/* Search for a session*/
|
Search for a session
|
RUDPCompareSegmentList
|
int RUDPCompareSegmentList(void *p1, void *p2)
{
RUDP_SEGMENT *s1, *s2;
UINT r;
// Validate arguments
if (p1 == NULL || p2 == NULL)
{
return 0;
}
s1 = *((RUDP_SEGMENT **)p1);
s2 = *((RUDP_SEGMENT **)p2);
if (s1 == NULL || s2 == NULL)
{
return 0;
}
r = COMPARE_RET(s1->SeqNo, s2->SeqNo);
return r;
}
|
/* Comparison function of the segment list items*/
|
Comparison function of the segment list items
|
GenRandInterval
|
UINT GenRandInterval(UINT min, UINT max)
{
UINT a, b;
a = MIN(min, max);
b = MAX(min, max);
if (a == b)
{
return a;
}
return (Rand32() % (b - a)) + a;
}
|
/* Generate a random intervals*/
|
Generate a random intervals
|
IsIPLocalHostOrMySelf
|
bool IsIPLocalHostOrMySelf(IP *ip)
{
LIST *o;
bool ret = false;
UINT i;
// Validate arguments
if (ip == NULL)
{
return false;
}
o = GetHostIPAddressList();
if (o == NULL)
{
return false;
}
for (i = 0;i < LIST_NUM(o);i++)
{
IP *p = LIST_DATA(o, i);
if (CmpIpAddr(p, ip) == 0)
{
ret = true;
break;
}
}
FreeHostIPAddressList(o);
if (IsLocalHostIP4(ip) || IsLocalHostIP6(ip))
{
ret = true;
}
return ret;
}
|
/* Check whether the specified IP address is localhost or the IP address of the local interface of itself*/
|
Check whether the specified IP address is localhost or the IP address of the local interface of itself
|
NewUDP4ForSpecificIp
|
SOCK *NewUDP4ForSpecificIp(IP *target_ip, UINT port)
{
SOCK *s;
IP local_ip;
// Validate arguments
if (target_ip == NULL || IsZeroIP(target_ip) || IsIP4(target_ip) == false)
{
target_ip = NULL;
}
Zero(&local_ip, sizeof(local_ip));
GetBestLocalIpForTarget(&local_ip, target_ip);
s = NewUDP4(port, &local_ip);
if (s == NULL)
{
s = NewUDP4(port, NULL);
}
return s;
}
|
/* Create an IPv4 UDP socket destined for a particular target*/
|
Create an IPv4 UDP socket destined for a particular target
|
ListenTcpForPopupFirewallDialog
|
void ListenTcpForPopupFirewallDialog()
{
#ifdef OS_WIN32
static bool tried = false;
if (tried == false)
{
SOCK *s;
tried = true;
s = ListenAnyPortEx2(false, true);
if (s != NULL)
{
Disconnect(s);
ReleaseSock(s);
}
}
#endif // OS_WIN32
}
|
/* Listen to the TCP for a moment to show the firewall dialog*/
|
Listen to the TCP for a moment to show the firewall dialog
|
GetCurrentMachineIpProcessHash
|
void GetCurrentMachineIpProcessHash(void *hash)
{
// Validate arguments
if (hash == NULL)
{
return;
}
Lock(machine_ip_process_hash_lock);
{
if (IsZero(machine_ip_process_hash, SHA1_SIZE))
{
GetCurrentMachineIpProcessHashInternal(machine_ip_process_hash);
}
Copy(hash, machine_ip_process_hash, SHA1_SIZE);
}
Unlock(machine_ip_process_hash_lock);
}
|
/* Generate a hash from the current computer name and the process name*/
|
Generate a hash from the current computer name and the process name
|
ListenAnyPortEx2
|
SOCK *ListenAnyPortEx2(bool local_only, bool disable_ca)
{
UINT i;
SOCK *s;
for (i = 40000;i < 65536;i++)
{
s = ListenEx(i, local_only);
if (s != NULL)
{
return s;
}
}
return NULL;
}
|
/* Listen in any available port*/
|
Listen in any available port
|
NewSslPipe
|
SSL_PIPE *NewSslPipe(bool server_mode, X *x, K *k, DH_CTX *dh)
{
return NewSslPipeEx(server_mode, x, k, dh, false, NULL);
}
|
/* Create a new SSL pipe*/
|
Create a new SSL pipe
|
FreeSslPipe
|
void FreeSslPipe(SSL_PIPE *s)
{
// Validate arguments
if (s == NULL)
{
return;
}
FreeSslBio(s->SslInOut);
FreeSslBio(s->RawIn);
FreeSslBio(s->RawOut);
SSL_free(s->ssl);
SSL_CTX_free(s->ssl_ctx);
Free(s);
}
|
/* Release of the SSL pipe*/
|
Release of the SSL pipe
|
FreeSslBio
|
void FreeSslBio(SSL_BIO *b)
{
// Validate arguments
if (b == NULL)
{
return;
}
if (b->NoFree == false)
{
BIO_free(b->bio);
}
ReleaseFifo(b->RecvFifo);
ReleaseFifo(b->SendFifo);
Free(b);
}
|
/* Release of the SSL BIO*/
|
Release of the SSL BIO
|
NewSslBioSsl
|
SSL_BIO *NewSslBioSsl()
{
SSL_BIO *b = ZeroMalloc(sizeof(SSL_BIO));
b->bio = BIO_new(BIO_f_ssl());
b->RecvFifo = NewFifo();
b->SendFifo = NewFifo();
return b;
}
|
/* Create a new SSL BIO (SSL)*/
|
Create a new SSL BIO (SSL)
|
NewSslBioMem
|
SSL_BIO *NewSslBioMem()
{
SSL_BIO *b = ZeroMalloc(sizeof(SSL_BIO));
b->bio = BIO_new(BIO_s_mem());
b->RecvFifo = NewFifo();
b->SendFifo = NewFifo();
return b;
}
|
/* Create a new SSL BIO (memory)*/
|
Create a new SSL BIO (memory)
|
IcmpApiFreeResult
|
void IcmpApiFreeResult(ICMP_RESULT *ret)
{
// Validate arguments
if (ret == NULL)
{
return;
}
if (ret->Data != NULL)
{
Free(ret->Data);
}
Free(ret);
}
|
/* Release the memory for the return value of the ICMP API*/
|
Release the memory for the return value of the ICMP API
|
IsIcmpApiSupported
|
bool IsIcmpApiSupported()
{
#ifdef OS_WIN32
if (w32net->IcmpCloseHandle != NULL &&
w32net->IcmpCreateFile != NULL &&
w32net->IcmpSendEcho != NULL)
{
return true;
}
#endif // OS_WIN32
return false;
}
|
/* Detect whether the ICMP API is supported*/
|
Detect whether the ICMP API is supported
|
NewRouteChange
|
ROUTE_CHANGE *NewRouteChange()
{
#ifdef OS_WIN32
return Win32NewRouteChange();
#else // OS_WIN32
return NULL;
#endif // OS_WIN32
}
|
/* Initialize the routing table change detector*/
|
Initialize the routing table change detector
|
FreeRouteChange
|
void FreeRouteChange(ROUTE_CHANGE *r)
{
#ifdef OS_WIN32
Win32FreeRouteChange(r);
#endif // OS_WIN32
}
|
/* Release the routing table change detector*/
|
Release the routing table change detector
|
IsRouteChanged
|
bool IsRouteChanged(ROUTE_CHANGE *r)
{
#ifdef OS_WIN32
return Win32IsRouteChanged(r);
#else // OS_WIN32
return false;
#endif // OS_WIN32
}
|
/* Get whether the routing table has been changed*/
|
Get whether the routing table has been changed
|
SetLinuxArpFilter
|
void SetLinuxArpFilter()
{
char *filename = "/proc/sys/net/ipv4/conf/all/arp_filter";
char *data = "1\n";
IO *o;
o = FileCreate(filename);
if (o == NULL)
{
return;
}
FileWrite(o, data, StrLen(data));
FileFlush(o);
FileClose(o);
}
|
/* Set the arp_filter in Linux*/
|
Set the arp_filter in Linux
|
IsIpMask6
|
bool IsIpMask6(char *str)
{
IP mask;
// Validate arguments
if (str == NULL)
{
return false;
}
return StrToMask6(&mask, str);
}
|
/* Determine whether the string is a IPv6 mask*/
|
Determine whether the string is a IPv6 mask
|
IsStrIPv6Address
|
bool IsStrIPv6Address(char *str)
{
IP ip;
// Validate arguments
if (str == NULL)
{
return false;
}
if (StrToIP6(&ip, str) == false)
{
return false;
}
return true;
}
|
/* Determine whether the string is a IPv6 address*/
|
Determine whether the string is a IPv6 address
|
SubnetMaskToInt6
|
UINT SubnetMaskToInt6(IP *a)
{
UINT i;
// Validate arguments
if (IsIP6(a) == false)
{
return 0;
}
for (i = 0;i <= 128;i++)
{
IP tmp;
IntToSubnetMask6(&tmp, i);
if (CmpIpAddr(a, &tmp) == 0)
{
return i;
}
}
return 0;
}
|
/* Convert the subnet mask to an integer*/
|
Convert the subnet mask to an integer
|
IsSubnetMask6
|
bool IsSubnetMask6(IP *a)
{
UINT i;
// Validate arguments
if (IsIP6(a) == false)
{
return false;
}
for (i = 0;i <= 128;i++)
{
IP tmp;
IntToSubnetMask6(&tmp, i);
if (CmpIpAddr(a, &tmp) == 0)
{
return true;
}
}
return false;
}
|
/* Determine whether the specified IP address is a subnet mask*/
|
Determine whether the specified IP address is a subnet mask
|
GenerateEui64LocalAddress
|
void GenerateEui64LocalAddress(IP *a, UCHAR *mac)
{
UCHAR tmp[8];
// Validate arguments
if (a == NULL || mac == NULL)
{
return;
}
GenerateEui64Address6(tmp, mac);
ZeroIP6(a);
a->ipv6_addr[0] = 0xfe;
a->ipv6_addr[1] = 0x80;
Copy(&a->ipv6_addr[8], tmp, 8);
}
|
/* Generate a local address from the MAC address*/
|
Generate a local address from the MAC address
|
GenerateEui64Address6
|
void GenerateEui64Address6(UCHAR *dst, UCHAR *mac)
{
// Validate arguments
if (dst == NULL || mac == NULL)
{
return;
}
Copy(dst, mac, 3);
Copy(dst + 5, mac, 3);
dst[3] = 0xff;
dst[4] = 0xfe;
dst[0] = ((~(dst[0] & 0x02)) & 0x02) | (dst[0] & 0xfd);
}
|
/* Generate the EUI-64 address from the MAC address*/
|
Generate the EUI-64 address from the MAC address
|
IsInSameNetwork6ByStr
|
bool IsInSameNetwork6ByStr(char *ip1, char *ip2, char *subnet)
{
IP p1, p2, s;
if (StrToIP6(&p1, ip1) == false)
{
return false;
}
if (StrToIP6(&p2, ip2) == false)
{
return false;
}
if (StrToMask6(&s, subnet) == false)
{
return false;
}
return IsInSameNetwork6(&p1, &p2, &s);
}
|
/* Examine whether two IP addresses are in the same network*/
|
Examine whether two IP addresses are in the same network
|
GetPrefixAddress6
|
void GetPrefixAddress6(IP *dst, IP *ip, IP *subnet)
{
// Validate arguments
if (dst == NULL || ip == NULL || subnet == NULL)
{
return;
}
IPAnd6(dst, ip, subnet);
dst->ipv6_scope_id = ip->ipv6_scope_id;
}
|
/* Get the prefix address*/
|
Get the prefix address
|
GetIPv6AddrType
|
UINT GetIPv6AddrType(IPV6_ADDR *addr)
{
IP ip;
// Validate arguments
if (addr == NULL)
{
return 0;
}
IPv6AddrToIP(&ip, addr);
return GetIPAddrType6(&ip);
}
|
/* Get the type of the IPv6 address*/
|
Get the type of the IPv6 address
|
GetAllNodeMulticaseAddress6
|
void GetAllNodeMulticaseAddress6(IP *ip)
{
// Validate arguments
if (ip == NULL)
{
return;
}
ZeroIP6(ip);
ip->ipv6_addr[0] = 0xff;
ip->ipv6_addr[1] = 0x02;
ip->ipv6_addr[15] = 0x01;
}
|
/* All-nodes multicast address*/
|
All-nodes multicast address
|
GetAllRouterMulticastAddress6
|
void GetAllRouterMulticastAddress6(IP *ip)
{
// Validate arguments
if (ip == NULL)
{
return;
}
ZeroIP6(ip);
ip->ipv6_addr[0] = 0xff;
ip->ipv6_addr[1] = 0x02;
ip->ipv6_addr[15] = 0x02;
}
|
/* All-routers multicast address*/
|
All-routers multicast address
|
IPAnd4
|
void IPAnd4(IP *dst, IP *a, IP *b)
{
UINT i;
// Validate arguments
if (dst == NULL || a == NULL || b == NULL || IsIP4(a) == false || IsIP4(b) == false)
{
Zero(dst, sizeof(IP));
return;
}
i = IPToUINT(a) & IPToUINT(b);
UINTToIP(dst, i);
}
|
/* Logical operation of the IPv4 address*/
|
Logical operation of the IPv4 address
|
IPAnd6
|
void IPAnd6(IP *dst, IP *a, IP *b)
{
UINT i;
// Validate arguments
if (dst == NULL || IsIP6(a) == false || IsIP6(b) == false)
{
ZeroIP6(dst);
return;
}
ZeroIP6(dst);
for (i = 0;i < 16;i++)
{
dst->ipv6_addr[i] = a->ipv6_addr[i] & b->ipv6_addr[i];
}
}
|
/* Logical operation of the IPv6 address*/
|
Logical operation of the IPv6 address
|
IntToSubnetMask6
|
void IntToSubnetMask6(IP *ip, UINT i)
{
UINT j = i / 8;
UINT k = i % 8;
UINT z;
IP a;
ZeroIP6(&a);
for (z = 0;z < 16;z++)
{
if (z < j)
{
a.ipv6_addr[z] = 0xff;
}
else if (z == j)
{
a.ipv6_addr[z] = ~(0xff >> k);
}
}
Copy(ip, &a, sizeof(IP));
}
|
/* Creating a subnet mask*/
|
Creating a subnet mask
|
IP6AddrToStr
|
void IP6AddrToStr(char *str, UINT size, IPV6_ADDR *addr)
{
// Validate arguments
if (str == NULL || addr == NULL)
{
return;
}
IPToStr6Array(str, size, addr->Value);
}
|
/* Convert the IP address to a string*/
|
Convert the IP address to a string
|
CheckIPItemStr6
|
bool CheckIPItemStr6(char *str)
{
UINT i, len;
// Validate arguments
if (str == NULL)
{
return false;
}
len = StrLen(str);
if (len >= 5)
{
// Invalid length
return false;
}
for (i = 0;i < len;i++)
{
char c = str[i];
if ((c >= 'a' && c <= 'f') ||
(c >= 'A' && c <= 'F') ||
(c >= '0' && c <= '9'))
{
}
else
{
return false;
}
}
return true;
}
|
/* Check whether invalid characters are included in the element string of the IP address*/
|
Check whether invalid characters are included in the element string of the IP address
|
ZeroIP4
|
void ZeroIP4(IP *ip)
{
// Validate arguments
if (ip == NULL)
{
return;
}
Zero(ip, sizeof(IP));
}
|
/* Create an IPv4 address of all zero*/
|
Create an IPv4 address of all zero
|
ZeroIP6
|
void ZeroIP6(IP *ip)
{
// Validate arguments
if (ip == NULL)
{
return;
}
SetIP6(ip, NULL);
}
|
/* Create an IPv6 address of all zero*/
|
Create an IPv6 address of all zero
|
GetLocalHostIP6
|
void GetLocalHostIP6(IP *ip)
{
// Validate arguments
if (ip == NULL)
{
return;
}
ZeroIP6(ip);
ip->ipv6_addr[15] = 1;
}
|
/* Get the IP address of the localhost*/
|
Get the IP address of the localhost
|
IsLocalHostIP6
|
bool IsLocalHostIP6(IP *ip)
{
IP local;
// Validate arguments
if (ip == NULL)
{
return false;
}
if (IsIP6(ip) == false)
{
return false;
}
GetLocalHostIP6(&local);
if (CmpIpAddr(&local, ip) == 0)
{
return true;
}
return false;
}
|
/* Check whether the specified address is a localhost*/
|
Check whether the specified address is a localhost
|
IPv6AddrToIP
|
void IPv6AddrToIP(IP *ip, IPV6_ADDR *addr)
{
// Validate arguments
if (ip == NULL || addr == NULL)
{
return;
}
SetIP6(ip, addr->Value);
}
|
/* Convert the IPV6_ADDR to an IP*/
|
Convert the IPV6_ADDR to an IP
|
IPToIPv6Addr
|
bool IPToIPv6Addr(IPV6_ADDR *addr, IP *ip)
{
UINT i;
// Validate arguments
if (addr == NULL || ip == NULL)
{
Zero(addr, sizeof(IPV6_ADDR));
return false;
}
if (IsIP6(ip) == false)
{
Zero(addr, sizeof(IPV6_ADDR));
return false;
}
for (i = 0;i < 16;i++)
{
addr->Value[i] = ip->ipv6_addr[i];
}
return true;
}
|
/* Convert the IP to an IPV6_ADDR*/
|
Convert the IP to an IPV6_ADDR
|
SetIP6
|
void SetIP6(IP *ip, UCHAR *value)
{
// Validate arguments
if (ip == NULL)
{
return;
}
Zero(ip, sizeof(IP));
ip->addr[0] = 223;
ip->addr[1] = 255;
ip->addr[2] = 255;
ip->addr[3] = 254;
if (value != NULL)
{
UINT i;
for (i = 0;i < 16;i++)
{
ip->ipv6_addr[i] = value[i];
}
}
}
|
/* Set an IPv6 address*/
|
Set an IPv6 address
|
IsIP6
|
bool IsIP6(IP *ip)
{
// Validate arguments
if (ip == NULL)
{
return false;
}
if (ip->addr[0] == 223 && ip->addr[1] == 255 && ip->addr[2] == 255 && ip->addr[3] == 254)
{
return true;
}
return false;
}
|
/* Check whether the specified address is a IPv6 address*/
|
Check whether the specified address is a IPv6 address
|
CopyIP
|
void CopyIP(IP *dst, IP *src)
{
Copy(dst, src, sizeof(IP));
}
|
/* Copy the IP address*/
|
Copy the IP address
|
GetNumIpClient
|
UINT GetNumIpClient(IP *ip)
{
IP_CLIENT *c;
UINT ret = 0;
// Validate arguments
if (ip == NULL)
{
return 0;
}
LockList(ip_clients);
{
c = SearchIpClient(ip);
if (c != NULL)
{
ret = c->NumConnections;
}
}
UnlockList(ip_clients);
return ret;
}
|
/* Get the number of clients connected from the specified IP address*/
|
Get the number of clients connected from the specified IP address
|
AddIpClient
|
void AddIpClient(IP *ip)
{
IP_CLIENT *c;
// Validate arguments
if (ip == NULL)
{
return;
}
LockList(ip_clients);
{
c = SearchIpClient(ip);
if (c == NULL)
{
c = ZeroMallocFast(sizeof(IP_CLIENT));
Copy(&c->IpAddress, ip, sizeof(IP));
c->NumConnections = 0;
Add(ip_clients, c);
}
c->NumConnections++;
}
UnlockList(ip_clients);
//Debug("AddIpClient: %r\n", ip);
}
|
/* Add to the IP client entry*/
|
Add to the IP client entry
|
DelIpClient
|
void DelIpClient(IP *ip)
{
IP_CLIENT *c;
// Validate arguments
if (ip == NULL)
{
return;
}
LockList(ip_clients);
{
c = SearchIpClient(ip);
if (c != NULL)
{
c->NumConnections--;
if (c->NumConnections == 0)
{
Delete(ip_clients, c);
Free(c);
}
}
}
UnlockList(ip_clients);
//Debug("DelIpClient: %r\n", ip);
}
|
/* Remove from the IP client list*/
|
Remove from the IP client list
|
SearchIpClient
|
IP_CLIENT *SearchIpClient(IP *ip)
{
IP_CLIENT t;
// Validate arguments
if (ip == NULL)
{
return NULL;
}
Zero(&t, sizeof(t));
Copy(&t.IpAddress, ip, sizeof(IP));
return Search(ip_clients, &t);
}
|
/* Search for the IP client entry*/
|
Search for the IP client entry
|
InitIpClientList
|
void InitIpClientList()
{
ip_clients = NewList(CompareIpClientList);
}
|
/* Initialization of the client list*/
|
Initialization of the client list
|
FreeIpClientList
|
void FreeIpClientList()
{
UINT i;
for (i = 0;i < LIST_NUM(ip_clients);i++)
{
IP_CLIENT *c = LIST_DATA(ip_clients, i);
Free(c);
}
ReleaseList(ip_clients);
ip_clients = NULL;
}
|
/* Release of the client list*/
|
Release of the client list
|
CompareIpClientList
|
int CompareIpClientList(void *p1, void *p2)
{
IP_CLIENT *c1, *c2;
if (p1 == NULL || p2 == NULL)
{
return 0;
}
c1 = *(IP_CLIENT **)p1;
c2 = *(IP_CLIENT **)p2;
if (c1 == NULL || c2 == NULL)
{
return 0;
}
return CmpIpAddr(&c1->IpAddress, &c2->IpAddress);
}
|
/* Comparison of the client list entries*/
|
Comparison of the client list entries
|
NormalizeMacAddress
|
bool NormalizeMacAddress(char *dst, UINT size, char *src)
{
BUF *b;
bool ret = false;
// Validate arguments
if (dst == NULL || src == NULL)
{
return false;
}
b = StrToBin(src);
if (b != NULL && b->Size == 6)
{
ret = true;
BinToStr(dst, size, b->Buf, b->Size);
}
FreeBuf(b);
return ret;
}
|
/* Normalization of the MAC address*/
|
Normalization of the MAC address
|
IsZeroIP
|
bool IsZeroIP(IP *ip)
{
return IsZeroIp(ip);
}
|
/* Identify whether the IP address is empty*/
|
Identify whether the IP address is empty
|
IsHostIPAddress4
|
bool IsHostIPAddress4(IP *ip)
{
UINT a;
// Validate arguments
if (ip == NULL)
{
return false;
}
a = IPToUINT(ip);
if (a == 0 || a == 0xffffffff)
{
return false;
}
return true;
}
|
/* Examine whether the specified IP address is meaningful as a host*/
|
Examine whether the specified IP address is meaningful as a host
|
IsNetworkAddress4
|
bool IsNetworkAddress4(IP *ip, IP *mask)
{
UINT a, b;
// Validate arguments
if (ip == NULL || mask == NULL)
{
return false;
}
if (IsIP4(ip) == false || IsIP4(mask) == false)
{
return false;
}
if (IsSubnetMask4(mask) == false)
{
return false;
}
a = IPToUINT(ip);
b = IPToUINT(mask);
if ((a & b) == a)
{
return true;
}
return false;
}
|
/* Check whether the specified IP address and subnet mask indicates a network correctly*/
|
Check whether the specified IP address and subnet mask indicates a network correctly
|
IsSubnetMask
|
bool IsSubnetMask(IP *ip)
{
if (IsIP6(ip))
{
return IsSubnetMask6(ip);
}
else
{
return IsSubnetMask4(ip);
}
}
|
/* Examine whether the specified IP address is a subnet mask*/
|
Examine whether the specified IP address is a subnet mask
|
UnixSetSocketNonBlockingMode
|
void UnixSetSocketNonBlockingMode(int fd, bool nonblock)
{
UINT flag = 0;
// Validate arguments
if (fd == INVALID_SOCKET)
{
return;
}
if (nonblock)
{
flag = 1;
}
#ifdef FIONBIO
ioctl(fd, FIONBIO, &flag);
#else // FIONBIO
{
int flag = fcntl(fd, F_GETFL, 0);
if (flag != -1)
{
if (nonblock)
{
flag |= O_NONBLOCK;
}
else
{
flag = flag & ~O_NONBLOCK;
fcntl(fd, F_SETFL, flag);
}
}
}
#endif // FIONBIO
}
|
/* Turn on and off the non-blocking mode of the socket*/
|
Turn on and off the non-blocking mode of the socket
|
UnixCleanupCancel
|
void UnixCleanupCancel(CANCEL *c)
{
// Validate arguments
if (c == NULL)
{
return;
}
if (c->SpecialFlag == false)
{
UnixDeletePipe(c->pipe_read, c->pipe_write);
}
Free(c);
}
|
/* Release of the cancel object*/
|
Release of the cancel object
|
UnixNewCancel
|
CANCEL *UnixNewCancel()
{
CANCEL *c = ZeroMallocFast(sizeof(CANCEL));
c->ref = NewRef();
c->SpecialFlag = false;
UnixNewPipe(&c->pipe_read, &c->pipe_write);
c->pipe_special_read2 = c->pipe_special_read3 = -1;
return c;
}
|
/* Creating a new cancel object*/
|
Creating a new cancel object
|
UnixSetSockEvent
|
void UnixSetSockEvent(SOCK_EVENT *event)
{
// Validate arguments
if (event == NULL)
{
return;
}
if (event->current_pipe_data <= 100)
{
UnixWritePipe(event->pipe_write);
event->current_pipe_data++;
}
}
|
/* Set the socket event*/
|
Set the socket event
|
safe_fd_set
|
int safe_fd_set(int fd, fd_set* fds, int* max_fd) {
FD_SET(fd, fds);
if (fd > *max_fd) {
*max_fd = fd;
}
return 0;
}
|
/* This is a helper function for select()*/
|
This is a helper function for select()
|
UnixCleanupSockEvent
|
void UnixCleanupSockEvent(SOCK_EVENT *event)
{
UINT i;
// Validate arguments
if (event == NULL)
{
return;
}
for (i = 0;i < LIST_NUM(event->SockList);i++)
{
SOCK *s = LIST_DATA(event->SockList, i);
ReleaseSock(s);
}
ReleaseList(event->SockList);
UnixDeletePipe(event->pipe_read, event->pipe_write);
Free(event);
}
|
/* Clean-up of the socket event*/
|
Clean-up of the socket event
|
UnixNewSockEvent
|
SOCK_EVENT *UnixNewSockEvent()
{
SOCK_EVENT *e = ZeroMallocFast(sizeof(SOCK_EVENT));
e->SockList = NewList(NULL);
e->ref = NewRef();
UnixNewPipe(&e->pipe_read, &e->pipe_write);
return e;
}
|
/* Create a socket event*/
|
Create a socket event
|
UnixDeletePipe
|
void UnixDeletePipe(int p1, int p2)
{
if (p1 != -1)
{
close(p1);
}
if (p2 != -1)
{
close(p2);
}
}
|
/* Close the pipe*/
|
Close the pipe
|
UnixWritePipe
|
void UnixWritePipe(int pipe_write)
{
char c = 1;
write(pipe_write, &c, 1);
}
|
/* Write to the pipe*/
|
Write to the pipe
|
UnixNewPipe
|
void UnixNewPipe(int *pipe_read, int *pipe_write)
{
int fd[2];
// Validate arguments
if (pipe_read == NULL || pipe_write == NULL)
{
return;
}
fd[0] = fd[1] = 0;
pipe(fd);
*pipe_read = fd[0];
*pipe_write = fd[1];
UnixSetSocketNonBlockingMode(*pipe_write, true);
UnixSetSocketNonBlockingMode(*pipe_read, true);
}
|
/* Create a new pipe*/
|
Create a new pipe
|
UnixInitSocketLibrary
|
void UnixInitSocketLibrary()
{
// Do not do anything special
}
|
/* Initializing the socket library*/
|
Initializing the socket library
|
UnixFreeSocketLibrary
|
void UnixFreeSocketLibrary()
{
// Do not do anything special
}
|
/* Release of the socket library*/
|
Release of the socket library
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.