function_name
stringlengths 1
80
| function
stringlengths 14
10.6k
| comment
stringlengths 12
8.02k
| normalized_comment
stringlengths 6
6.55k
|
|---|---|---|---|
CompareIpAdapterIndexMap
|
int CompareIpAdapterIndexMap(void *p1, void *p2)
{
IP_ADAPTER_INDEX_MAP *a1, *a2;
if (p1 == NULL || p2 == NULL)
{
return 0;
}
a1 = *(IP_ADAPTER_INDEX_MAP **)p1;
a2 = *(IP_ADAPTER_INDEX_MAP **)p2;
if (a1 == NULL || a2 == NULL)
{
return 0;
}
if (a1->Index > a2->Index)
{
return 1;
}
else if (a1->Index < a2->Index)
{
return -1;
}
else
{
return 0;
}
}
|
/* Comparison of IP_ADAPTER_INDEX_MAP*/
|
Comparison of IP_ADAPTER_INDEX_MAP
|
Win32RenewAddressByGuid
|
bool Win32RenewAddressByGuid(char *guid)
{
IP_ADAPTER_INDEX_MAP a;
// Validate arguments
if (guid == NULL)
{
return false;
}
Zero(&a, sizeof(a));
if (Win32GetAdapterFromGuid(&a, guid) == false)
{
return false;
}
return Win32RenewAddress(&a);
}
|
/* Update the IP address of the adapter*/
|
Update the IP address of the adapter
|
Win32ReleaseAddress
|
bool Win32ReleaseAddress(void *a)
{
DWORD ret;
// Validate arguments
if (a == NULL)
{
return false;
}
if (w32net->IpReleaseAddress == NULL)
{
return false;
}
ret = w32net->IpReleaseAddress(a);
if (ret == NO_ERROR)
{
return true;
}
else
{
Debug("IpReleaseAddress: Error: %u\n", ret);
return false;
}
}
|
/* Release the IP address of the adapter*/
|
Release the IP address of the adapter
|
Win32FlushDnsCache
|
void Win32FlushDnsCache()
{
Run("ipconfig.exe", "/flushdns", true, false);
}
|
/* Clear the DNS cache on Win32*/
|
Clear the DNS cache on Win32
|
Win32UINTToIP
|
void Win32UINTToIP(IP *ip, UINT i)
{
UINTToIP(ip, i);
}
|
/* IP conversion function for Win32*/
|
IP conversion function for Win32
|
Win32IPToUINT
|
UINT Win32IPToUINT(IP *ip)
{
return IPToUINT(ip);
}
|
/* IP conversion function for Win32*/
|
IP conversion function for Win32
|
Win32DeleteRouteEntry
|
void Win32DeleteRouteEntry(ROUTE_ENTRY *e)
{
MIB_IPFORWARDROW *p;
// Validate arguments
if (e == NULL)
{
return;
}
p = ZeroMallocFast(sizeof(MIB_IPFORWARDROW));
Win32RouteEntryToIpForwardRow(p, e);
// Delete
w32net->DeleteIpForwardEntry(p);
Free(p);
}
|
/* Remove a routing entry from the routing table*/
|
Remove a routing entry from the routing table
|
Win32CompareRouteEntryByMetric
|
int Win32CompareRouteEntryByMetric(void *p1, void *p2)
{
ROUTE_ENTRY *e1, *e2;
// Validate arguments
if (p1 == NULL || p2 == NULL)
{
return 0;
}
e1 = *(ROUTE_ENTRY **)p1;
e2 = *(ROUTE_ENTRY **)p2;
if (e1 == NULL || e2 == NULL)
{
return 0;
}
if (e1->Metric > e2->Metric)
{
return 1;
}
else if (e1->Metric == e2->Metric)
{
return 0;
}
else
{
return -1;
}
}
|
/* Sort the routing entries by metric*/
|
Sort the routing entries by metric
|
Win32FreeSocketLibrary
|
void Win32FreeSocketLibrary()
{
if (w32net != NULL)
{
if (w32net->hIpHlpApi32 != NULL)
{
FreeLibrary(w32net->hIpHlpApi32);
}
if (w32net->hIcmp != NULL)
{
FreeLibrary(w32net->hIcmp);
}
Free(w32net);
w32net = NULL;
}
WSACleanup();
}
|
/* Release of the socket library*/
|
Release of the socket library
|
Win32CleanupCancel
|
void Win32CleanupCancel(CANCEL *c)
{
// Validate arguments
if (c == NULL)
{
return;
}
if (c->SpecialFlag == false)
{
CloseHandle(c->hEvent);
}
Free(c);
}
|
/* Cleanup of the cancel object*/
|
Cleanup of the cancel object
|
Win32NewCancel
|
CANCEL *Win32NewCancel()
{
CANCEL *c = ZeroMallocFast(sizeof(CANCEL));
c->ref = NewRef();
c->SpecialFlag = false;
c->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
return c;
}
|
/* New cancel object*/
|
New cancel object
|
Win32WaitSockEvent
|
bool Win32WaitSockEvent(SOCK_EVENT *event, UINT timeout)
{
// Validate arguments
if (event == NULL || timeout == 0)
{
return false;
}
if (WaitForSingleObject((HANDLE)event->hEvent, timeout) == WAIT_OBJECT_0)
{
return true;
}
else
{
return false;
}
}
|
/* Waiting for a socket event*/
|
Waiting for a socket event
|
Win32CleanupSockEvent
|
void Win32CleanupSockEvent(SOCK_EVENT *event)
{
// Validate arguments
if (event == NULL)
{
return;
}
CloseHandle((HANDLE)event->hEvent);
Free(event);
}
|
/* Clean-up of the socket event*/
|
Clean-up of the socket event
|
Win32SetSockEvent
|
void Win32SetSockEvent(SOCK_EVENT *event)
{
// Validate arguments
if (event == NULL)
{
return;
}
SetEvent((HANDLE)event->hEvent);
}
|
/* Set of the socket event*/
|
Set of the socket event
|
Win32NewSockEvent
|
SOCK_EVENT *Win32NewSockEvent()
{
SOCK_EVENT *e = ZeroMallocFast(sizeof(SOCK_EVENT));
e->ref = NewRef();
e->hEvent = (void *)CreateEvent(NULL, FALSE, FALSE, NULL);
return e;
}
|
/* Creating a socket event*/
|
Creating a socket event
|
Win32JoinSockToSockEvent
|
void Win32JoinSockToSockEvent(SOCK *sock, SOCK_EVENT *event)
{
HANDLE hEvent;
// Validate arguments
if (sock == NULL || event == NULL || sock->AsyncMode)
{
return;
}
if (sock->ListenMode != false || (sock->Type != SOCK_UDP && sock->Connected == false))
{
return;
}
sock->AsyncMode = true;
hEvent = event->hEvent;
// Association
WSAEventSelect(sock->socket, hEvent, FD_READ | FD_WRITE | FD_CLOSE);
// Increase the reference count of the SOCK_EVENT
AddRef(event->ref);
sock->SockEvent = event;
}
|
/* Associate the socket with socket event and set it to asynchronous mode*/
|
Associate the socket with socket event and set it to asynchronous mode
|
Win32FreeAsyncSocket
|
void Win32FreeAsyncSocket(SOCK *sock)
{
// Validate arguments
if (sock == NULL)
{
return;
}
// Asynchronous socket
if (sock->hEvent != NULL)
{
if (sock->Type != SOCK_INPROC)
{
CloseHandle((HANDLE)sock->hEvent);
}
}
sock->hEvent = NULL;
sock->AsyncMode = false;
// Socket event
if (sock->SockEvent != NULL)
{
ReleaseSockEvent(sock->SockEvent);
sock->SockEvent = NULL;
}
}
|
/* Release the asynchronous socket*/
|
Release the asynchronous socket
|
IsIPv6Supported
|
bool IsIPv6Supported()
{
#ifdef NO_IPV6
return false;
#else // NO_IPV6
SOCKET s;
s = socket(AF_INET6, SOCK_STREAM, 0);
if (s == INVALID_SOCKET)
{
return false;
}
closesocket(s);
return true;
#endif // NO_IPV6
}
|
/* Check whether the IPv6 is supported*/
|
Check whether the IPv6 is supported
|
CompareHostCache
|
int CompareHostCache(void *p1, void *p2)
{
HOSTCACHE *c1, *c2;
if (p1 == NULL || p2 == NULL)
{
return 0;
}
c1 = *(HOSTCACHE **)p1;
c2 = *(HOSTCACHE **)p2;
if (c1 == NULL || c2 == NULL)
{
return 0;
}
return CmpIpAddr(&c1->IpAddress, &c2->IpAddress);
}
|
/* Comparison of host name cache entries*/
|
Comparison of host name cache entries
|
FreeHostCache
|
void FreeHostCache()
{
UINT i;
for (i = 0;i < LIST_NUM(HostCacheList);i++)
{
HOSTCACHE *c = LIST_DATA(HostCacheList, i);
Free(c);
}
ReleaseList(HostCacheList);
HostCacheList = NULL;
}
|
/* Release of the host name cache*/
|
Release of the host name cache
|
InitHostCache
|
void InitHostCache()
{
HostCacheList = NewList(CompareHostCache);
}
|
/* Initialization of the host name cache*/
|
Initialization of the host name cache
|
AddWaitThread
|
void AddWaitThread(THREAD *t)
{
// Validate arguments
if (t == NULL)
{
return;
}
AddRef(t->ref);
LockList(WaitThreadList);
{
Add(WaitThreadList, t);
}
UnlockList(WaitThreadList);
}
|
/* Add the thread to the thread waiting list*/
|
Add the thread to the thread waiting list
|
DelWaitThread
|
void DelWaitThread(THREAD *t)
{
// Validate arguments
if (t == NULL)
{
return;
}
LockList(WaitThreadList);
{
if (Delete(WaitThreadList, t))
{
ReleaseThread(t);
}
}
UnlockList(WaitThreadList);
}
|
/* Remove the thread from the waiting list*/
|
Remove the thread from the waiting list
|
InitWaitThread
|
void InitWaitThread()
{
WaitThreadList = NewList(NULL);
}
|
/* Creating a thread waiting list*/
|
Creating a thread waiting list
|
FreeWaitThread
|
void FreeWaitThread()
{
UINT i, num;
THREAD **threads;
LockList(WaitThreadList);
{
num = LIST_NUM(WaitThreadList);
threads = ToArray(WaitThreadList);
DeleteAll(WaitThreadList);
}
UnlockList(WaitThreadList);
for (i = 0;i < num;i++)
{
THREAD *t = threads[i];
WaitThread(t, INFINITE);
ReleaseThread(t);
}
Free(threads);
ReleaseList(WaitThreadList);
WaitThreadList = NULL;
}
|
/* Release of the thread waiting list*/
|
Release of the thread waiting list
|
GetDomainName
|
bool GetDomainName(char *name, UINT size)
{
bool ret = false;
IP ip;
// Validate arguments
ClearStr(name, size);
if (name == NULL)
{
return false;
}
#ifdef OS_WIN32
ClearStr(name, size);
ret = Win32GetDefaultDns(&ip, name, size);
if (ret == false || IsEmptyStr(name))
{
ret = Win32GetDnsSuffix(name, size);
}
#else // OS_WIN32
ret = UnixGetDomainName(name, size);
#endif // OS_WIN32
if (ret == false)
{
return false;
}
return (IsEmptyStr(name) ? false : true);
}
|
/* Get the domain name*/
|
Get the domain name
|
GetDefaultDns
|
bool GetDefaultDns(IP *ip)
{
#ifdef OS_WIN32
return Win32GetDefaultDns(ip, NULL, 0);
#else
return UnixGetDefaultDns(ip);
#endif // OS_WIN32
}
|
/* Get the default DNS server*/
|
Get the default DNS server
|
NewSockEvent
|
SOCK_EVENT *NewSockEvent()
{
#ifdef OS_WIN32
return Win32NewSockEvent();
#else
return UnixNewSockEvent();
#endif // OS_WIN32
}
|
/* Creating a socket event*/
|
Creating a socket event
|
SetSockEvent
|
void SetSockEvent(SOCK_EVENT *event)
{
#ifdef OS_WIN32
Win32SetSockEvent(event);
#else
UnixSetSockEvent(event);
#endif // OS_WIN32
}
|
/* Set of the socket event*/
|
Set of the socket event
|
CleanupSockEvent
|
void CleanupSockEvent(SOCK_EVENT *event)
{
#ifdef OS_WIN32
Win32CleanupSockEvent(event);
#else
UnixCleanupSockEvent(event);
#endif // OS_WIN32
}
|
/* Clean-up of the socket event*/
|
Clean-up of the socket event
|
WaitSockEvent
|
bool WaitSockEvent(SOCK_EVENT *event, UINT timeout)
{
bool ret = false;
#ifdef OS_WIN32
ret = Win32WaitSockEvent(event, timeout);
#else
ret = UnixWaitSockEvent(event, timeout);
#endif // OS_WIN32
return ret;
}
|
/* Waiting for the socket event*/
|
Waiting for the socket event
|
ReleaseSockEvent
|
void ReleaseSockEvent(SOCK_EVENT *event)
{
// Validate arguments
if (event == NULL)
{
return;
}
if (Release(event->ref) == 0)
{
CleanupSockEvent(event);
}
}
|
/* Release of the socket event*/
|
Release of the socket event
|
JoinSockToSockEvent
|
void JoinSockToSockEvent(SOCK *sock, SOCK_EVENT *event)
{
// Validate arguments
if (sock == NULL || event == NULL)
{
return;
}
if (sock->Type == SOCK_INPROC)
{
// Set the SockEvent on the receiver TUBE for in-process type socket
SetTubeSockEvent(sock->RecvTube, event);
return;
}
if (sock->BulkRecvTube != NULL)
{
// Set the SockEvent on the receiver TUBE in case of R-UDP socket
SetTubeSockEvent(sock->BulkRecvTube, event);
}
#ifdef OS_WIN32
Win32JoinSockToSockEvent(sock, event);
#else
UnixJoinSockToSockEvent(sock, event);
#endif // OS_WIN32
}
|
/* Let belonging the socket to the socket event*/
|
Let belonging the socket to the socket event
|
NewCancelSpecial
|
CANCEL *NewCancelSpecial(void *hEvent)
{
CANCEL *c;
// Validate arguments
if (hEvent == NULL)
{
return NULL;
}
c = ZeroMalloc(sizeof(CANCEL));
c->ref = NewRef();
c->SpecialFlag = true;
#ifdef OS_WIN32
c->hEvent = (HANDLE)hEvent;
#else // OS_WIN32
c->pipe_read = (int)hEvent;
c->pipe_write = -1;
#endif // OS_WIN32
return c;
}
|
/* New special cancel object*/
|
New special cancel object
|
NewCancel
|
CANCEL *NewCancel()
{
CANCEL *c = NULL;
#ifdef OS_WIN32
c = Win32NewCancel();
#else
c = UnixNewCancel();
#endif // OS_WIN32
return c;
}
|
/* Creating a cancel object*/
|
Creating a cancel object
|
ReleaseCancel
|
void ReleaseCancel(CANCEL *c)
{
// Validate arguments
if (c == NULL)
{
return;
}
if (Release(c->ref) == 0)
{
CleanupCancel(c);
}
}
|
/* Release of the cancel object*/
|
Release of the cancel object
|
CleanupCancel
|
void CleanupCancel(CANCEL *c)
{
#ifdef OS_WIN32
Win32CleanupCancel(c);
#else
UnixCleanupCancel(c);
#endif
}
|
/* Clean up of the cancel object*/
|
Clean up of the cancel object
|
FreeRouteEntry
|
void FreeRouteEntry(ROUTE_ENTRY *e)
{
// Validate arguments
if (e == NULL)
{
return;
}
Free(e);
}
|
/* Release the routing entry*/
|
Release the routing entry
|
GetBestRouteEntry
|
ROUTE_ENTRY *GetBestRouteEntry(IP *ip)
{
return GetBestRouteEntryEx(ip, 0);
}
|
/* Get the best route entry by analyzing the current routing table*/
|
Get the best route entry by analyzing the current routing table
|
GetVLanInterfaceID
|
UINT GetVLanInterfaceID(char *tag_name)
{
UINT ret = 0;
#ifdef OS_WIN32
ret = Win32GetVLanInterfaceID(tag_name);
#else // OS_WIN32
ret = UnixGetVLanInterfaceID(tag_name);
#endif // OS_WIN32
return ret;
}
|
/* Get the interface ID of the virtual LAN card*/
|
Get the interface ID of the virtual LAN card
|
FreeEnumVLan
|
void FreeEnumVLan(char **s)
{
char *a;
UINT i;
// Validate arguments
if (s == NULL)
{
return;
}
i = 0;
while (true)
{
a = s[i++];
if (a == NULL)
{
break;
}
Free(a);
}
Free(s);
}
|
/* Release of enumeration variable of virtual LAN card*/
|
Release of enumeration variable of virtual LAN card
|
EnumVLan
|
char **EnumVLan(char *tag_name)
{
char **ret = NULL;
#ifdef OS_WIN32
ret = Win32EnumVLan(tag_name);
#else // OS_WIN32
ret = UnixEnumVLan(tag_name);
#endif // OS_WIN32
return ret;
}
|
/* Enumeration of virtual LAN cards*/
|
Enumeration of virtual LAN cards
|
DebugPrintRouteTable
|
void DebugPrintRouteTable(ROUTE_TABLE *r)
{
UINT i;
// Validate arguments
if (r == NULL)
{
return;
}
if (IsDebug() == false)
{
return;
}
Debug("---- Routing Table (%u Entries) ----\n", r->NumEntry);
for (i = 0;i < r->NumEntry;i++)
{
Debug(" ");
DebugPrintRoute(r->Entry[i]);
}
Debug("------------------------------------\n");
}
|
/* Display the routing table*/
|
Display the routing table
|
DebugPrintRoute
|
void DebugPrintRoute(ROUTE_ENTRY *e)
{
char tmp[MAX_SIZE];
// Validate arguments
if (e == NULL)
{
return;
}
if (IsDebug() == false)
{
return;
}
RouteToStr(tmp, sizeof(tmp), e);
Debug("%s\n", tmp);
}
|
/* Display the routing table entry*/
|
Display the routing table entry
|
DeleteRouteEntry
|
void DeleteRouteEntry(ROUTE_ENTRY *e)
{
Debug("DeleteRouteEntry();\n");
#ifdef OS_WIN32
Win32DeleteRouteEntry(e);
#else // OS_WIN32
UnixDeleteRouteEntry(e);
#endif
}
|
/* Delete the routing table*/
|
Delete the routing table
|
AddRouteEntry
|
bool AddRouteEntry(ROUTE_ENTRY *e)
{
bool dummy = false;
return AddRouteEntryEx(e, &dummy);
}
|
/* Add to the routing table*/
|
Add to the routing table
|
FreeRouteTable
|
void FreeRouteTable(ROUTE_TABLE *t)
{
UINT i;
// Validate arguments
if (t == NULL)
{
return;
}
for (i = 0;i < t->NumEntry;i++)
{
Free(t->Entry[i]);
}
Free(t->Entry);
Free(t);
}
|
/* Release of the routing table*/
|
Release of the routing table
|
ClearSockDfBit
|
void ClearSockDfBit(SOCK *s)
{
#ifdef IP_PMTUDISC_DONT
#ifdef IP_MTU_DISCOVER
UINT value = IP_PMTUDISC_DONT;
if (s == NULL)
{
return;
}
(void)setsockopt(s->socket, IPPROTO_IP, IP_MTU_DISCOVER, (char *)&value, sizeof(value));
#endif // IP_MTU_DISCOVER
#endif // IP_PMTUDISC_DONT
}
|
/* Set the DF bit of the socket*/
|
Set the DF bit of the socket
|
SetRawSockHeaderIncludeOption
|
void SetRawSockHeaderIncludeOption(SOCK *s, bool enable)
{
UINT value = BOOL_TO_INT(enable);
if (s == NULL || s->IsRawSocket == false)
{
return;
}
(void)setsockopt(s->socket, IPPROTO_IP, IP_HDRINCL, (char *)&value, sizeof(value));
s->RawIP_HeaderIncludeFlag = enable;
}
|
/* Set the header-include option*/
|
Set the header-include option
|
NewUDP
|
SOCK *NewUDP(UINT port)
{
return NewUDPEx(port, false);
}
|
/* If port is specified as 0, system assigns a certain port.*/
|
If port is specified as 0, system assigns a certain port.
|
AddSockSet
|
void AddSockSet(SOCKSET *set, SOCK *sock)
{
// Validate arguments
if (set == NULL || sock == NULL)
{
return;
}
if (sock->Type == SOCK_TCP && sock->Connected == false)
{
return;
}
if (set->NumSocket >= MAX_SOCKSET_NUM)
{
// Upper limit
return;
}
set->Sock[set->NumSocket++] = sock;
}
|
/* Add a socket to the socket set*/
|
Add a socket to the socket set
|
InitSockSet
|
void InitSockSet(SOCKSET *set)
{
// Validate arguments
if (set == NULL)
{
return;
}
Zero(set, sizeof(SOCKSET));
}
|
/* Initializing the socket set*/
|
Initializing the socket set
|
RecvAllWithDiscard
|
bool RecvAllWithDiscard(SOCK *sock, UINT size, bool secure)
{
static UCHAR buffer[4096];
UINT recv_size, sz, ret;
if (sock == NULL)
{
return false;
}
if (size == 0)
{
return true;
}
if (sock->AsyncMode)
{
return false;
}
recv_size = 0;
while (true)
{
sz = MIN(size - recv_size, sizeof(buffer));
ret = Recv(sock, buffer, sz, secure);
if (ret == 0)
{
return false;
}
if (ret == SOCK_LATER)
{
// I suppose that this is safe because the RecvAll() function is used only
// if the sock->AsyncMode == true. And the Recv() function may return
// SOCK_LATER only if the sock->AsyncMode == false. Therefore the call of
// Recv() function in the RecvAll() function never returns SOCK_LATER.
return false;
}
recv_size += ret;
if (recv_size >= size)
{
return true;
}
}
}
|
/* Receive data and discard all of them*/
|
Receive data and discard all of them
|
SendNow
|
bool SendNow(SOCK *sock, int secure)
{
bool ret;
// Validate arguments
if (sock == NULL || sock->AsyncMode != false)
{
return false;
}
if (sock->SendBuf->Size == 0)
{
return true;
}
ret = SendAll(sock, sock->SendBuf->Buf, sock->SendBuf->Size, secure);
ClearBuf(sock->SendBuf);
return ret;
}
|
/* Send the TCP send buffer*/
|
Send the TCP send buffer
|
SendAdd
|
void SendAdd(SOCK *sock, void *data, UINT size)
{
// Validate arguments
if (sock == NULL || data == NULL || size == 0 || sock->AsyncMode != false)
{
return;
}
WriteBuf(sock->SendBuf, data, size);
}
|
/* Append to the TCP send buffer*/
|
Append to the TCP send buffer
|
SendAll
|
bool SendAll(SOCK *sock, void *data, UINT size, bool secure)
{
UCHAR *buf;
UINT sent_size;
UINT ret;
// Validate arguments
if (sock == NULL || data == NULL)
{
return false;
}
if (sock->AsyncMode)
{
return false;
}
if (size == 0)
{
return true;
}
buf = (UCHAR *)data;
sent_size = 0;
while (true)
{
ret = Send(sock, buf, size - sent_size, secure);
if (ret == 0)
{
return false;
}
sent_size += ret;
buf += ret;
if (sent_size >= size)
{
return true;
}
}
}
|
/* Send all by TCP*/
|
Send all by TCP
|
SetWantToUseCipher
|
void SetWantToUseCipher(SOCK *sock, char *name)
{
// Validate arguments
if (sock == NULL || name == NULL)
{
return;
}
if (sock->WaitToUseCipher)
{
Free(sock->WaitToUseCipher);
}
sock->WaitToUseCipher = CopyStr(name);
}
|
/* Set the cipher algorithm name to want to use*/
|
Set the cipher algorithm name to want to use
|
AddChainSslCert
|
bool AddChainSslCert(struct ssl_ctx_st *ctx, X *x)
{
bool ret = false;
X *x_copy;
// Validate arguments
if (ctx == NULL || x == NULL)
{
return ret;
}
x_copy = CloneX(x);
if (x_copy != NULL)
{
SSL_CTX_add_extra_chain_cert(ctx, x_copy->x509);
x_copy->do_not_free = true;
ret = true;
FreeX(x_copy);
}
return ret;
}
|
/* Add the chain certificate*/
|
Add the chain certificate
|
StartSSL
|
bool StartSSL(SOCK *sock, X *x, K *priv)
{
return StartSSLEx(sock, x, priv, 0, NULL);
}
|
/* Start a TCP-SSL communication*/
|
Start a TCP-SSL communication
|
SockCloseSslLogging
|
void SockCloseSslLogging(SOCK *s)
{
// Validate arguments
if (s == NULL)
{
return;
}
if (s->IsSslLoggingEnabled == false)
{
return;
}
s->IsSslLoggingEnabled = false;
FileClose(s->SslLogging_Recv);
s->SslLogging_Recv = NULL;
FileClose(s->SslLogging_Send);
s->SslLogging_Send = NULL;
DeleteLock(s->SslLogging_Lock);
s->SslLogging_Lock = NULL;
}
|
/* Close SSL logging*/
|
Close SSL logging
|
SetNoNeedToRead
|
void SetNoNeedToRead(SOCK *sock)
{
// Validate arguments
if (sock == NULL)
{
return;
}
sock->NoNeedToRead = true;
}
|
/* Set the flag to indicate that the socket doesn't require reading*/
|
Set the flag to indicate that the socket doesn't require reading
|
GetTimeout
|
UINT GetTimeout(SOCK *sock)
{
// Validate arguments
if (sock == NULL)
{
return INFINITE;
}
if (sock->Type != SOCK_TCP && sock->Type != SOCK_INPROC)
{
return INFINITE;
}
return sock->TimeOut;
}
|
/* Get the time-out value (in milliseconds)*/
|
Get the time-out value (in milliseconds)
|
DisableGetHostNameWhenAcceptInit
|
void DisableGetHostNameWhenAcceptInit()
{
disable_gethostname_by_accept = true;
}
|
/* Disable GetHostName call by accepting new TCP connection*/
|
Disable GetHostName call by accepting new TCP connection
|
AcceptInit
|
void AcceptInit(SOCK *s)
{
AcceptInitEx(s, false);
}
|
/* Initialize the connection acceptance*/
|
Initialize the connection acceptance
|
ListenEx6
|
SOCK *ListenEx6(UINT port, bool local_only)
{
return ListenEx62(port, local_only, false);
}
|
/* Standby for TCP (IPv6)*/
|
Standby for TCP (IPv6)
|
Listen
|
SOCK *Listen(UINT port)
{
return ListenEx(port, false);
}
|
/* Standby for the TCP*/
|
Standby for the TCP
|
CheckTCPPortEx
|
bool CheckTCPPortEx(char *hostname, UINT port, UINT timeout)
{
SOCK *s;
// Validate arguments
if (hostname == NULL || port == 0 || port >= 65536)
{
return false;
}
if (timeout == 0)
{
timeout = TIMEOUT_TCP_PORT_CHECK;
}
s = ConnectEx(hostname, port, timeout);
if (s == NULL)
{
return false;
}
else
{
Disconnect(s);
ReleaseSock(s);
return true;
}
}
|
/* Check whether the TCP port can be connected*/
|
Check whether the TCP port can be connected
|
SetSockTos
|
void SetSockTos(SOCK *s, int tos)
{
// Validate arguments
if (s == NULL)
{
return;
}
if (s->CurrentTos == tos)
{
return;
}
#ifdef IP_TOS
(void)setsockopt(s->socket, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int));
#endif // IP_TOS
s->CurrentTos = tos;
}
|
/* Set the TOS value of the socket*/
|
Set the TOS value of the socket
|
SetSockHighPriority
|
void SetSockHighPriority(SOCK *s, bool flag)
{
// Validate arguments
if (s == NULL)
{
return;
}
SetSockTos(s, (flag ? 16 : 0));
}
|
/* Set the priority of the socket*/
|
Set the priority of the socket
|
SetSocketBufferSize
|
bool SetSocketBufferSize(SOCKET s, bool send, UINT size)
{
int value = (int)size;
// Validate arguments
if (s == INVALID_SOCKET)
{
return false;
}
if (setsockopt(s, SOL_SOCKET, (send ? SO_SNDBUF : SO_RCVBUF), (char *)&value, sizeof(int)) != 0)
{
return false;
}
return true;
}
|
/* Setting the buffer size of the socket*/
|
Setting the buffer size of the socket
|
InitUdpSocketBufferSize
|
void InitUdpSocketBufferSize(SOCKET s)
{
SetSocketBufferSizeWithBestEffort(s, true, UDP_MAX_BUFFER_SIZE);
SetSocketBufferSizeWithBestEffort(s, false, UDP_MAX_BUFFER_SIZE);
}
|
/* Initialize the buffer size of the UDP socket*/
|
Initialize the buffer size of the UDP socket
|
ReleaseSock
|
void ReleaseSock(SOCK *s)
{
// Validate arguments
if (s == NULL)
{
return;
}
if (Release(s->ref) == 0)
{
if (s->ListenMode == false && s->ServerMode)
{
Print("");
}
CleanupSock(s);
}
}
|
/* Release of the socket*/
|
Release of the socket
|
NewSock
|
SOCK *NewSock()
{
SOCK *s = ZeroMallocFast(sizeof(SOCK));
s->ref = NewRef();
s->lock = NewLock();
s->SendBuf = NewBuf();
s->socket = INVALID_SOCKET;
s->ssl_lock = NewLock();
s->disconnect_lock = NewLock();
Inc(num_tcp_connections);
return s;
}
|
/* Creating a new socket*/
|
Creating a new socket
|
IPToUINT
|
UINT IPToUINT(IP *ip)
{
UCHAR *b;
UINT i, value = 0;
// Validate arguments
if (ip == NULL)
{
return 0;
}
b = (UCHAR *)&value;
for (i = 0;i < 4;i++)
{
b[i] = ip->addr[i];
}
return value;
}
|
/* Convert the IP to UINT*/
|
Convert the IP to UINT
|
UINTToIP
|
void UINTToIP(IP *ip, UINT value)
{
UCHAR *b;
UINT i;
// Validate arguments
if (ip == NULL)
{
return;
}
ZeroIP4(ip);
b = (UCHAR *)&value;
for (i = 0;i < 4;i++)
{
ip->addr[i] = b[i];
}
}
|
/* Convert UINT to IP*/
|
Convert UINT to IP
|
GetMachineHostName
|
void GetMachineHostName(char *name, UINT size)
{
char tmp[MAX_SIZE];
UINT i, len;
// Validate arguments
if (name == NULL)
{
return;
}
GetMachineName(tmp, sizeof(tmp));
len = StrLen(tmp);
for (i = 0;i < len;i++)
{
if (tmp[i] == '.')
{
tmp[i] = 0;
}
}
ConvertSafeFileName(name, size, tmp);
}
|
/* Get the host name of the computer*/
|
Get the host name of the computer
|
GetMachineName
|
void GetMachineName(char *name, UINT size)
{
GetMachineNameEx(name, size, false);
}
|
/* Get the computer name of this computer*/
|
Get the computer name of this computer
|
GetHostNameThread
|
void GetHostNameThread(THREAD *t, void *p)
{
IP *ip;
char hostname[256];
// Validate arguments
if (t == NULL || p == NULL)
{
return;
}
ip = (IP *)p;
AddWaitThread(t);
NoticeThreadInit(t);
if (GetHostNameInner(hostname, sizeof(hostname), ip))
{
AddHostCache(ip, hostname);
}
Free(ip);
DelWaitThread(t);
}
|
/* Host name acquisition thread*/
|
Host name acquisition thread
|
SetIP
|
void SetIP(IP *ip, UCHAR a1, UCHAR a2, UCHAR a3, UCHAR a4)
{
// Validate arguments
if (ip == NULL)
{
return;
}
Zero(ip, sizeof(IP));
ip->addr[0] = a1;
ip->addr[1] = a2;
ip->addr[2] = a3;
ip->addr[3] = a4;
}
|
/* Set the IP address*/
|
Set the IP address
|
CleanupGetIPThreadParam
|
void CleanupGetIPThreadParam(GETIP_THREAD_PARAM *p)
{
// Validate arguments
if (p == NULL)
{
return;
}
Free(p);
}
|
/* Clean-up of the parameters for GetIP thread*/
|
Clean-up of the parameters for GetIP thread
|
ReleaseGetIPThreadParam
|
void ReleaseGetIPThreadParam(GETIP_THREAD_PARAM *p)
{
// Validate arguments
if (p == NULL)
{
return;
}
if (Release(p->Ref) == 0)
{
CleanupGetIPThreadParam(p);
}
}
|
/* Release of the parameters of the GetIP for thread*/
|
Release of the parameters of the GetIP for thread
|
GetIP4Ex6ExThread
|
void GetIP4Ex6ExThread(THREAD *t, void *param)
{
GETIP_THREAD_PARAM *p;
// Validate arguments
if (t == NULL || param == NULL)
{
return;
}
p = (GETIP_THREAD_PARAM *)param;
AddRef(p->Ref);
NoticeThreadInit(t);
AddWaitThread(t);
// Execution of resolution
if (p->IPv6 == false)
{
// IPv4
p->Ok = GetIP4Inner(&p->Ip, p->HostName);
}
else
{
// IPv6
p->Ok = GetIP6Inner(&p->Ip, p->HostName);
}
ReleaseGetIPThreadParam(p);
DelWaitThread(t);
Dec(getip_thread_counter);
}
|
/* Thread to perform to query the DNS forward lookup (with timeout)*/
|
Thread to perform to query the DNS forward lookup (with timeout)
|
GetIP4Ex6Ex
|
bool GetIP4Ex6Ex(IP *ip, char *hostname_arg, UINT timeout, bool ipv6, bool *cancel)
{
return GetIP4Ex6Ex2(ip, hostname_arg, timeout, ipv6, cancel, false);
}
|
/* Perform a forward DNS query (with timeout)*/
|
Perform a forward DNS query (with timeout)
|
GetIP
|
bool GetIP(IP *ip, char *hostname)
{
return GetIPEx(ip, hostname, false);
}
|
/* Perform a DNS forward lookup query*/
|
Perform a DNS forward lookup query
|
QueryDnsCache
|
bool QueryDnsCache(IP *ip, char *hostname)
{
return QueryDnsCacheEx(ip, hostname, false);
}
|
/* Search in the DNS cache*/
|
Search in the DNS cache
|
IPToUniStr
|
void IPToUniStr(wchar_t *str, UINT size, IP *ip)
{
char tmp[128];
IPToStr(tmp, sizeof(tmp), ip);
StrToUni(str, size, tmp);
}
|
/* Convert the IP to a string*/
|
Convert the IP to a string
|
IPToUniStr32
|
void IPToUniStr32(wchar_t *str, UINT size, UINT ip)
{
char tmp[128];
IPToStr32(tmp, sizeof(tmp), ip);
StrToUni(str, size, tmp);
}
|
/* Convert the IP to a string (32bit UINT)*/
|
Convert the IP to a string (32bit UINT)
|
IPToStr32
|
void IPToStr32(char *str, UINT size, UINT ip)
{
IP ip_st;
// Validate arguments
if (str == NULL)
{
return;
}
UINTToIP(&ip_st, ip);
IPToStr(str, size, &ip_st);
}
|
/* Convert the IP to a string (32bit UINT)*/
|
Convert the IP to a string (32bit UINT)
|
IPToStr4or6
|
void IPToStr4or6(char *str, UINT size, UINT ip_4_uint, UCHAR *ip_6_bytes)
{
IP ip4;
IP ip6;
IP ip;
// Validate arguments
if (str == NULL)
{
return;
}
Zero(&ip, sizeof(ip));
UINTToIP(&ip4, ip_4_uint);
SetIP6(&ip6, ip_6_bytes);
if (IsIP6(&ip4) || (IsZeroIp(&ip4) && (IsZeroIp(&ip6) == false)))
{
Copy(&ip, &ip6, sizeof(IP));
}
else
{
Copy(&ip, &ip4, sizeof(IP));
}
IPToStr(str, size, &ip);
}
|
/* Convert IPv4 or IPv6 to a string*/
|
Convert IPv4 or IPv6 to a string
|
IPToStr
|
void IPToStr(char *str, UINT size, IP *ip)
{
// Validate arguments
if (str == NULL || ip == NULL)
{
return;
}
if (IsIP6(ip))
{
IPToStr6(str, size, ip);
}
else
{
IPToStr4(str, size, ip);
}
}
|
/* Convert the IP to a string*/
|
Convert the IP to a string
|
IPToStr4
|
void IPToStr4(char *str, UINT size, IP *ip)
{
// Validate arguments
if (str == NULL || ip == NULL)
{
return;
}
// Conversion
snprintf(str, size != 0 ? size : 64, "%u.%u.%u.%u", ip->addr[0], ip->addr[1], ip->addr[2], ip->addr[3]);
}
|
/* Convert the IPv4 to a string*/
|
Convert the IPv4 to a string
|
IPToInAddr
|
void IPToInAddr(struct in_addr *addr, IP *ip)
{
UINT i;
// Validate arguments
if (addr == NULL || ip == NULL)
{
return;
}
Zero(addr, sizeof(struct in_addr));
if (IsIP6(ip) == false)
{
for (i = 0;i < 4;i++)
{
((UCHAR *)addr)[i] = ip->addr[i];
}
}
}
|
/* Convert the IP to the in_addr*/
|
Convert the IP to the in_addr
|
IPToInAddr6
|
void IPToInAddr6(struct in6_addr *addr, IP *ip)
{
UINT i;
// Validate arguments
if (addr == NULL || ip == NULL)
{
return;
}
Zero(addr, sizeof(struct in6_addr));
if (IsIP6(ip))
{
for (i = 0;i < 16;i++)
{
((UCHAR *)addr)[i] = ip->ipv6_addr[i];
}
}
}
|
/* Convert the IP to the in6_addr*/
|
Convert the IP to the in6_addr
|
InAddrToIP
|
void InAddrToIP(IP *ip, struct in_addr *addr)
{
UINT i;
// Validate arguments
if (ip == NULL || addr == NULL)
{
return;
}
Zero(ip, sizeof(IP));
for (i = 0;i < 4;i++)
{
ip->addr[i] = ((UCHAR *)addr)[i];
}
}
|
/* Convert the in_addr to the IP*/
|
Convert the in_addr to the IP
|
InAddrToIP6
|
void InAddrToIP6(IP *ip, struct in6_addr *addr)
{
UINT i;
// Validate arguments
if (ip == NULL || addr == NULL)
{
return;
}
ZeroIP6(ip);
for (i = 0;i < 16;i++)
{
ip->ipv6_addr[i] = ((UCHAR *)addr)[i];
}
}
|
/* Convert the in6_addr to the IP*/
|
Convert the in6_addr to the IP
|
FindDnsCache
|
DNSCACHE *FindDnsCache(char *hostname)
{
return FindDnsCacheEx(hostname, false);
}
|
/* Search in the DNS cache*/
|
Search in the DNS cache
|
GenDnsCacheKeyName
|
void GenDnsCacheKeyName(char *dst, UINT size, char *src, bool ipv6)
{
// Validate arguments
if (dst == NULL || src == NULL)
{
return;
}
if (ipv6 == false)
{
StrCpy(dst, size, src);
}
else
{
Format(dst, size, "%s@ipv6", src);
}
}
|
/* Generate the IPv4 / IPv6 key name for the DNS cache*/
|
Generate the IPv4 / IPv6 key name for the DNS cache
|
NewDnsCache
|
void NewDnsCache(char *hostname, IP *ip)
{
NewDnsCacheEx(hostname, ip, IsIP6(ip));
}
|
/* Registration of the new DNS cache*/
|
Registration of the new DNS cache
|
CompareDnsCache
|
int CompareDnsCache(void *p1, void *p2)
{
DNSCACHE *c1, *c2;
if (p1 == NULL || p2 == NULL)
{
return 0;
}
c1 = *(DNSCACHE **)p1;
c2 = *(DNSCACHE **)p2;
if (c1 == NULL || c2 == NULL)
{
return 0;
}
return StrCmpi(c1->HostName, c2->HostName);
}
|
/* Name comparison of the DNS cache entries*/
|
Name comparison of the DNS cache entries
|
InitDnsCache
|
void InitDnsCache()
{
// Creating a List
DnsCache = NewList(CompareDnsCache);
}
|
/* Initialization of the DNS cache*/
|
Initialization of the DNS cache
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.