``````
/*
*
* Authors:
*		Axel Dörfler, axeld@pinc-software.de
*		Oliver Tappe, zooey@hirschkaefer.de
*		Atis Elsts, the.kfx@gmail.com
*/

#include <NetUtilities.h>

#include <memory.h>
#include <netinet6/in6.h>
#include <stdio.h>
#include <stdlib.h>

#include "ipv6_utils.h"
#include "jenkins.h"

static void
{

for (uint32 i = 0; i < sizeof(in6_addr); i++)
}

/*!	Routing utility function: copies address \a from into a new address
that is put into \a to.
If \a replaceWithZeros is set \a from will be replaced by an empty
If a \a mask is given it is applied to \a from (such that \a to is the
result of \a from & \a mask).
\return B_OK if the address could be copied
\return B_NO_MEMORY if the new address could not be allocated
\return B_BAD_VALUE if any of \a from or \a mask refers to an uninitialized
\return B_MISMATCHED_VALUES if \a address does not match family AF_INET
*/
static status_t
{
if (replaceWithZeros) {
if (*to == NULL)
return B_NO_MEMORY;

(*to)->sa_family = AF_INET6;
} else {
if (from == NULL)
return B_OK;
if (from->sa_len == 0 || (mask != NULL && mask->sa_len == 0))
if (from->sa_family != AF_INET6)
return B_MISMATCHED_VALUES;

if (*to == NULL)
return B_NO_MEMORY;

}
return B_OK;
}

/*!	Routing utility function: applies \a mask to given \a address and puts
the resulting address into \a result.
\return B_OK if the mask has been applied
*/
static status_t
{
if (address == NULL || address->sa_len == 0 || result == NULL

return B_OK;
}

/*!	Checks if the given \a address is the empty address. By default, the port
is checked, too, but you can avoid that by passing \a checkPort = false.
\return true if \a address is NULL, uninitialized or the empty address,
false if not
*/
static bool
{
return true;

if (checkPort && address->sin6_port != 0)
return false;

}

\return false if \a address is NULL, or with family different from AF_INET
true if it has AF_INET address family
*/
static bool
{
return false;

}

/*!	Compares the IP-addresses of the two given address structures \a a and \a b.
\return true if IP-addresses of \a a and \a b are equal, false if not
*/
static bool
{
if (a == NULL && b == NULL)
return true;
if (a != NULL && b == NULL)
if (a == NULL && b != NULL)

}

/*!	Compares the ports of the two given address structures \a a and \a b.
\return true if ports of \a a and \a b are equal, false if not
*/
static bool
{
uint16 portA = a ? ((sockaddr_in6 *)a)->sin6_port : 0;
uint16 portB = b ? ((sockaddr_in6 *)b)->sin6_port : 0;
return portA == portB;
}

/*!	Compares the IP-addresses and ports of the two given address structures
\a a and \a b.
\return true if IP-addresses and ports of \a a and \a b are equal, false if
not
*/
static bool
{
if (a == NULL && b == NULL)
return true;
if (a != NULL && b == NULL)
if (a == NULL && b != NULL)

return i6a->sin6_port == i6b->sin6_port
}

/*!	Applies the given \a mask two \a a and \a b and then checks whether
\return true if \a a matches \a b after masking both, false if not
*/
static bool
{
if (a == NULL && b == NULL)
return true;

if (a == NULL)
else

if (b == NULL)
else

for (uint8 i = 0; i < sizeof(in6_addr); ++i) {
}

return false;
}

return true;
}

/*!	Routing utility function: determines the least significant bit that is set
\return the number of the first bit that is set (0-32, where 32 means
that there's no bit set in the mask).
*/
static int32
{
return 0;

for (uint8 i = 0; i < sizeof(in6_addr); ++i) {
continue;

for (uint8 bit = 0; bit < 8; bit++) {
if ((pmask[i] & (1 << (7 - bit))) == 0)
return i * 8 + bit;
}
}

return 128;
}

/*!	Routing utility function: checks the given \a mask for correctness (which
means that (starting with LSB) consists zero or more unset bits, followed
by bits that are all set).
\return true if \a mask is ok, false if not
*/
static bool
{
return true;

bool zero = false;
for (uint8 i = 0; i < sizeof(in6_addr); ++i) {
if (zero)
return false;
} else if (pmask[i] == 0) {
zero = true;
} else {
for (int8 bit = 7; bit >= 0; bit--) {
if (pmask[i] & (1 << bit)) {
if (zero)
return false;
} else {
zero = true;
}
}
}
}

return true;
}

/*!	Creates a buffer for the given \a address and prints the address into
it (hexadecimal representation in network byte order or '<none>').
If \a printPort is set, the port is printed, too.
\return B_OK if the address could be printed, \a buffer will point to
the resulting string
\return B_BAD_VALUE if no buffer has been given
\return B_NO_MEMORY if the buffer could not be allocated,
or does not have enogh space
*/
static status_t
size_t bufferSize, bool printPort)
{

if (buffer == NULL)

if (bufferSize < sizeof("<none>"))
return B_NO_MEMORY;
strcpy(buffer, "<none>");
} else {
if (printPort && bufferSize > 0) {
*buffer = '[';
buffer++;
bufferSize--;
}

return B_NO_MEMORY;

if (printPort) {
char port;
if (bufferSize - strlen(buffer) < strlen(port) + 1)
return B_NO_MEMORY;
strcat(buffer, port);
}
}

return B_OK;
}

static status_t
{
if (_buffer == NULL)

char tmp;

*_buffer = strdup(tmp);
if (*_buffer == NULL)
return B_NO_MEMORY;

return B_OK;
}

/*!	Determines the port of the given \a address.
\return uint16 representing the port-nr
*/
static uint16
{
return 0;

}

/*!	Sets the port of the given \a address to \a port.
\return B_OK if the port has been set
\return B_BAD_VALUE if \a address is NULL or has not been initialized
*/
static status_t
{

return B_OK;
}

/*!	Sets \a address to \a from.
\return B_OK if \a from has been copied into \a address
\return B_BAD_VALUE if either \a address or \a from is NULL or if the
address given in from has not been initialized
\return B_MISMATCHED_VALUES if from is not of family AF_INET6
*/
static status_t
{
if (address == NULL || from == NULL || from->sa_len == 0)

if (from->sa_family != AF_INET6)
return B_MISMATCHED_VALUES;

return B_OK;
}

/*!	Updates missing parts in \a address with the values in \a from.
\return B_OK if \a address has been updated from \a from
\return B_BAD_VALUE if either \a address or \a from is NULL or if the
address given in from has not been initialized
\return B_MISMATCHED_VALUES if from is not of family AF_INET6
*/
static status_t
{

if (address == NULL || from == NULL || from->sin6_len == 0)

if (from->sin6_family != AF_INET6)

}

return B_OK;
}

\return B_OK if \a address has been set
*/
static status_t
{

return B_OK;
}

static status_t
{

} else {
// use /128 as the default mask
}

return B_OK;
}

/*!	Computes a hash value of the given \a address.
\return uint32 representing the hash value
*/
static uint32
{
return 0;

// TODO: also use sin6_flowinfo and sin6_scope_id?
uint32 port = includePort ? address->sin6_port : 0;

return jenkins_hashword(&port, 1, result);
}

\return uint32 representing the hash-value
*/
static uint32
{
}

\return B_BAD_VALUE if either \a address or \a checksum is NULL or if
the given address is not initialized
*/
static status_t
{
if (checksum == NULL || address == NULL || address->sa_len == 0)

for (uint32 i = 0; i < sizeof(in6_addr); i += 2)

return B_OK;
}

static void
{
}

{
NULL,
0,
NULL
},
0, // flags
ipv6_equal_ports,
ipv6_is_same_family,
ipv6_get_port,
ipv6_set_port,
ipv6_set_to,
ipv6_set_to_defaults,
ipv6_update_to,
};

``````

V512 A call of the 'memcpy' function will lead to underflow of the buffer 'from'.

V512 A call of the 'memcpy' function will lead to underflow of the buffer 'address'.

V512 A call of the 'memset' function will lead to underflow of the buffer '* to'.

V641 The size of the allocated memory buffer is not a multiple of the element size.

V641 The size of the allocated memory buffer is not a multiple of the element size.

V512 A call of the 'memcpy' function will lead to underflow of the buffer 'from'.

V512 A call of the 'memcpy' function will lead to underflow of the buffer 'address'.

V512 A call of the 'memset' function will lead to underflow of the buffer 'address'.

V512 A call of the 'memcpy' function will lead to underflow of the buffer 'result'.

V512 A call of the 'memcpy' function will lead to underflow of the buffer '* to'.
{"ft_lang_label":"__label__en","ft_lang_prob":0.50268036,"math_prob":0.9745433,"size":15022,"snap":"2019-43-2019-47","text_gpt3_token_len":4331,"char_repetition_ratio":0.23678252,"word_repetition_ratio":0.2867036,"special_character_ratio":0.32033017,"punctuation_ratio":0.16044317,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9763535,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-11-16T22:28:47Z\",\"WARC-Record-ID\":\"<urn:uuid:0f209d4b-4047-4abe-88cb-d032c2e9823b>\",\"Content-Length\":\"31643\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:10c32835-16c7-47db-a7e5-5cc422b00bc2>\",\"WARC-Concurrent-To\":\"<urn:uuid:f219963f-34a3-4779-9350-610d979433c6>\",\"WARC-IP-Address\":\"185.199.109.153\",\"WARC-Target-URI\":\"https://pulkomandy.github.io/sources/ipv6_address.cpp_293.html\",\"WARC-Payload-Digest\":\"sha1:T3QF47QIURJZTI2YODWWNNDEMOHMF4ME\",\"WARC-Block-Digest\":\"sha1:OMHPM6EZE24ARCSUXIQDMCVKO57O24JP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-47/CC-MAIN-2019-47_segments_1573496668765.35_warc_CC-MAIN-20191116204950-20191116232950-00476.warc.gz\"}"}