AW: [En-Nut-Discussion] I: Problem GETting a binary file via HTTP

Ernst Stippl ernst at stippl.org
Sat Sep 23 13:36:44 CEST 2006


Hi Paolo!

I downloaded the ledblink.bin file using IE and had Ethereal running to
capture the LAN traffic. At offset 0x8c, the first hex value 0x0A appears in
the file and at 0x9c, the first 0x00 byte.

You could run the download both to a PC and to Ethernut, having Ethereal
capturing both sessions and compare the data streams. This way, you can make
sure that the data arriving at the Ethernut is REALLY the same as arriving
on the PC. If that is the case, the prob is somewhere "in" the
Ethernut SW. If the streams are different, maybe the "GET" from the Ethernut
if different from the "GET" a PC is issuing.

regards
Ernst
-----Ursprüngliche Nachricht-----
Von: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de] Im Auftrag von paolo
Gesendet: Mittwoch, 20. September 2006 10:56
An: en-nut-discussion at egnite.de
Betreff: [En-Nut-Discussion] I: Problem GETting a binary file via HTTP

Hi all,
 
I am experimenting proglems while downloading a simple binary file from an
HTTP server. I used the inetq example and GET method to download file
"ledblink.bin" from a server, while dumping it to serial port, and capturing
with a terminal program for checkout.
 
The url of my file is
amelia.dei.unipd.it/plc/fw/ledblink.bin
 
(I downloaded it with mozilla and it's OK).
 
After some 0x8C bytes the two files start to differ. It seems like 0x0A in
original file gets always an 0x0D appended, and I never get a 0x00 from
serial output, instead I get a 0x20.
 
I opened both input stream and serial in binary mode....I seems like fread
(AND/OR) fwrite corrupt the binary data.
 
The code I use to download my file .bin:
 
 
/*
 * Main application routine. 
 *
 */
int main(void)
{
    u_long baud = 115200;
    TCPSOCKET *sock;
    FILE *stream;
    u_long rip;
    u_long ip_addr;
    int bite;
    size_t rc;
    size_t len;
    u_long start_time;
    u_long total_bytes;
 
 
      buf = malloc(2048);
 
 
 
      int j;
    /*
     * Initialize the uart device.
     */
    NutRegisterDevice(&DEV_DEBUG, 0, 0);
    freopen(DEV_DEBUG_NAME, "w+b", stdout);
    _ioctl(_fileno(stdout), UART_SETSPEED, &baud);
    puts("\nInetQuery 1.0");
 
    /*
     * Register Realtek controller at address 8300 hex and interrupt 5.
     */
    puts("Configuring Ethernet interface");
    NutRegisterDevice(&DEV_ETHER, 0, 0);
 
    /*
     * Try DHCP. First use MAC from EEPROM.
     */
    if (NutDhcpIfConfig("eth0", 0, 60000) && NutDhcpIfConfig("eth0", my_mac,
60000)) {
        /*
         * No DHCP server available. Use hard coded values.
         */
        ip_addr = inet_addr(MY_IP);
        NutNetIfConfig("eth0", my_mac, ip_addr, inet_addr(MY_MASK));
        NutIpRouteAdd(0, 0, inet_addr(MY_GATE), &DEV_ETHER);
        NutDnsConfig(0, 0, inet_addr(DNSSERVERIP));
    } else
        ip_addr = confnet.cdn_ip_addr;
    printf("%s ready\n", inet_ntoa(ip_addr));
 
 
    /*
     * Resolve hostname using DNS.
     */
    if ((rip = NutDnsGetHostByName(INETSERVER)) != 0) {
      
        /*
         * Let's try a stdio stream first.
         */
        if ((sock = NutTcpCreateSocket()) != 0) {
 
            /*
             * Connect a HTTP server in the Internet.
             */
            printf("Connecting %s:%u\r\n", inet_ntoa(rip), INETSERVERPORT);
            if (NutTcpConnect(sock, rip, INETSERVERPORT) == 0) {
 
                /*
                 * Assign a stream to our connected socket.
                 */
                if ((stream = _fdopen((int) sock, "rb")) != 0) {
                    /*
                     * Send HTTP request to the server.
                     */
                    fprintf(stream, "GET %s HTTP/1.0\r\n", INETURL);
                    fputs("User-Agent: Ethernut [en] (NutOS)\r\n", stream);
                    fputs("\r\n", stream);
                    fflush(stream);
 
                    /*
                     * Init measure values.
                     */
                    start_time = NutGetTickCount();
                    total_bytes = 0;
 
                    /*
                     * Read server response and send it to the UART.
                     */
                     int k = 1;
                    while (fgets(buff, sizeof(buff), stream)) {
////                    printf ("%04d(%d): ", k++, strlen(buff));
puts(buff);
 
                        total_bytes += strlen(buff);
                        if (strlen(buff) == 2)
                        {
                             char c;
                        //   2 Newline found, start of binary data
                        //    while ((c = fgetc(stream)) != EOF) putc(c,
stdout);  
                              uint16_t tc;
                              while ((tc = fgetc(stream)) != EOF)
                              putc (tc, stdout);
                        }
                    }
                    printf("Transfered %lu bytes in %lu seconds\n",
total_bytes, (NutGetTickCount() - start_time) / 16UL);
                    fclose(stream);
                } else
                    puts("Creating stream device failed");
 
            } else {
                printf("Bad news, %s refuses the connection.\n",
INETSERVER);
            }
            printf("Disconnecting %s:%u\n", inet_ntoa(rip), INETSERVERPORT);
            NutTcpCloseSocket(sock);
        }
        
        NutSleep(5000);
        
    } else
        printf("Great news, %s has been removed!\n", INETSERVER);
 
    for (;;)
        NutSleep(1000);
}
 
 
Am I doing something wrong ?
 
Thanks, regards
 
Paolo
 
P.S. I enclose the incriminated file, both downloaded via Mozilla (OK) and
downloaded via Ethernut/Serial port (not OK), together with Ethernut source
 
 
 
_______________________________________________
En-Nut-Discussion mailing list
En-Nut-Discussion at egnite.de
http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.12.5/451 - Release Date: 19.09.2006



-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.12.6/453 - Release Date: 20.09.2006





More information about the En-Nut-Discussion mailing list