def udp_to_tcp_data(d):
    """
    Append two byte length field to UDP datagram, to send it over TCP.

    :param d: (bytes) UDP DNS request
    :return: (bytes) TCP ready DNS request
    """
    length = len(d)
    length_hex = hex(length)[2:].zfill(4)
    prefix = bytes.fromhex(length_hex)
    d = prefix + d
    return d