/[jscoverage]/trunk/tests/http-client-bad-url.c
ViewVC logotype

Annotation of /trunk/tests/http-client-bad-url.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 126 - (hide annotations)
Mon Jun 2 17:53:43 2008 UTC (11 years, 6 months ago) by siliconforks
File MIME type: text/plain
File size: 2069 byte(s)
Fixes for MinGW.

1 siliconforks 114 /*
2     http-client-bad-url.c - HTTP client that sends bad URLs
3     Copyright (C) 2008 siliconforks.com
4    
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9    
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     GNU General Public License for more details.
14    
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18     */
19    
20 siliconforks 126 #include <config.h>
21    
22 siliconforks 114 #include <assert.h>
23     #include <stdio.h>
24     #include <string.h>
25    
26 siliconforks 126 #include "http-server.h"
27 siliconforks 114 #include "util.h"
28    
29     int main(int argc, char ** argv) {
30 siliconforks 126 #ifdef __MINGW32__
31     WSADATA data;
32     if (WSAStartup(MAKEWORD(1, 1), &data) != 0) {
33     return 1;
34     }
35     #endif
36    
37 siliconforks 114 int result;
38    
39     if (argc < 3) {
40     fprintf(stderr, "Usage: %s PORT URL\n", argv[0]);
41     exit(EXIT_FAILURE);
42     }
43    
44     uint16_t connect_port = atoi(argv[1]);
45     char * url = argv[2];
46    
47     struct sockaddr_in a;
48     a.sin_family = AF_INET;
49     a.sin_port = htons(connect_port);
50     a.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
51    
52 siliconforks 126 SOCKET s = socket(PF_INET, SOCK_STREAM, 0);
53     assert(s != INVALID_SOCKET);
54 siliconforks 114
55     result = connect(s, (struct sockaddr *) &a, sizeof(a));
56     assert(result == 0);
57    
58     /* send request */
59     char * message;
60     xasprintf(&message, "GET %s HTTP/1.1\r\nConnection: close\r\n\r\n", url);
61     size_t message_length = strlen(message);
62     ssize_t bytes_sent = send(s, message, message_length, 0);
63     assert(bytes_sent == (ssize_t) message_length);
64    
65     /* read response */
66     for (;;) {
67     uint8_t buffer[8192];
68     ssize_t bytes_read = recv(s, buffer, 8192, 0);
69     assert(bytes_read >= 0);
70     if (bytes_read == 0) {
71     break;
72     }
73     }
74    
75 siliconforks 126 closesocket(s);
76 siliconforks 114 return 0;
77     }

  ViewVC Help
Powered by ViewVC 1.1.24