Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrapper ip format #2

Closed
kyy13 opened this issue Jun 15, 2022 · 6 comments
Closed

wrapper ip format #2

kyy13 opened this issue Jun 15, 2022 · 6 comments

Comments

@kyy13
Copy link
Owner

kyy13 commented Jun 15, 2022

Create IPv4 and IPv6 formats that can be converted to/from string rather than supply a string to socket sender/receiver.

@kyy13
Copy link
Owner Author

kyy13 commented Jun 15, 2022

Note that format needs to he exposed to main API as well

@kyy13
Copy link
Owner Author

kyy13 commented Jun 15, 2022

struct IPv4Address
{
    uint8_t octets[4];
};

struct IPv6Address
{
    uint16_t segments[8];
};

@kyy13
Copy link
Owner Author

kyy13 commented Jun 15, 2022

enum IpVersion : uint8_t
{
    IP_V4,
    IP_V6,
};

// IP represented in bytes
// IPv4 readable format by byte number is
//   [0].[1].[2].[3]
// IPv6 readable format by byte number is
//   [0][1]:[2][3]:[4][5]:[6][7]:[8][9]:[10][11]:[12][13]:[14][15]
//   NOTE: Byte pairs (e.g. [0][1]) in Big Endian byte order
union IpAddress
{
    uint8_t ip_v4[4];
    uint8_t ip_v6[16];
};

@kyy13
Copy link
Owner Author

kyy13 commented Jun 15, 2022

void udcConvertStringToIp(const char* str, IpVersion* version, IpAddress* address);

void udcConvertIpToString(IpVersion version, IpAddress address, char* str);

@kyy13
Copy link
Owner Author

kyy13 commented Jun 15, 2022

needs to be typedef uint8_t[16] IpAddress;
because no unions in C

@kyy13
Copy link
Owner Author

kyy13 commented Jun 15, 2022

enum UdcAddressFamily
{
    UDC_IPV4,
    UDC_IPV6,
};

struct UdcAddress
{
    uint8_t bytes[16];
};

struct UdcAddressIPv4
{
    uint8_t bytes[4];
};

struct UdcAddressIPv6
{
    uint8_t bytes[16];
};

UdcAddressIPv4 udcConvertToIPv4(UdcAddress);

UdcAddressIPv6 udcConvertToIPv6(UdcAddress);

@kyy13 kyy13 closed this as completed Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant