def generate_pseudo_header(self, source, destination):
        # Calculate the length of the UDP layer
        udp_length = 8 + len(bytes(self.payload))

        if isinstance(source, IPv4Address) \
        and isinstance(destination, IPv4Address):
            # Generate an IPv4 pseudo-header
            header = BitStream('uint:32=%d, '
                               'uint:32=%d, '
                               'uint:16=17, '
                               'uint:16=%d' % (int(source),
                                               int(destination),
                                               udp_length))

        elif isinstance(source, IPv6Address) \
        and isinstance(destination, IPv6Address):
            # Generate an IPv6 pseudo-header
            header = BitStream('uint:128=%d, '
                               'uint:128=%d, '
                               'uint:32=%d, '
                               'uint:32=17' % (int(source),
                                               int(destination),
                                               udp_length))
        else:
            raise ValueError('Source and destination must belong to the same '
                             'IP version')

        # Return the header bytes
        return header.bytes