function_name
stringlengths
1
80
function
stringlengths
14
10.6k
comment
stringlengths
12
8.02k
normalized_comment
stringlengths
6
6.55k
FreeDnsCache
void FreeDnsCache() { LockDnsCache(); { DNSCACHE *c; UINT i; for (i = 0;i < LIST_NUM(DnsCache);i++) { // Release the memory for the entry c = LIST_DATA(DnsCache, i); Free(c->HostName); Free(c); } } UnlockDnsCache(); // Release the list ReleaseList(DnsCache); DnsCache = NULL; }
/* Release of the DNS cache*/
Release of the DNS cache
LockDnsCache
void LockDnsCache() { LockList(DnsCache); }
/* Lock the DNS cache*/
Lock the DNS cache
UnlockDnsCache
void UnlockDnsCache() { UnlockList(DnsCache); }
/* Unlock the DNS cache*/
Unlock the DNS cache
TmpDhCallback
DH *TmpDhCallback(SSL *ssl, int is_export, int keylength) { DH *ret = NULL; if (dh_param != NULL) { ret = dh_param->dh; } return ret; }
/* DH temp key callback*/
DH temp key callback
NewSSLCtx
struct ssl_ctx_st *NewSSLCtx(bool server_mode) { struct ssl_ctx_st *ctx = SSL_CTX_new(SSLv23_method()); #ifdef SSL_OP_NO_TICKET SSL_CTX_set_options(ctx, SSL_OP_NO_TICKET); #endif // SSL_OP_NO_TICKET #ifdef SSL_OP_CIPHER_SERVER_PREFERENCE if (server_mode) { SSL_CTX_set_options(ctx, SSL_OP_CIPHER_SERVER_PREFERENCE); } #endif // SSL_OP_CIPHER_SERVER_PREFERENCE SSL_CTX_set_tmp_dh_callback(ctx, TmpDhCallback); #ifdef SSL_CTX_set_ecdh_auto SSL_CTX_set_ecdh_auto(ctx, 1); #endif // SSL_CTX_set_ecdh_auto return ctx; }
/* Create the SSL_CTX*/
Create the SSL_CTX
FreeSSLCtx
void FreeSSLCtx(struct ssl_ctx_st *ctx) { // Validate arguments if (ctx == NULL) { return; } SSL_CTX_free(ctx); }
/* Release of the SSL_CTX*/
Release of the SSL_CTX
SetGetIpThreadMaxNum
void SetGetIpThreadMaxNum(UINT num) { max_getip_thread = num; }
/* The number of get ip threads*/
The number of get ip threads
EnableNetworkNameCache
void EnableNetworkNameCache() { disable_cache = false; }
/* Enable the network name cache*/
Enable the network name cache
DisableNetworkNameCache
void DisableNetworkNameCache() { disable_cache = true; }
/* Disable the network name cache*/
Disable the network name cache
IsNetworkNameCacheEnabled
bool IsNetworkNameCacheEnabled() { return !disable_cache; }
/* Get whether the network name cache is enabled*/
Get whether the network name cache is enabled
GetNumTcpConnectionsCounter
COUNTER *GetNumTcpConnectionsCounter() { return num_tcp_connections; }
/* Get the TCP connections counter*/
Get the TCP connections counter
GetCurrentGlobalIP
bool GetCurrentGlobalIP(IP *ip, bool ipv6) { bool ret = false; // Validate arguments if (ip == NULL) { return false; } Zero(ip, sizeof(IP)); Lock(current_global_ip_lock); { if (ipv6 == false) { Copy(ip, &current_glocal_ipv4, sizeof(IP)); } else { Copy(ip, &current_glocal_ipv6, sizeof(IP)); } ret = current_global_ip_set; } Unlock(current_global_ip_lock); return ret; }
/* Get the current global IP address*/
Get the current global IP address
IsIPMyHost
bool IsIPMyHost(IP *ip) { LIST *o; UINT i; bool ret = false; // Validate arguments if (ip == NULL) { return false; } if (IsZeroIp(ip)) { return false; } // Search to check whether it matches to any of the IP of the local host o = GetHostIPAddressList(); for (i = 0;i < LIST_NUM(o);i++) { IP *p = LIST_DATA(o, i); if (CmpIpAddr(p, ip) == 0) { // Matched ret = true; break; } } FreeHostIPAddressList(o); if (ret == false) { if (IsLocalHostIP(ip)) { // localhost IP addresses ret = true; } } return ret; }
/* Check whether the specified IP address is assigned to the local host*/
Check whether the specified IP address is assigned to the local host
IsOnPrivateIPFile
bool IsOnPrivateIPFile(UINT ip) { bool ret = false; if (g_private_ip_list != NULL) { LIST *o = g_private_ip_list; UINT i; for (i = 0;i < LIST_NUM(o);i++) { PRIVATE_IP_SUBNET *p = LIST_DATA(o, i); if ((ip & p->Mask) == p->Ip2) { ret = true; } } } return ret; }
/* Examine whether the specified IP address is in the private IP file*/
Examine whether the specified IP address is in the private IP file
FreePrivateIPFile
void FreePrivateIPFile() { if (g_private_ip_list != NULL) { LIST *o = g_private_ip_list; UINT i; g_private_ip_list = NULL; for (i = 0;i < LIST_NUM(o);i++) { PRIVATE_IP_SUBNET *p = LIST_DATA(o, i); Free(p); } ReleaseList(o); } g_use_privateip_file = false; }
/* Free the private IP file*/
Free the private IP file
IsIPAddressInSameLocalNetwork
bool IsIPAddressInSameLocalNetwork(IP *a) { bool ret = false; LIST *o; UINT i; // Validate arguments if (a == NULL) { return false; } o = GetHostIPAddressList(); if (o != NULL) { for (i = 0;i < LIST_NUM(o);i++) { IP *p = LIST_DATA(o, i); if (IsIP4(p)) { if (IsZeroIp(p) == false && p->addr[0] != 127) { if (IsInSameNetwork4Standard(p, a)) { ret = true; break; } } } } FreeHostIPAddressList(o); } return ret; }
/* Check whether the specified IP address is in the same network to this computer*/
Check whether the specified IP address is in the same network to this computer
SetCurrentGlobalIP
void SetCurrentGlobalIP(IP *ip, bool ipv6) { // Validate arguments if (ip == NULL) { return; } if (IsZeroIp(ip)) { return; } Lock(current_global_ip_lock); { if (ipv6 == false) { Copy(&current_glocal_ipv4, ip, sizeof(IP)); } else { Copy(&current_glocal_ipv6, ip, sizeof(IP)); } current_global_ip_set = true; } Unlock(current_global_ip_lock); }
/* Record the current global IP address*/
Record the current global IP address
StopSockList
void StopSockList(SOCKLIST *sl) { SOCK **ss; UINT num, i; // Validate arguments if (sl == NULL) { return; } LockList(sl->SockList); { num = LIST_NUM(sl->SockList); ss = ToArray(sl->SockList); DeleteAll(sl->SockList); } UnlockList(sl->SockList); for (i = 0;i < num;i++) { SOCK *s = ss[i]; Disconnect(s); ReleaseSock(s); } Free(ss); }
/* Stop all the sockets in the list and delete it*/
Stop all the sockets in the list and delete it
FreeSockList
void FreeSockList(SOCKLIST *sl) { // Validate arguments if (sl == NULL) { return; } StopSockList(sl); ReleaseList(sl->SockList); Free(sl); }
/* Delete the socket list*/
Delete the socket list
NewSockList
SOCKLIST *NewSockList() { SOCKLIST *sl = ZeroMallocFast(sizeof(SOCKLIST)); sl->SockList = NewList(NULL); return sl; }
/* Creating a socket list*/
Creating a socket list
SocketTimeoutThread
void SocketTimeoutThread(THREAD *t, void *param) { SOCKET_TIMEOUT_PARAM *ttparam; ttparam = (SOCKET_TIMEOUT_PARAM *)param; // Wait for time-out period Select(NULL, ttparam->sock->TimeOut, ttparam->cancel, NULL); // Disconnect if it is blocked if(! ttparam->unblocked) { // Debug("Socket timeouted\n"); closesocket(ttparam->sock->socket); } else { // Debug("Socket timeout cancelled\n"); } }
/* Time-out thread of the socket on Solaris*/
Time-out thread of the socket on Solaris
NewSocketTimeout
SOCKET_TIMEOUT_PARAM *NewSocketTimeout(SOCK *sock) { SOCKET_TIMEOUT_PARAM *ttp; if(! sock->AsyncMode && sock->TimeOut != TIMEOUT_INFINITE) { // Debug("NewSockTimeout(%u)\n",sock->TimeOut); ttp = (SOCKET_TIMEOUT_PARAM*)Malloc(sizeof(SOCKET_TIMEOUT_PARAM)); // Set the parameters of the time-out thread ttp->cancel = NewCancel(); ttp->sock = sock; ttp->unblocked = false; ttp->thread = NewThread(SocketTimeoutThread, ttp); return ttp; } return NULL; }
/* Initialize and start the thread for time-out*/
Initialize and start the thread for time-out
FreeSocketTimeout
void FreeSocketTimeout(SOCKET_TIMEOUT_PARAM *ttp) { if(ttp == NULL) { return; } ttp->unblocked = true; Cancel(ttp->cancel); WaitThread(ttp->thread, INFINITE); ReleaseCancel(ttp->cancel); ReleaseThread(ttp->thread); Free(ttp); // Debug("FreeSocketTimeout succeed\n"); return; }
/* Stop and free the thread for timeout*/
Stop and free the thread for timeout
ParseIpAndSubnetMask46
bool ParseIpAndSubnetMask46(char *src, IP *ip, IP *mask) { // Validate arguments if (src == NULL || ip == NULL || mask == NULL) { return false; } if (ParseIpAndMask46(src, ip, mask) == false) { return false; } if (IsIP4(ip)) { return IsSubnetMask4(mask); } else { return IsSubnetMask6(mask); } }
/* Parse the IP address and subnet mask*/
Parse the IP address and subnet mask
IsIpStr4
bool IsIpStr4(char *str) { // Validate arguments if (str == NULL) { return false; } if (StrToIP32(str) == 0 && StrCmpi(str, "0.0.0.0") != 0) { return false; } return true; }
/* Check whether the specification of the IPv4 address is correct*/
Check whether the specification of the IPv4 address is correct
IsIpStr6
bool IsIpStr6(char *str) { IP ip; // Validate arguments if (str == NULL) { return false; } if (StrToIP6(&ip, str) == false) { return false; } return true; }
/* Check whether the specification of the IPv6 address is correct*/
Check whether the specification of the IPv6 address is correct
StrToMask6
bool StrToMask6(IP *mask, char *str) { // Validate arguments if (mask == NULL || str == NULL) { return false; } if (str[0] == '/') { str++; } if (IsNum(str)) { UINT n = ToInt(str); if (n <= 128) { IntToSubnetMask6(mask, n); return true; } else { return false; } } else { if (StrToIP(mask, str) == false) { return false; } else { return IsIP6(mask); } } }
/* Convert the string to an IPv6 mask*/
Convert the string to an IPv6 mask
MaskToStr
void MaskToStr(char *str, UINT size, IP *mask) { MaskToStrEx(str, size, mask, false); }
/* Convert the IPv4 / IPv6 mask to a string*/
Convert the IPv4 / IPv6 mask to a string
TubeDisconnect
void TubeDisconnect(TUBE *t) { // Validate arguments if (t == NULL) { return; } if (t->TubePairData == NULL) { return; } Lock(t->TubePairData->Lock); { t->TubePairData->IsDisconnected = true; Set(t->TubePairData->Event1); Set(t->TubePairData->Event2); SetSockEvent(t->TubePairData->SockEvent1); SetSockEvent(t->TubePairData->SockEvent2); } Unlock(t->TubePairData->Lock); }
/* Disconnecting of the tube*/
Disconnecting of the tube
NewTubePairData
TUBEPAIR_DATA *NewTubePairData() { TUBEPAIR_DATA *d = ZeroMalloc(sizeof(TUBEPAIR_DATA)); d->Ref = NewRef(); d->Lock = NewLock(); return d; }
/* Creating a tube pair data*/
Creating a tube pair data
ReleaseTubePairData
void ReleaseTubePairData(TUBEPAIR_DATA *d) { // Validate arguments if (d == NULL) { return; } if (Release(d->Ref) == 0) { CleanupTubePairData(d); } }
/* Release of the tube pair data*/
Release of the tube pair data
IsTubeConnected
bool IsTubeConnected(TUBE *t) { // Validate arguments if (t == NULL) { return false; } if (t->TubePairData == NULL) { return true; } if (t->TubePairData->IsDisconnected) { return false; } return true; }
/* Check whether the tube is connected to the opponent still*/
Check whether the tube is connected to the opponent still
TubeSend
bool TubeSend(TUBE *t, void *data, UINT size, void *header) { return TubeSendEx(t, data, size, header, false); }
/* Send the data to the tube*/
Send the data to the tube
TubeFlush
void TubeFlush(TUBE *t) { TubeFlushEx(t, false); }
/* Flush the tube*/
Flush the tube
TubeRecvAsync
TUBEDATA *TubeRecvAsync(TUBE *t) { TUBEDATA *d; // Validate arguments if (t == NULL) { return NULL; } if (IsTubeConnected(t) == false) { return NULL; } LockQueue(t->Queue); { d = GetNext(t->Queue); } UnlockQueue(t->Queue); return d; }
/* Receive the data from the tube (asynchronous)*/
Receive the data from the tube (asynchronous)
GetTubeSockEvent
SOCK_EVENT *GetTubeSockEvent(TUBE *t) { SOCK_EVENT *e = NULL; // Validate arguments if (t == NULL) { return NULL; } Lock(t->Lock); { if (t->SockEvent != NULL) { AddRef(t->SockEvent->ref); e = t->SockEvent; } } Unlock(t->Lock); return e; }
/* Get the SockEvent associated with the tube*/
Get the SockEvent associated with the tube
NewTube
TUBE *NewTube(UINT size_of_header) { TUBE *t = ZeroMalloc(sizeof(TUBE)); t->Event = NewEvent(); t->Queue = NewQueue(); t->Ref = NewRef(); t->Lock = NewLock(); t->SockEvent = NewSockEvent(); t->SizeOfHeader = size_of_header; return t; }
/* Creating a tube*/
Creating a tube
ReleaseTube
void ReleaseTube(TUBE *t) { // Validate arguments if (t == NULL) { return; } if (Release(t->Ref) == 0) { CleanupTube(t); } }
/* Release of the tube*/
Release of the tube
NewTubeData
TUBEDATA *NewTubeData(void *data, UINT size, void *header, UINT header_size) { TUBEDATA *d; // Validate arguments if (size == 0 || data == NULL) { return NULL; } d = ZeroMalloc(sizeof(TUBEDATA)); d->Data = Clone(data, size); d->DataSize = size; if (header != NULL) { d->Header = Clone(header, header_size); d->HeaderSize = header_size; } else { d->Header = ZeroMalloc(header_size); } return d; }
/* Creating a tube data*/
Creating a tube data
FreeTubeData
void FreeTubeData(TUBEDATA *d) { // Validate arguments if (d == NULL) { return; } Free(d->Data); Free(d->Header); Free(d); }
/* Release of the tube data*/
Release of the tube data
FreeHostIPAddressList
void FreeHostIPAddressList(LIST *o) { UINT i; // Validate arguments if (o == NULL) { return; } for (i = 0;i < LIST_NUM(o);i++) { IP *ip = LIST_DATA(o, i); Free(ip); } ReleaseList(o); }
/* Release of the IP address list of the host*/
Release of the IP address list of the host
IsMyIPAddress
bool IsMyIPAddress(IP *ip) { LIST *o; UINT i; bool ret = false; // Validate arguments if (ip == NULL) { return false; } o = GetHostIPAddressList(); for (i = 0;i < LIST_NUM(o);i++) { IP *a = LIST_DATA(o, i); if (CmpIpAddr(ip, a) == 0) { ret = true; break; } } FreeHostIPAddressList(o); return ret; }
/* Get whether the specified IP address is held by this host*/
Get whether the specified IP address is held by this host
AddHostIPAddressToList
void AddHostIPAddressToList(LIST *o, IP *ip) { IP *r; // Validate arguments if (o == NULL || ip == NULL) { return; } r = Search(o, ip); if (r != NULL) { return; } Insert(o, Clone(ip, sizeof(IP))); }
/* Add the IP address to the list*/
Add the IP address to the list
CloneIPAddressList
LIST *CloneIPAddressList(LIST *o) { LIST *ret; UINT i; // Validate arguments if (o == NULL) { return NULL; } ret = NewListFast(CmpIpAddressList); for (i = 0;i < LIST_NUM(o);i++) { IP *ip = LIST_DATA(o, i); if (ip != NULL) { ip = Clone(ip, sizeof(IP)); Add(ret, ip); } } return ret; }
/* Copy of the IP address list*/
Copy of the IP address list
NewQueryIpThread
QUERYIPTHREAD *NewQueryIpThread(char *hostname, UINT interval_last_ok, UINT interval_last_ng) { QUERYIPTHREAD *t; t = ZeroMalloc(sizeof(QUERYIPTHREAD)); t->HaltEvent = NewEvent(); t->Lock = NewLock(); StrCpy(t->Hostname, sizeof(t->Hostname), hostname); t->IntervalLastOk = interval_last_ok; t->IntervalLastNg = interval_last_ng; t->Thread = NewThread(QueryIpThreadMain, t); return t; }
/* Creating an IP address acquisition thread*/
Creating an IP address acquisition thread
GetQueryIpThreadResult
bool GetQueryIpThreadResult(QUERYIPTHREAD *t, IP *ip) { bool ret = false; Zero(ip, sizeof(IP)); // Validate arguments if (t == NULL || ip == NULL) { return false; } Lock(t->Lock); if (IsZero(&t->Ip, sizeof(IP))) { ret = false; } else { Copy(ip, &t->Ip, sizeof(IP)); } Unlock(t->Lock); return ret; }
/* Get the results of the IP address acquisition thread*/
Get the results of the IP address acquisition thread
FreeQueryIpThread
void FreeQueryIpThread(QUERYIPTHREAD *t) { // Validate arguments if (t == NULL) { return; } t->Halt = true; Set(t->HaltEvent); WaitThread(t->Thread, INFINITE); ReleaseThread(t->Thread); ReleaseEvent(t->HaltEvent); DeleteLock(t->Lock); Free(t); }
/* Release of the IP address acquisition thread*/
Release of the IP address acquisition thread
FreeUdpPacket
void FreeUdpPacket(UDPPACKET *p) { // Validate arguments if (p == NULL) { return; } Free(p->Data); Free(p); }
/* Release of the UDP packet*/
Release of the UDP packet
NewUdpPacket
UDPPACKET *NewUdpPacket(IP *src_ip, UINT src_port, IP *dst_ip, UINT dst_port, void *data, UINT size) { UDPPACKET *p; // Validate arguments if (data == NULL || size == 0 || dst_ip == NULL || dst_port == 0) { return NULL; } p = ZeroMalloc(sizeof(UDPPACKET)); p->Data = data; p->Size = size; Copy(&p->SrcIP, src_ip, sizeof(IP)); p->SrcPort = src_port; Copy(&p->DstIP, dst_ip, sizeof(IP)); p->DestPort = dst_port; return p; }
/* Create a new UDP packet*/
Create a new UDP packet
UdpListenerSendPackets
void UdpListenerSendPackets(UDPLISTENER *u, LIST *packet_list) { UINT num = 0; // Validate arguments if (u == NULL || packet_list == NULL) { return; } LockList(u->SendPacketList); { UINT i; num = LIST_NUM(packet_list); for (i = 0;i < LIST_NUM(packet_list);i++) { UDPPACKET *p = LIST_DATA(packet_list, i); Add(u->SendPacketList, p); } } UnlockList(u->SendPacketList); if (num >= 1) { SetSockEvent(u->Event); } }
/* Transmit the packets via UDP Listener*/
Transmit the packets via UDP Listener
NewUdpListener
UDPLISTENER *NewUdpListener(UDPLISTENER_RECV_PROC *recv_proc, void *param, IP *listen_ip) { return NewUdpListenerEx(recv_proc, param, listen_ip, INFINITE); }
/* Creating a UDP listener*/
Creating a UDP listener
FreeUdpListener
void FreeUdpListener(UDPLISTENER *u) { UINT i; // Validate arguments if (u == NULL) { return; } u->Halt = true; SetSockEvent(u->Event); WaitThread(u->Thread, INFINITE); ReleaseThread(u->Thread); ReleaseSockEvent(u->Event); ReleaseIntList(u->PortList); for (i = 0;i < LIST_NUM(u->SendPacketList);i++) { UDPPACKET *p = LIST_DATA(u->SendPacketList, i); FreeUdpPacket(p); } ReleaseList(u->SendPacketList); FreeInterruptManager(u->Interrupts); Free(u); }
/* Release the UDP listener*/
Release the UDP listener
AddPortToUdpListener
void AddPortToUdpListener(UDPLISTENER *u, UINT port) { // Validate arguments if (u == NULL || port == 0) { return; } LockList(u->PortList); { AddIntDistinct(u->PortList, port); } UnlockList(u->PortList); SetSockEvent(u->Event); }
/* Add the UDP port*/
Add the UDP port
DeletePortFromUdpListener
void DeletePortFromUdpListener(UDPLISTENER *u, UINT port) { // Validate arguments if (u == NULL || port == 0) { return; } LockList(u->PortList); { DelInt(u->PortList, port); } UnlockList(u->PortList); SetSockEvent(u->Event); }
/* Delete the UDP port*/
Delete the UDP port
CmpInterruptManagerTickList
int CmpInterruptManagerTickList(void *p1, void *p2) { UINT64 *v1, *v2; if (p1 == NULL || p2 == NULL) { return 0; } v1 = *(UINT64 **)p1; v2 = *(UINT64 **)p2; if (v1 == NULL || v2 == NULL) { return 0; } if (*v1 > *v2) { return 1; } else if (*v1 < *v2) { return -1; } else { return 0; } }
/* Sort function of the interrupt management list*/
Sort function of the interrupt management list
NewInterruptManager
INTERRUPT_MANAGER *NewInterruptManager() { INTERRUPT_MANAGER *m = ZeroMalloc(sizeof(INTERRUPT_MANAGER)); m->TickList = NewList(CmpInterruptManagerTickList); return m; }
/* Initialization of the interrupt management*/
Initialization of the interrupt management
FreeInterruptManager
void FreeInterruptManager(INTERRUPT_MANAGER *m) { UINT i; // Validate arguments if (m == NULL) { return; } for (i = 0;i < LIST_NUM(m->TickList);i++) { UINT64 *v = LIST_DATA(m->TickList, i); Free(v); } ReleaseList(m->TickList); Free(m); }
/* Release of the interrupt management*/
Release of the interrupt management
AddInterrupt
void AddInterrupt(INTERRUPT_MANAGER *m, UINT64 tick) { // Validate arguments if (tick == 0) { return; } LockList(m->TickList); { if (Search(m->TickList, &tick) == NULL) { Insert(m->TickList, Clone(&tick, sizeof(UINT64))); } } UnlockList(m->TickList); }
/* Add a number to the interrupt management*/
Add a number to the interrupt management
ListenReverse
SOCK *ListenReverse() { SOCK *s = NewSock(); s->Type = SOCK_REVERSE_LISTEN; s->ListenMode = true; s->ReverseAcceptQueue = NewQueue(); s->ReverseAcceptEvent = NewEvent(); s->Connected = true; return s; }
/* Create a listening socket for the reverse socket*/
Create a listening socket for the reverse socket
ListenInProc
SOCK *ListenInProc() { SOCK *s = NewSock(); s->Type = SOCK_INPROC; s->ListenMode = true; s->InProcAcceptQueue = NewQueue(); s->InProcAcceptEvent = NewEvent(); s->Connected = true; return s; }
/* Start listening on the in-process socket*/
Start listening on the in-process socket
NewInProcSocket
SOCK *NewInProcSocket(TUBE *tube_send, TUBE *tube_recv) { SOCK *s; // Validate arguments if (tube_recv == NULL || tube_send == NULL) { return NULL; } s = NewSock(); s->Type = SOCK_INPROC; s->SendTube = tube_send; s->RecvTube = tube_recv; AddRef(tube_send->Ref); AddRef(tube_recv->Ref); s->InProcRecvFifo = NewFifo(); s->Connected = true; return s; }
/* Creating a new in-process socket*/
Creating a new in-process socket
SendInProc
UINT SendInProc(SOCK *sock, void *data, UINT size) { if (sock == NULL || sock->Type != SOCK_INPROC || sock->Disconnecting || sock->Connected == false) { return 0; } if (IsTubeConnected(sock->SendTube) == false) { return 0; } if (TubeSend(sock->SendTube, data, size, NULL) == false) { return 0; } return size; }
/* Transmission process for the in-process socket*/
Transmission process for the in-process socket
WaitForTubes
void WaitForTubes(TUBE **tubes, UINT num, UINT timeout) { // Validate arguments if (num != 0 && tubes == NULL) { return; } if (timeout == 0) { return; } if (num == 0) { SleepThread(timeout); return; } #ifdef OS_WIN32 Win32WaitForTubes(tubes, num, timeout); #else // OS_WIN32 UnixWaitForTubes(tubes, num, timeout); #endif // OS_WIN32 }
/* Wait for the arrival of data on multiple tubes*/
Wait for the arrival of data on multiple tubes
NewTubeFlushList
TUBE_FLUSH_LIST *NewTubeFlushList() { TUBE_FLUSH_LIST *f = ZeroMalloc(sizeof(TUBE_FLUSH_LIST)); f->List = NewListFast(NULL); return f; }
/* Creating a Tube Flush List*/
Creating a Tube Flush List
FreeTubeFlushList
void FreeTubeFlushList(TUBE_FLUSH_LIST *f) { UINT i; // Validate arguments if (f == NULL) { return; } for (i = 0;i < LIST_NUM(f->List);i++) { TUBE *t = LIST_DATA(f->List, i); ReleaseTube(t); } ReleaseList(f->List); Free(f); }
/* Release of the Tube Flush List*/
Release of the Tube Flush List
AddTubeToFlushList
void AddTubeToFlushList(TUBE_FLUSH_LIST *f, TUBE *t) { // Validate arguments if (f == NULL || t == NULL) { return; } if (t->IsInFlushList) { return; } if (IsInList(f->List, t) == false) { Add(f->List, t); AddRef(t->Ref); t->IsInFlushList = true; } }
/* Add a Tube to the Tube Flush List*/
Add a Tube to the Tube Flush List
FlushTubeFlushList
void FlushTubeFlushList(TUBE_FLUSH_LIST *f) { UINT i; // Validate arguments if (f == NULL) { return; } for (i = 0;i < LIST_NUM(f->List);i++) { TUBE *t = LIST_DATA(f->List, i); TubeFlush(t); t->IsInFlushList = false; ReleaseTube(t); } DeleteAll(f->List); }
/* Flush the all tubes in the Tube Flush List*/
Flush the all tubes in the Tube Flush List
PackError
PACK *PackError(UINT error) { PACK *p; p = NewPack(); PackAddInt(p, "error", error); return p; }
/* Store the error value into PACK*/
Store the error value into PACK
GetErrorFromPack
UINT GetErrorFromPack(PACK *p) { // Validate arguments if (p == NULL) { return 0; } return PackGetInt(p, "error"); }
/* Get the error value from PACK*/
Get the error value from PACK
CreateDummyValue
void CreateDummyValue(PACK *p) { UINT size; UCHAR *buf; // Validate arguments if (p == NULL) { return; } size = Rand32() % HTTP_PACK_RAND_SIZE_MAX; buf = Malloc(size); Rand(buf, size); PackAddData(p, "pencore", buf, size); Free(buf); }
/* Create an entry to PACK for the dummy*/
Create an entry to PACK for the dummy
SendPack
bool SendPack(SOCK *s, PACK *p) { BUF *b; UINT sz; // Validate arguments if (s == NULL || p == NULL || s->Type != SOCK_TCP) { return false; } b = PackToBuf(p); sz = Endian32(b->Size); SendAdd(s, &sz, sizeof(UINT)); SendAdd(s, b->Buf, b->Size); FreeBuf(b); return SendNow(s, s->SecureMode); }
/* Send a PACK*/
Send a PACK
SendPackWithHash
bool SendPackWithHash(SOCK *s, PACK *p) { BUF *b; UINT sz; UCHAR hash[SHA1_SIZE]; // Validate arguments if (s == NULL || p == NULL || s->Type != SOCK_TCP) { return false; } b = PackToBuf(p); sz = Endian32(b->Size); SendAdd(s, &sz, sizeof(UINT)); SendAdd(s, b->Buf, b->Size); Sha1(hash, b->Buf, b->Size); SendAdd(s, hash, sizeof(hash)); FreeBuf(b); return SendNow(s, s->SecureMode); }
/* Send a Pack (with adding a hash)*/
Send a Pack (with adding a hash)
TickHighres64
UINT64 TickHighres64() { #ifdef OS_WIN32 return (UINT64)(MsGetHiResTimeSpan(MsGetHiResCounter()) * 1000.0f); #else // OS_WIN32 return Tick64(); #endif // OS_WIN32 }
/* Get the high-resolution time*/
Get the high-resolution time
Tick64ToTime64
UINT64 Tick64ToTime64(UINT64 tick) { UINT64 ret = 0; if (tick == 0) { return 0; } LockList(tk64->AdjustTime); { INT i; for (i = ((INT)LIST_NUM(tk64->AdjustTime) - 1); i >= 0; i--) { ADJUST_TIME *t = LIST_DATA(tk64->AdjustTime, i); if (t->Tick <= tick) { ret = t->Time + (tick - t->Tick); break; } } } UnlockList(tk64->AdjustTime); if (ret == 0) { ret++; } return ret; }
/* Convert the Tick value to time*/
Convert the Tick value to time
TickToTime
UINT64 TickToTime(UINT64 tick) { return Tick64ToTime64(tick); }
/* Convert the Tick value to time*/
Convert the Tick value to time
Tick64
UINT64 Tick64() { #ifdef OS_WIN32 return Win32FastTick64(); #else // OS_WIN32 UINT64 tick64; if (tk64 == NULL) { return 0; } Lock(tk64->TickLock); { tick64 = tk64->Tick; } Unlock(tk64->TickLock); return tick64; #endif // OS_WIN32 }
/* Get the Tick value*/
Get the Tick value
Diff64
UINT64 Diff64(UINT64 a, UINT64 b) { if (a > b) { return a - b; } else { return b - a; } }
/* Get the absolute value of the difference between the two 64 bit integers*/
Get the absolute value of the difference between the two 64 bit integers
InitTick64
void InitTick64() { if (tk64 != NULL) { // Already initialized return; } halt_tick_event = NewEvent(); // Initialize the structure tk64 = ZeroMalloc(sizeof(TICK64)); tk64->TickLock = NewLock(); tk64->AdjustTime = NewList(NULL); // Creating a thread tk64->Thread = NewThread(Tick64Thread, NULL); WaitThreadInit(tk64->Thread); }
/* Initialization of the Tick64*/
Initialization of the Tick64
FreeTick64
void FreeTick64() { UINT i; if (tk64 == NULL) { // Uninitialized return; } // Termination process tk64->Halt = true; Set(halt_tick_event); WaitThread(tk64->Thread, INFINITE); ReleaseThread(tk64->Thread); // Releasing process for (i = 0;i < LIST_NUM(tk64->AdjustTime);i++) { ADJUST_TIME *t = LIST_DATA(tk64->AdjustTime, i); Free(t); } ReleaseList(tk64->AdjustTime); DeleteLock(tk64->TickLock); Free(tk64); tk64 = NULL; ReleaseEvent(halt_tick_event); halt_tick_event = NULL; }
/* Release of the Tick64*/
Release of the Tick64
Win32GetDispatchTable
OS_DISPATCH_TABLE *Win32GetDispatchTable() { static OS_DISPATCH_TABLE t = { Win32Init, Win32Free, Win32MemoryAlloc, Win32MemoryReAlloc, Win32MemoryFree, Win32GetTick, Win32GetSystemTime, Win32Inc32, Win32Dec32, Win32Sleep, Win32NewLock, Win32Lock, Win32Unlock, Win32DeleteLock, Win32InitEvent, Win32SetEvent, Win32ResetEvent, Win32WaitEvent, Win32FreeEvent, Win32WaitThread, Win32FreeThread, Win32InitThread, Win32ThreadId, Win32FileOpen, Win32FileOpenW, Win32FileCreate, Win32FileCreateW, Win32FileWrite, Win32FileRead, Win32FileClose, Win32FileFlush, Win32FileSize, Win32FileSeek, Win32FileDelete, Win32FileDeleteW, Win32MakeDir, Win32MakeDirW, Win32DeleteDir, Win32DeleteDirW, Win32GetCallStack, Win32GetCallStackSymbolInfo, Win32FileRename, Win32FileRenameW, Win32Run, Win32RunW, Win32IsSupportedOs, Win32GetOsInfo, Win32Alert, Win32AlertW, Win32GetProductId, Win32SetHighPriority, Win32RestorePriority, Win32NewSingleInstance, Win32FreeSingleInstance, Win32GetMemInfo, Win32Yield, }; return &t; }
/* Create a dispatch table*/
Create a dispatch table
Win32SetThreadName
void Win32SetThreadName(UINT thread_id, char *name) { DWORD ms_vc_exception = 0x406D1388; THREADNAME_INFO t; // Validate arguments if (thread_id == 0 || name == NULL) { return; } Zero(&t, sizeof(t)); t.dwType = 0x1000; t.szName = name; t.dwThreadID = thread_id; t.dwFlags = 0; __try { RaiseException(ms_vc_exception, 0, sizeof(t) / sizeof(ULONG_PTR), (ULONG_PTR *)&t); } __except (EXCEPTION_EXECUTE_HANDLER) { } }
/* Set the thread name*/
Set the thread name
Win32InitNewThread
void Win32InitNewThread() { static HINSTANCE hDll = NULL; static bool (WINAPI *_SetThreadLocale)(LCID) = NULL; if (hDll == NULL) { hDll = LoadLibrary("kernel32.dll"); _SetThreadLocale = (bool (__stdcall *)(LCID)) GetProcAddress(hDll, "SetThreadLocale"); } if (_SetThreadLocale != NULL) { _SetThreadLocale(LOCALE_USER_DEFAULT); } }
/* Initialization function of the new thread*/
Initialization function of the new thread
Win32EnumDirEx
DIRLIST *Win32EnumDirEx(char *dirname, COMPARE *compare) { DIRLIST *ret; wchar_t *dirname_w = CopyStrToUni(dirname); ret = Win32EnumDirExW(dirname_w, compare); Free(dirname_w); return ret; }
/* Enumeration of directory*/
Enumeration of directory
Win32GetExeNameW
void Win32GetExeNameW(wchar_t *name, UINT size) { // Validate arguments if (name == NULL) { return; } if (IsNt() == false) { char name_a[MAX_PATH]; Win32GetExeName(name_a, sizeof(name_a)); StrToUni(name, size, name_a); return; } UniStrCpy(name, size, L""); GetModuleFileNameW(NULL, name, size); }
/* Get the EXE file name*/
Get the EXE file name
Win32GetCurrentDirW
void Win32GetCurrentDirW(wchar_t *dir, UINT size) { // Validate arguments if (dir == NULL) { return; } if (IsNt() == false) { char dir_a[MAX_PATH]; Win32GetCurrentDir(dir_a, sizeof(dir_a)); StrToUni(dir, size, dir_a); return; } GetCurrentDirectoryW(size, dir); }
/* Get the current directory*/
Get the current directory
Win32FreeSingleInstance
void Win32FreeSingleInstance(void *data) { WIN32MUTEX *m; // Validate arguments if (data == NULL) { return; } m = (WIN32MUTEX *)data; ReleaseMutex(m->hMutex); CloseHandle(m->hMutex); Win32MemoryFree(m); }
/* Release the single instance*/
Release the single instance
Win32SetHighPriority
void Win32SetHighPriority() { SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); }
/* Raise the priority*/
Raise the priority
Win32RestorePriority
void Win32RestorePriority() { SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS); }
/* Restore the priority*/
Restore the priority
Win32GetProductId
char* Win32GetProductId() { char *product_id; return CopyStr("--"); // Product ID product_id = MsRegReadStr(REG_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductId"); if (product_id == NULL) { product_id = MsRegReadStr(REG_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", "ProductId"); } return product_id; }
/* Get the node information*/
Get the node information
Win32IsSupportedOs
bool Win32IsSupportedOs() { if (Win32GetOsType() == 0) { Win32Alert( CEDAR_PRODUCT_STR " VPN doesn't support this Windows Operating System.\n" CEDAR_PRODUCT_STR " VPN requires " SUPPORTED_WINDOWS_LIST ".\n\n" "Please contact your system administrator.", NULL); return false; } return true; }
/* Acquisition whether the OS is currently supported*/
Acquisition whether the OS is currently supported
Win32AlertW
void Win32AlertW(wchar_t *msg, wchar_t *caption) { char *s; // Validate arguments if (msg == NULL) { msg = L"Alert"; } if (caption == NULL) { caption = CEDAR_PRODUCT_STR_W L" VPN Kernel"; } s = GetCommandLineStr(); if (SearchStr(s, "win9x_uninstall", 0) == INFINITE && SearchStr(s, "win9x_install", 0) == INFINITE) { // Hide during the uninstallation in Win9x service mode MessageBoxW(NULL, msg, caption, MB_SETFOREGROUND | MB_TOPMOST | MB_SERVICE_NOTIFICATION | MB_OK | MB_ICONEXCLAMATION); } Free(s); }
/* Show an alert*/
Show an alert
Win32GetNumberOfCpuInner
UINT Win32GetNumberOfCpuInner() { UINT ret = 0; SYSTEM_INFO info; Zero(&info, sizeof(info)); GetSystemInfo(&info); if (info.dwNumberOfProcessors >= 1 && info.dwNumberOfProcessors <= 128) { ret = info.dwNumberOfProcessors; } return ret; }
/* Get the number of CPUs*/
Get the number of CPUs
Win32GetVersionExInternal
bool Win32GetVersionExInternal(void *info) { OSVERSIONINFOA os; // Validate arguments if (info == NULL) { return false; } Zero(&os, sizeof(os)); os.dwOSVersionInfoSize = sizeof(os); if (GetVersionExA(&os)) { if (os.dwPlatformId == VER_PLATFORM_WIN32_NT) { if ((os.dwMajorVersion == 6 && os.dwMinorVersion >= 2) || (os.dwMajorVersion >= 7)) { // Windows 8 later return Win32GetVersionExInternalForWindows81orLater(info); } } } return GetVersionExA(info); }
/* GetVersionEx API (Ignore the tricky features that have been added to the Windows 8.2 or later)*/
GetVersionEx API (Ignore the tricky features that have been added to the Windows 8.2 or later)
Win32IsNt
bool Win32IsNt() { OSVERSIONINFO os; Zero(&os, sizeof(os)); os.dwOSVersionInfoSize = sizeof(os); if (GetVersionEx(&os) == FALSE) { // Failure? return false; } if (os.dwPlatformId == VER_PLATFORM_WIN32_NT) { // NT return true; } // 9x return false; }
/* Acquisition whether it's a Windows NT*/
Acquisition whether it's a Windows NT
Win32GetSpVer
UINT Win32GetSpVer(char *str) { UINT ret, i; TOKEN_LIST *t; // Validate arguments if (str == NULL) { return 0; } t = ParseToken(str, NULL); if (t == NULL) { return 0; } ret = 0; for (i = 0;i < t->NumTokens;i++) { ret = ToInt(t->Token[i]); if (ret != 0) { break; } } FreeToken(t); return ret; }
/* Get the SP version from the string*/
Get the SP version from the string
Win32TerminateProcess
bool Win32TerminateProcess(void *handle) { HANDLE h; // Validate arguments if (handle == NULL) { return false; } h = (HANDLE)handle; TerminateProcess(h, 0); return true; }
/* Kill the process*/
Kill the process
Win32CloseProcess
void Win32CloseProcess(void *handle) { // Validate arguments if (handle == NULL) { return; } CloseHandle((HANDLE)handle); }
/* Close the process*/
Close the process
Win32IsProcessAlive
bool Win32IsProcessAlive(void *handle) { HANDLE h; // Validate arguments if (handle == NULL) { return false; } h = (HANDLE)handle; if (WaitForSingleObject(h, 0) == WAIT_OBJECT_0) { return false; } return true; }
/* Check whether the specified process is alive*/
Check whether the specified process is alive
Win32WaitProcess
bool Win32WaitProcess(void *h, UINT timeout) { // Validate arguments if (h == NULL) { return false; } if (timeout == 0) { timeout = INFINITE; } if (WaitForSingleObject((HANDLE)h, timeout) == WAIT_TIMEOUT) { return false; } return true; }
/* Wait for the process termination*/
Wait for the process termination
Win32RunAndWaitProcess
bool Win32RunAndWaitProcess(wchar_t *filename, wchar_t *arg, bool hide, bool disableWow, UINT timeout) { UINT process_id = 0; void *p = Win32RunEx3W(filename, arg, hide, &process_id, disableWow); if (p == NULL) { return false; } return Win32WaitProcess(p, timeout); }
/* Run the process and wait for terminate it*/
Run the process and wait for terminate it