Details

      Description

      To implement MDEV-274 easier, let's wrap the code in item_inetfunc.cc into classes Inet4 and Inet6.

      The handler for the coming soon INET6 data type will reuse the new class Inet6.

      The implementation for Inet6 will look approximately like this:

      class Inet6
      {
        char m_buffer[IN6_ADDR_SIZE];
        bool str_to_ipv6(const char *str, size_t str_length, CHARSET_INFO *cs);
      public:
        // Initialize from a text representation
        Inet6(bool *error, const char *str, size_t length, CHARSET_INFO *cs)
        {
          *error= !str_to_ipv6(str, length, cs);
        }
        // Initialize from a binary representation
        Inet6(bool *error, const char *str, size_t length)
        {
          if (!(*error= length != sizeof(m_buffer)))
            memcpy(m_buffer, str, length);
        }
        Inet6(bool *error, Item *item);
        bool to_binary(String *to) const
        {
          return to->copy(m_buffer, sizeof(m_buffer), &my_charset_bin);
        }
        size_t to_string(char *dst, size_t dstsize) const;
        bool to_string(String *to) const
        {
          to->set_charset(&my_charset_latin1);
          if (to->alloc(INET6_ADDRSTRLEN))
            return true;
          to->length((uint32) to_string((char*) to->ptr(), INET6_ADDRSTRLEN));
          return false;
        }
        bool is_v4compat() const
        {
          static_assert(sizeof(in6_addr) == IN6_ADDR_SIZE, "unexpected in6_addr size");
          return IN6_IS_ADDR_V4COMPAT((struct in6_addr *) m_buffer);
        }
        bool is_v4mapped() const
        {
          static_assert(sizeof(in6_addr) == IN6_ADDR_SIZE, "unexpected in6_addr size");
          return IN6_IS_ADDR_V4MAPPED((struct in6_addr *) m_buffer);
        }
      };
      

      The implementation for Inet4 will look very similar.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                bar Alexander Barkov
                Reporter:
                bar Alexander Barkov
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: