File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / miniupnpc / testminiwget.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Mon Jul 22 00:36:10 2013 UTC (10 years, 10 months ago) by misho
Branches: miniupnpc, elwix, MAIN
CVS tags: v1_8p0, v1_8, HEAD
1.8

    1: /* $Id: testminiwget.c,v 1.1.1.2 2013/07/22 00:36:10 misho Exp $ */
    2: /* Project : miniupnp
    3:  * Author : Thomas Bernard
    4:  * Copyright (c) 2005-2012 Thomas Bernard
    5:  * This software is subject to the conditions detailed in the
    6:  * LICENCE file provided in this distribution.
    7:  * */
    8: #include <stdio.h>
    9: #include <stdlib.h>
   10: #include "miniwget.h"
   11: 
   12: /**
   13:  * This program uses the miniwget / miniwget_getaddr function
   14:  * from miniwget.c in order to retreive a web ressource using
   15:  * a GET HTTP method, and store it in a file.
   16:  */
   17: int main(int argc, char * * argv)
   18: {
   19: 	void * data;
   20: 	int size, writtensize;
   21: 	FILE *f;
   22: 	char addr[64];
   23: 
   24: 	if(argc < 3) {
   25: 		fprintf(stderr, "Usage:\t%s url file\n", argv[0]);
   26: 		fprintf(stderr, "Example:\t%s http://www.google.com/ out.html\n", argv[0]);
   27: 		return 1;
   28: 	}
   29: 	data = miniwget_getaddr(argv[1], &size, addr, sizeof(addr), 0);
   30: 	if(!data) {
   31: 		fprintf(stderr, "Error fetching %s\n", argv[1]);
   32: 		return 1;
   33: 	}
   34: 	printf("local address : %s\n", addr);
   35: 	printf("got %d bytes\n", size);
   36: 	f = fopen(argv[2], "wb");
   37: 	if(!f) {
   38: 		fprintf(stderr, "Cannot open file %s for writing\n", argv[2]);
   39: 		free(data);
   40: 		return 1;
   41: 	}
   42: 	writtensize = fwrite(data, 1, size, f);
   43: 	if(writtensize != size) {
   44: 		fprintf(stderr, "Could only write %d bytes out of %d to %s\n",
   45: 		        writtensize, size, argv[2]);
   46: 	} else {
   47: 		printf("%d bytes written to %s\n", writtensize, argv[2]);
   48: 	}
   49: 	fclose(f);
   50: 	free(data);
   51: 	return 0;
   52: }
   53: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>