-
Notifications
You must be signed in to change notification settings - Fork 4
/
poc-http-inetd.c
94 lines (76 loc) · 1.69 KB
/
poc-http-inetd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*C
(c) 2005 bl0rg.net
**/
#include "conf.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include "network.h"
#include "rtp.h"
/*M
\emph{Print a HTTP failure header to standard out.}
**/
static void pob_bad_request(unsigned long code,
const char *comment,
const char *msg) {
printf("HTTP/1.0 %lu %s\r\nConnection: close\r\n\r\n%s\r\n",
code, comment, msg);
}
int pob_http(void) {
}
/*M
\emph{Print usage information.}
**/
static void usage(void) {
fprintf(stderr, "Usage: ./pob [-s address] [-p port]\n");
fprintf(stderr, "\t-s address : destination address (default 224.0.1.23)\n");
fprintf(stderr, "\t-p port : destination port (default 1500)\n");
}
/*M
**/
int main(int argc, char *argv[]) {
int retval = EXIT_SUCCESS;
char *address = NULL;
int port = 1500;
address = strdup("224.0.1.23");
int c;
while ((c = getopt(argc, argv, "hs:p:")) >= 0) {
switch (c) {
case 's':
if (address != NULL)
free(address);
address = strdup(optarg);
break;
case 'p':
port = atoi(optarg);
break;
case 'h':
default:
usage();
retval = EXIT_FAILURE;
goto exit;
}
}
if (!pob_http()) {
retval = EXIT_FAILURE;
goto exit;
}
if ((sock = net_udp4_recv_socket(address, port)) < 0) {
fprintf(stderr, "Could not open socket\n");
retval = EXIT_FAILURE;
pob_bad_request(500, "Internal Server Error", "");
goto exit;
}
printf("HTTP/1.0 200 OK\r\n");
if (!pob_main(sock)) {
retval = EXIT_FAILURE;
goto exit;
}
exit:
if (address != NULL)
free(address);
return retval;
}
/*C
**/