Skip to content

Commit

Permalink
migrate to defines
Browse files Browse the repository at this point in the history
  • Loading branch information
jrepp authored and jrepp committed Mar 15, 2024
1 parent f4d2749 commit 8c79e81
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
13 changes: 5 additions & 8 deletions ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@
// Original core address RFC 3513: https://tools.ietf.org/html/rfc3513
// Replacement address RFC 4291: https://tools.ietf.org/html/rfc4291

// These constants are for self-documenting string formatting expansions
// sizeof "[1234:1234:1234:1234:1234:1234:1234:1234/128%longinterface]:65535";
const uint32_t IPV6_STRING_SIZE = 66;
// sizeof "255.255.255.255:65535";
const uint32_t IPV4_STRING_SIZE = 22;

//
// Distinct states of parsing an address
//
Expand Down Expand Up @@ -907,6 +901,9 @@ size_t IPV6_API_DEF(ipv6_to_str) (
char *output,
size_t output_bytes)
{
char token[IPV4_STRING_SIZE] = {0,};
const uint16_t *components;

if (!in || !output) {
return 0;
}
Expand All @@ -917,10 +914,10 @@ size_t IPV6_API_DEF(ipv6_to_str) (

*output = '\0';

const uint16_t* components = in->address.components;
components = in->address.components;
char* wp = output; // write pointer
const char* ep = output + output_bytes - 1; // end pointer with one octet for nul
char token[IPV4_STRING_SIZE] = {0};


// If the address is an IPv4 compatible address shortcut the IPv6 rules and
// print an address or address:port
Expand Down
8 changes: 6 additions & 2 deletions ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ extern "C" {
#endif


/// Maximum size of a IPV
extern const uint32_t IPV6_STRING_SIZE;
// These constants are for self-documenting string formatting expansions
// sizeof "[1234:1234:1234:1234:1234:1234:1234:1234/128%longinterface]:65535";
#define IPV6_STRING_SIZE 66

// sizeof "255.255.255.255:65535";
#define IPV4_STRING_SIZE 22

// ### ipv6_flag_t
//
Expand Down

0 comments on commit 8c79e81

Please sign in to comment.