Subversion Repositories SvarDOS

Rev

Rev 336 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 336 Rev 338
1
/*
1
/*
2
 * pkgnet - pulls SvarDOS packages from the project's online repository
2
 * pkgnet - pulls SvarDOS packages from the project's online repository
3
 * Copyright (C) 2021 Mateusz Viste
3
 * Copyright (C) 2021 Mateusz Viste
4
 *
4
 *
5
 * PUBLISHED UNDER THE TERMS OF THE MIT LICENSE
5
 * PUBLISHED UNDER THE TERMS OF THE MIT LICENSE
6
 *
6
 *
7
 * COPYRIGHT (C) 2016-2021 MATEUSZ VISTE, ALL RIGHTS RESERVED.
7
 * COPYRIGHT (C) 2016-2021 MATEUSZ VISTE, ALL RIGHTS RESERVED.
8
 *
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a
9
 * Permission is hereby granted, free of charge, to any person obtaining a
10
 * copy of this software and associated documentation files (the "Software"),
10
 * copy of this software and associated documentation files (the "Software"),
11
 * to deal in the Software without restriction, including without limitation
11
 * to deal in the Software without restriction, including without limitation
12
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13
 * and/or sell copies of the Software, and to permit persons to whom the
13
 * and/or sell copies of the Software, and to permit persons to whom the
14
 * Software is furnished to do so, subject to the following conditions:
14
 * Software is furnished to do so, subject to the following conditions:
15
 *
15
 *
16
 * The above copyright notice and this permission notice shall be included in
16
 * The above copyright notice and this permission notice shall be included in
17
 * all copies or substantial portions of the Software.
17
 * all copies or substantial portions of the Software.
18
 *
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25
 * DEALINGS IN THE SOFTWARE.
25
 * DEALINGS IN THE SOFTWARE.
26
 *
26
 *
27
 * http://svardos.osdn.io
27
 * http://svardos.osdn.io
28
 */
28
 */
29
 
29
 
30
#include <stdio.h>
30
#include <stdio.h>
31
#include <stdlib.h>
31
#include <stdlib.h>
32
#include <string.h>
32
#include <string.h>
33
#include <time.h>
33
#include <time.h>
34
 
34
 
35
#include "net.h"
35
#include "net.h"
36
 
36
 
37
#define PVER "20210514"
37
#define PVER "20210520"
38
#define PDATE "2021"
38
#define PDATE "2021"
39
 
39
 
40
#define HOSTADDR "svardos.osdn.io"
40
#define HOSTADDR "svardos.osdn.io"
41
 
41
 
42
 
42
 
43
/* strips http headers and returns new buff len */
43
/* returns length of all http headers, or 0 if uncomplete yet */
44
static int detecthttpheadersend(unsigned char *buff, int len) {
44
static unsigned short detecthttpheadersend(const unsigned char *buff) {
45
  static char lastbyteislf = 0; /* static because I must potentially remember it for next packet/call */
45
  char lastbyteislf = 0;
46
  int i;
46
  unsigned short i;
47
  for (i = 0; i < len; i++) {
47
  for (i = 0; buff[i] != 0; i++) {
48
    if (buff[i] == '\r') continue; /* ignore CR characters */
48
    if (buff[i] == '\r') continue; /* ignore CR characters */
49
    if (buff[i] != '\n') {
49
    if (buff[i] != '\n') {
50
      lastbyteislf = 0;
50
      lastbyteislf = 0;
51
      continue;
51
      continue;
52
    }
52
    }
53
    /* cur byte is LF -> if last one was also LF then this is an empty line, meaning headers are over */
53
    /* cur byte is LF -> if last one was also LF then this is an empty line, meaning headers are over */
54
    if (lastbyteislf == 0) {
54
    if (lastbyteislf == 0) {
55
      lastbyteislf = 1;
55
      lastbyteislf = 1;
56
      continue;
56
      continue;
57
    }
57
    }
58
    /* end of headers! rewind the buffer and return new len */
58
    /* end of headers! return length of headers */
59
    i += 1; /* add 1 to skip the current \n character */
59
    return(i + 1); /* add 1 to skip the current \n character */
60
    len -= i;
-
 
61
    if (len > 0) memmove(buff, buff + i, len + 1); /* +1 so I catch the string terminator as well */
-
 
62
    return(len);
-
 
63
  }
60
  }
64
  return(0);
61
  return(0);
65
}
62
}
66
 
63
 
67
 
64
 
68
static void help(void) {
65
static void help(void) {
69
  puts("pkgnet ver " PVER " -- Copyright (C) " PDATE " Mateusz Viste");
66
  puts("pkgnet ver " PVER " -- Copyright (C) " PDATE " Mateusz Viste");
70
  puts("");
67
  puts("");
71
  puts("pkgnet is the SvarDOS package downloader.");
68
  puts("pkgnet is the SvarDOS package downloader.");
72
  puts("");
69
  puts("");
73
  puts("usage:  pkgnet search <term>");
70
  puts("usage:  pkgnet search <term>");
74
  puts("        pkgnet pull <package>");
71
  puts("        pkgnet pull <package>");
75
  puts("        pkgnet checkup");
72
  puts("        pkgnet checkup");
76
  puts("");
73
  puts("");
77
  puts("actions:");
74
  puts("actions:");
78
  puts(" search   - asks remote repository for the list of matching packages");
75
  puts(" search   - asks remote repository for the list of matching packages");
79
  puts(" pull     - downloads package into current directory");
76
  puts(" pull     - downloads package into current directory");
80
  puts(" checkup  - lists updates available for your system");
77
  puts(" checkup  - lists updates available for your system");
81
  puts("");
78
  puts("");
82
}
79
}
83
 
80
 
84
 
81
 
85
/* parses command line arguments and fills outfname and url accordingly
82
/* parses command line arguments and fills outfname and url accordingly
86
 * returns 0 on success, non-zero otherwise */
83
 * returns 0 on success, non-zero otherwise */
87
static int parseargv(int argc, char * const *argv, char *outfname, char *url) {
84
static int parseargv(int argc, char * const *argv, char *outfname, char *url) {
88
  *outfname = 0;
85
  *outfname = 0;
89
  *url = 0;
86
  *url = 0;
90
  if ((argc == 3) && (strcasecmp(argv[1], "search") == 0)) {
87
  if ((argc == 3) && (strcasecmp(argv[1], "search") == 0)) {
91
    sprintf(url, "/repo/?a=search&p=%s", argv[2]);
88
    sprintf(url, "/repo/?a=search&p=%s", argv[2]);
92
  } else if ((argc == 3) && (strcasecmp(argv[1], "pull") == 0)) {
89
  } else if ((argc == 3) && (strcasecmp(argv[1], "pull") == 0)) {
93
    if ((strlen(argv[2]) > 8) || (argv[2][0] == 0)) {
90
    if ((strlen(argv[2]) > 8) || (argv[2][0] == 0)) {
94
      puts("ERROR: package name must be 8 characters maximum");
91
      puts("ERROR: package name must be 8 characters maximum");
95
      return(-1);
92
      return(-1);
96
    }
93
    }
97
    sprintf(url, "/repo/?a=pull&p=%s", argv[2]);
94
    sprintf(url, "/repo/?a=pull&p=%s", argv[2]);
98
    sprintf(outfname, "%s.zip", argv[2]);
95
    sprintf(outfname, "%s.zip", argv[2]);
99
  } else if ((argc == 2) && (strcasecmp(argv[1], "checkup") == 0)) {
96
  } else if ((argc == 2) && (strcasecmp(argv[1], "checkup") == 0)) {
100
    puts("NOT SUPPORTED YET");
97
    puts("NOT SUPPORTED YET");
101
    return(-1);
98
    return(-1);
102
  } else {
99
  } else {
103
    help();
100
    help();
104
    return(-1);
101
    return(-1);
105
  }
102
  }
106
  return(0);
103
  return(0);
107
}
104
}
108
 
105
 
109
 
106
 
-
 
107
static int htget_headers(unsigned char *buffer, size_t buffersz, struct net_tcpsocket *sock, int *httpcode)  {
-
 
108
  unsigned char *buffptr = buffer;
-
 
109
  unsigned short bufflen = 0;
-
 
110
  int byteread;
-
 
111
  time_t starttime = time(NULL);
-
 
112
  for (;;) {
-
 
113
    byteread = net_recv(sock, buffptr, buffersz - (bufflen + 1)); /* -1 because I will append a NULL terminator */
-
 
114
 
-
 
115
    if (byteread > 0) { /* got data */
-
 
116
      int hdlen;
-
 
117
      bufflen += byteread;
-
 
118
      buffptr += byteread;
-
 
119
      buffer[bufflen] = 0;
-
 
120
      hdlen = detecthttpheadersend(buffer);
-
 
121
      if (hdlen > 0) { /* full headers - parse http code and continue processing */
-
 
122
        int spc;
-
 
123
        /* find the first space (HTTP/1.1 200 OK) */
-
 
124
        for (spc = 0; spc < 16; spc++) {
-
 
125
          if (buffer[spc] == ' ') break;
-
 
126
          if (buffer[spc] == 0) break;
-
 
127
        }
-
 
128
        if (buffer[spc] != ' ') return(-1);
-
 
129
        *httpcode = atoi((char *)(buffer + spc + 1));
-
 
130
        /* rewind the buffer */
-
 
131
        bufflen -= hdlen;
-
 
132
        memmove(buffer, buffer + hdlen, bufflen);
-
 
133
        return(bufflen); /* move to body processing now */
-
 
134
      }
-
 
135
 
-
 
136
    } else if (byteread < 0) { /* abort on error */
-
 
137
      return(-2); /* unexpected end of connection (while waiting for all http headers) */
-
 
138
 
-
 
139
    } else { /* else no data received - look for timeout and release a cpu cycle */
-
 
140
      if (time(NULL) - starttime > 20) return(-3); /* TIMEOUT! */
-
 
141
      _asm int 28h; /* release a CPU cycle */
-
 
142
    }
-
 
143
  }
-
 
144
}
-
 
145
 
-
 
146
 
110
/* fetch http data from ipaddr using url
147
/* fetch http data from ipaddr using url
111
 * write result to file outfname if not null, or print to stdout otherwise
148
 * write result to file outfname if not null, or print to stdout otherwise
112
 * fills bsum with the BSD sum of the data
149
 * fills bsum with the BSD sum of the data
113
 * returns the length of data obtained, or neg value on error */
150
 * returns the length of data obtained, or neg value on error */
114
static long htget(const char *ipaddr, const char *url, const char *outfname, unsigned short *bsum) {
151
static long htget(const char *ipaddr, const char *url, const char *outfname, unsigned short *bsum) {
115
  struct net_tcpsocket *sock;
152
  struct net_tcpsocket *sock;
116
  unsigned char buffer[4096];
153
  unsigned char buffer[4096];
117
  time_t lastactivity, lastprogressoutput = 0;
154
  time_t lastactivity, lastprogressoutput = 0;
118
  int headersdone = 0;
-
 
119
  int httpcode = -1;
155
  int httpcode = -1;
-
 
156
  int byteread;
120
  long flen = 0, lastflen = 0;
157
  long flen = 0, lastflen = 0;
121
  FILE *fd = NULL;
158
  FILE *fd = NULL;
122
 
159
 
123
  sock = net_connect(ipaddr, 80);
160
  sock = net_connect(ipaddr, 80);
124
  if (sock == NULL) {
161
  if (sock == NULL) {
125
    puts("ERROR: failed to connect to " HOSTADDR);
162
    puts("ERROR: failed to connect to " HOSTADDR);
126
    goto SHITQUIT;
163
    goto SHITQUIT;
127
  }
164
  }
128
 
165
 
129
  /* wait for net_connect() to actually connect */
166
  /* wait for net_connect() to actually connect */
130
  for (;;) {
167
  for (;;) {
131
    int connstate = net_isconnected(sock);
168
    int connstate = net_isconnected(sock);
132
    if (connstate > 0) break;
169
    if (connstate > 0) break;
133
    if (connstate < 0) {
170
    if (connstate < 0) {
134
      puts("ERROR: connection error");
171
      puts("ERROR: connection error");
135
      goto SHITQUIT;
172
      goto SHITQUIT;
136
    }
173
    }
137
    _asm int 28h;  /* DOS idle */
174
    _asm int 28h;  /* DOS idle */
138
  }
175
  }
139
 
176
 
140
  /* socket is connected - send the http request (MUST be HTTP/1.0 because I do not support chunked transfers!) */
177
  /* socket is connected - send the http request (MUST be HTTP/1.0 because I do not support chunked transfers!) */
141
  snprintf((char *)buffer, sizeof(buffer), "GET %s HTTP/1.0\r\nHOST: " HOSTADDR "\r\nUSER-AGENT: pkgnet\r\nConnection: close\r\n\r\n", url);
178
  snprintf((char *)buffer, sizeof(buffer), "GET %s HTTP/1.0\r\nHOST: " HOSTADDR "\r\nUSER-AGENT: pkgnet\r\nConnection: close\r\n\r\n", url);
142
 
179
 
143
  if (net_send(sock, buffer, strlen((char *)buffer)) != (int)strlen((char *)buffer)) {
180
  if (net_send(sock, buffer, strlen((char *)buffer)) != (int)strlen((char *)buffer)) {
144
    puts("ERROR: failed to send HTTP query to remote server");
181
    puts("ERROR: failed to send HTTP query to remote server");
145
    goto SHITQUIT;
182
    goto SHITQUIT;
146
  }
183
  }
147
 
184
 
148
  lastactivity = time(NULL);
185
  /* receive and process HTTP headers */
149
  for (;;) {
-
 
150
    int byteread = net_recv(sock, buffer, sizeof(buffer) - 1); /* -1 because I will append a NULL terminator */
186
  byteread = htget_headers(buffer, sizeof(buffer), sock, &httpcode);
151
 
187
 
-
 
188
  /* transmission error? */
-
 
189
  if (byteread < 0) {
152
    if (byteread < 0) break; /* end of connection */
190
    printf("ERROR: communication error (%d)", byteread);
-
 
191
    puts("");
-
 
192
    goto SHITQUIT;
-
 
193
  }
153
 
194
 
154
    /*  */
-
 
155
    if (byteread == 0) {
-
 
156
      if (time(NULL) - lastactivity > 20) { /* TIMEOUT! */
195
  /* open destination file if required and if no server-side error occured */
157
        puts("ERROR: Timeout while waiting for data");
196
  if ((httpcode == 200) && (*outfname != 0)) {
158
        goto SHITQUIT;
197
    fd = fopen(outfname, "wb");
159
      }
198
    if (fd == NULL) {
160
      /* waiting for packets - release a CPU cycle in the meantime */
199
      printf("ERROR: failed to create file %s", outfname);
161
      _asm int 28h;
-
 
162
      /* */
200
      puts("");
163
      continue;
201
      goto SHITQUIT;
164
    }
202
    }
-
 
203
  }
-
 
204
 
-
 
205
  /* read body of the answer */
-
 
206
  lastactivity = time(NULL);
-
 
207
  for (;; byteread = net_recv(sock, buffer, sizeof(buffer) - 1)) { /* read 1 byte less because I need to append a NULL terminator */
165
 
208
 
166
    if (byteread > 0) {
209
    if (byteread > 0) { /* got data */
167
      buffer[byteread] = 0;
210
      buffer[byteread] = 0;
168
      lastactivity = time(NULL);
211
      lastactivity = time(NULL);
169
      /* are headers done already? */
-
 
170
      if (headersdone == 0) {
-
 
171
        if (httpcode < 0) { /* do I know the http code yet? */
-
 
172
          int spc;
-
 
173
          /* find the first space (HTTP/1.1 200 OK) */
-
 
174
          for (spc = 0; spc < 16; spc++) {
-
 
175
            if (buffer[spc] == ' ') break;
-
 
176
            if (buffer[spc] == 0) break;
-
 
177
          }
-
 
178
          if (buffer[spc] == 0) continue; /* not enough data received */
-
 
179
          if (buffer[spc] != ' ') {
-
 
180
            puts("ERROR: server answered with invalid HTTP");
-
 
181
            goto SHITQUIT;
-
 
182
          }
-
 
183
          httpcode = atoi((char *)(buffer + spc + 1));
-
 
184
          /* on error, the answer should be always printed on screen */
-
 
185
          if ((httpcode == 200) && (*outfname != 0)) {
-
 
186
            fd = fopen(outfname, "wb");
-
 
187
            if (fd == NULL) {
-
 
188
              printf("ERROR: failed to create file %s", outfname);
-
 
189
              puts("");
-
 
190
              goto SHITQUIT;
-
 
191
            }
-
 
192
          }
-
 
193
        }
-
 
194
        /* skip headers: look for \r\n\r\n or \n\n within the stream */
-
 
195
        byteread = detecthttpheadersend(buffer, byteread);
-
 
196
        headersdone = 1; /* assumes ALL headers are contained in the first packet TODO FIXME */
-
 
197
        if (byteread == 0) continue;
-
 
198
      }
-
 
199
      /* if downloading to file, write stuff to disk */
212
      /* if downloading to file, write stuff to disk */
200
      if (fd != NULL) {
213
      if (fd != NULL) {
201
        int i;
214
        int i;
202
        if (fwrite(buffer, 1, byteread, fd) != byteread) {
215
        if (fwrite(buffer, 1, byteread, fd) != byteread) {
203
          printf("ERROR: failed to write data to file %s after %ld bytes", outfname, flen);
216
          printf("ERROR: failed to write data to file %s after %ld bytes", outfname, flen);
204
          puts("");
217
          puts("");
205
          break;
218
          break;
206
        }
219
        }
207
        flen += byteread;
220
        flen += byteread;
208
        /* update progress once a sec */
221
        /* update progress once a sec */
209
        if (lastprogressoutput != lastactivity) {
222
        if (lastprogressoutput != lastactivity) {
210
          lastprogressoutput = lastactivity;
223
          lastprogressoutput = lastactivity;
211
          printf("%ld KiB (%ld KiB/s)     \r", flen >> 10, (flen >> 10) - (lastflen >> 10)); /* trailing spaces are meant to avoid leaving garbage on screen if speed goes from, say, 1000 KiB/s to 9 KiB/s */
224
          printf("%ld KiB (%ld KiB/s)     \r", flen >> 10, (flen >> 10) - (lastflen >> 10)); /* trailing spaces are meant to avoid leaving garbage on screen if speed goes from, say, 1000 KiB/s to 9 KiB/s */
212
          lastflen = flen;
225
          lastflen = flen;
213
          fflush(stdout); /* avoid console buffering */
226
          fflush(stdout); /* avoid console buffering */
214
        }
227
        }
215
        /* update the bsd sum */
228
        /* update the bsd sum */
216
        for (i = 0; i < byteread; i++) {
229
        for (i = 0; i < byteread; i++) {
217
          /* rotr16 */
230
          /* rotr16 */
218
          unsigned short bsumlsb = *bsum & 1;
231
          unsigned short bsumlsb = *bsum & 1;
219
          *bsum >>= 1;
232
          *bsum >>= 1;
220
          *bsum |= (bsumlsb << 15);
233
          *bsum |= (bsumlsb << 15);
221
          *bsum += buffer[i];
234
          *bsum += buffer[i];
222
        }
235
        }
223
      } else { /* otherwise dump to screen */
236
      } else { /* otherwise dump to screen */
224
        printf("%s", buffer);
237
        printf("%s", buffer);
225
      }
238
      }
-
 
239
 
-
 
240
    } else if (byteread < 0) { /* end of connection */
-
 
241
      break;
-
 
242
 
-
 
243
    } else { /* check for timeout (byteread == 0) */
-
 
244
      if (time(NULL) - lastactivity > 20) { /* TIMEOUT! */
-
 
245
        puts("ERROR: Timeout while waiting for data");
-
 
246
        goto SHITQUIT;
-
 
247
      }
-
 
248
      /* waiting for packets - release a CPU cycle in the meantime */
-
 
249
      _asm int 28h;
226
    }
250
    }
227
  }
251
  }
228
  net_close(sock);
-
 
-
 
252
 
229
  return(flen);
253
  goto ALLGOOD;
230
 
254
 
231
  SHITQUIT:
255
  SHITQUIT:
-
 
256
  flen = -1;
-
 
257
 
-
 
258
  ALLGOOD:
-
 
259
  if (fd != NULL) fclose(fd);
232
  net_close(sock);
260
  net_close(sock);
233
  return(-1);
261
  return(flen);
234
}
262
}
235
 
263
 
236
 
264
 
237
/* checks if file exists, returns 0 if not, non-zero otherwise */
265
/* checks if file exists, returns 0 if not, non-zero otherwise */
238
static int fexists(const char *fname) {
266
static int fexists(const char *fname) {
239
  FILE *fd = fopen(fname, "rb");
267
  FILE *fd = fopen(fname, "rb");
240
  if (fd == NULL) return(0);
268
  if (fd == NULL) return(0);
241
  fclose(fd);
269
  fclose(fd);
242
  return(1);
270
  return(1);
243
}
271
}
244
 
272
 
245
 
273
 
246
int main(int argc, char **argv) {
274
int main(int argc, char **argv) {
247
  char ipaddr[64];
275
  char ipaddr[64];
248
  char url[64];
276
  char url[64];
249
  unsigned short bsum = 0;
277
  unsigned short bsum = 0;
250
  char outfname[16];
278
  char outfname[16];
251
  long flen;
279
  long flen;
252
 
280
 
253
  /* parse command line arguments */
281
  /* parse command line arguments */
254
  if (parseargv(argc, argv, outfname, url) != 0) return(1);
282
  if (parseargv(argc, argv, outfname, url) != 0) return(1);
255
 
283
 
256
  /* if outfname requested, make sure that file does not exist yet */
284
  /* if outfname requested, make sure that file does not exist yet */
257
  if (fexists(outfname)) {
285
  if (fexists(outfname)) {
258
    printf("ERROR: file %s already exists", outfname);
286
    printf("ERROR: file %s already exists", outfname);
259
    puts("");
287
    puts("");
260
    return(1);
288
    return(1);
261
  }
289
  }
262
 
290
 
263
  /* init network stack */
291
  /* init network stack */
264
  if (net_init() != 0) {
292
  if (net_init() != 0) {
265
    puts("ERROR: Network subsystem initialization failed");
293
    puts("ERROR: Network subsystem initialization failed");
266
    return(1);
294
    return(1);
267
  }
295
  }
268
 
296
 
269
  puts(""); /* required because watt-32 likes to print out garbage sometimes ("configuring through DHCP...") */
297
  puts(""); /* required because watt-32 likes to print out garbage sometimes ("configuring through DHCP...") */
270
 
298
 
271
  if (net_dnsresolve(ipaddr, HOSTADDR) != 0) {
299
  if (net_dnsresolve(ipaddr, HOSTADDR) != 0) {
272
    puts("ERROR: DNS resolution failed");
300
    puts("ERROR: DNS resolution failed");
273
    return(1);
301
    return(1);
274
  }
302
  }
275
 
303
 
276
  flen = htget(ipaddr, url, outfname, &bsum);
304
  flen = htget(ipaddr, url, outfname, &bsum);
277
  if (flen < 1) return(1);
305
  if (flen < 1) return(1);
278
 
306
 
279
  if (*outfname != 0) {
307
  if (*outfname != 0) {
280
    /* print bsum, size, filename */
308
    /* print bsum, size, filename */
281
    printf("Downloaded %ld KiB into %s (BSUM: %04X)", flen >> 10, outfname, bsum);
309
    printf("Downloaded %ld KiB into %s (BSUM: %04X)", flen >> 10, outfname, bsum);
282
    puts("");
310
    puts("");
283
  }
311
  }
284
 
312
 
285
  return(0);
313
  return(0);
286
}
314
}
287
 
315