[En-Nut-Discussion] UFLASH Write Appends Trash Data

Bob Wirka bobwirka at yahoo.com
Sun Mar 22 14:30:57 CET 2015


Ole,
While I'm at it, here is another modification for /pro/resolv.c (changes marked by _RCW_):
uint8_t NutDnsGetResourceAll(const uint8_t * hostname, const uint16_t type, uint32_t * ip_all){    uint8_t n_ip;    uint8_t *pkt;    uint16_t len;    uint16_t id = 0;    UDPSOCKET *sock;    DNSHEADER *doh = 0;    DNSQUESTION *doq = 0;    DNSRESOURCE *dor = 0;    int n;    int retries;    uint32_t raddr;    uint16_t rport;

    for (n_ip = 0; n_ip < 8; n_ip++)        ip_all[n_ip] = 0;
    /*     * _RCW_     * Set n_ip to '0' here in case we fail all retries.     */    n_ip = 0;
    /*     * We need a configured DNS address.     */    if (confdns.doc_ip1 == 0 && confdns.doc_ip2 == 0)        return 0;
    /*     * Create client socket and allocate     * a buffer for the UDP packet.     */    if ((sock = NutUdpCreateSocket(0)) == 0)        return 0;    pkt = NutHeapAlloc(512);
    for (retries = 0; retries < 6; retries++) {
        /*         * Create standard header info structures.         */        doh = CreateDnsHeader(doh, ++id);        doq = CreateDnsQuestion(doq, hostname, type);
#ifdef NUTDEBUG        //DumpDnsHeader(doh);        //DumpDnsQuestion(doq);#endif
        /*         * Encode the header info into the packet buffer         * and send it to the DNS server.         */        len = EncodeDnsHeader(pkt, doh);        len += EncodeDnsQuestion(pkt + len, doq);
        if ((retries & 1) == 0 || confdns.doc_ip2 == 0) {            if (NutUdpSendTo(sock, confdns.doc_ip1, 53, pkt, len) < 0)                break;        } else {            if (NutUdpSendTo(sock, confdns.doc_ip2, 53, pkt, len) < 0)                break;        }
        /*         * Loop until we receive a response with the         * expected id or until timeout.         */        for (;;) {            len = 0;            n = NutUdpReceiveFrom(sock, &raddr, &rport, pkt, 512, 1000);            if (n <= 0)                break;            if (n > 12) {                len = DecodeDnsHeader(doh, pkt);#ifdef NUTDEBUG                //DumpDnsHeader(doh);#endif                if (doh->doh_id == id)                    break;            }        }
        /*         * Decode the answer.         */        if (len && doh->doh_quests == 1) {            len += DecodeDnsQuestion(doq, pkt + len);#ifdef NUTDEBUG            //DumpDnsQuestion(doq);#endif            if (doh->doh_answers < 1)                break;            else {                n_ip = 0;                for (n = 1; n <= (int) doh->doh_answers; n++) {                    dor = CreateDnsResource(dor);                    len += DecodeDnsResource(dor, pkt + len);#ifdef NUTDEBUG                    //DumpDnsResource(dor);#endif                    if (dor->dor_type == 1) {                        if (dor->dor_len == 4) {                            ip_all[n_ip] = *dor->dor_data;                            ip_all[n_ip] += (uint32_t) (*(dor->dor_data + 1)) << 8;                            ip_all[n_ip] += (uint32_t) (*(dor->dor_data + 2)) << 16;                            ip_all[n_ip] += (uint32_t) (*(dor->dor_data + 3)) << 24;                            n_ip++;                        }                    }                }                /*                 * _RCW_                 * Successfully acquired host names.                 * Break here so we don't send redundant requests.                 */                break;            }        }    }
    /*     * Clean up.     */    ReleaseDnsHeader(doh);    ReleaseDnsQuestion(doq);    ReleaseDnsResource(dor);
    NutHeapFree(pkt);    NutUdpDestroySocket(sock);
    return n_ip;}
Best regards,
Bob      From: Ole Reinhardt <ole.reinhardt at embedded-it.de>
 To: en-nut-discussion at egnite.de 
 Sent: Saturday, March 21, 2015 7:59 PM
 Subject: Re: [En-Nut-Discussion] UFLASH Write Appends Trash Data
   
Hi Bob,

Am 22.03.2015 00:47, schrieb Bob Wirka:
> Thank you for your reply.
> I have updated my svn version of the trunk from Source Forge.
> When you speak of the latest dataflash and uflash implementation, do you mean only "/dev/spi_flash_at45d.c" and "/fs/uflashfs.c"? Or are there other files that I should update?
> I see the checksum changes in the spi driver, and the memory leak fix in uflashfs.c. If it's only those two files, that would be great. With other files I see some new #defines that would have to get dragged in.
> Hope you're doing well, and thanks again for your help.

In general those two files and perhaps the header files as well.

But I would suggest to update everything, as I do not know if any
dependencies have changed as well. For example the support for the
select() function was introduced in some 5.x version. The select
function support added one entry to the NUTDEVICE struct.

Beside of these changes there have been a lot of improvements and
bugfixes since 4.10.x



Best regards,

Ole




-- 
kernel concepts GmbH            Tel: +49-271-771091-14
Sieghuetter Hauptweg 48        Mob: +49-177-7420433
D-57072 Siegen
http://www.embedded-it.de
http://www.kernelconcepts.de
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion


  


More information about the En-Nut-Discussion mailing list