aboutsummaryrefslogtreecommitdiffstats
path: root/c/wget.c
blob: 013b32689d4ec463b299d7837f8c202cd27602eb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "netlib.h"
/* wget URL : send the URL to the host gateway over SLIP, print the reply body.
   The gateway does the real DNS/TCP/HTTP and streams the body back as frames:
   each reply frame is 'D'<chunk>, ending with a single 'E' frame. */
void main(void) {
    char *argv[4];
    unsigned char argc = argv_parse(argv, 4);
    char buf[220];
    unsigned char len, i;
    if (argc < 1) { puts("usage: wget URL"); nl(); return; }
    slip_send(argv[0], strlen(argv[0]));
    for (;;) {
        len = slip_recv(buf, 219);
        if (len >= 1 && buf[0] == 'E') break;      /* end of stream */
        for (i = 1; i < len; i++) putc(buf[i]);    /* skip the 'D' type byte */
    }
    nl();
}