-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocker.c
103 lines (93 loc) · 3.24 KB
/
socker.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
95
96
97
98
99
100
101
102
103
/***********************************************************************
socker
a bunch of source addressing tcp/ip sockets.
Build
-----
Builds through cmake or from command line
To build from command line
/usr/bin/gcc -g -x c *.cpp -o socker
noticeably the link line does not work if the files are suffixed .c (rather than .cpp)
linker errors are undefined reference to sbind_usage and sbind.
using nm on the .o files did not indicate the root cause.
I assume that gcc behaves differently with .cpp vs. .c at the linker stage
or maybe at the compile stage. It could be an ordering issue of the.os
I tried forcing bind.o first but not last. Next step try that and
find out the detailed behaviour of gcc.
There is a very simple module called minimal.c which only builds on Linux.
it is a minimal sockets program that implements both server and client.
Usage
do ./acoker --usage to see usage
Currently
echo: is a listener that sends back messages - single client only
connect: is the client tht matches echo
proxy: can sit between server and client (single client only)
test: runs a set of self tests on the OneTimeBuffer mechanism
************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "rasocket.h"
#include "utils.h"
#include "send.h"
#include "echo.h"
#include "proxy.h"
#include "testOneTimeBuffer.h"
#include "testSessionHandler.h"
#include "multi_proxy.h"
#define USAGE_LEN 1024
#define NUM_ACTIONS 6
enum {NO_ACTION, SUCCESS, FAILURE};
int main(int argc, char **argv)
{
char usages[NUM_ACTIONS][USAGE_LEN];
int actionIdx = 0;
int result = NO_ACTION;
unsigned short port = 0;
char machine[ADDRESS_SIZE];
WINSOCK_START
if (ssend_usage(argc, argv, usages[actionIdx++], USAGE_LEN))
{
if (getHostAndPort(argc, argv, ARG_REMOTE_HOST, ARG_PORT, machine, ADDRESS_SIZE, &port))
{
result = ssend(machine, port) ? SUCCESS : FAILURE;
}
}
else if (secho_usage(argc, argv, usages[actionIdx++], USAGE_LEN))
{
if (getHostAndPort(argc, argv, ARG_REMOTE_HOST, ARG_PORT, machine, ADDRESS_SIZE, &port))
{
result = secho(machine, port) ? SUCCESS : FAILURE;
}
}
else if (sproxy_usage(argc, argv, usages[actionIdx++], USAGE_LEN))
{
result = sproxy(argc, argv) ? SUCCESS : FAILURE;
}
else if (smulti_proxy_usage(argc, argv, usages[actionIdx++], USAGE_LEN))
{
result = smulti_proxy(argc, argv) ? SUCCESS : FAILURE;
}
else if (testSessionHandler_usage(argc, argv, usages[actionIdx++], USAGE_LEN))
{
result = testSessionHandler() ? SUCCESS : FAILURE;
}
else if (testOneTimeBuffer_usage(argc, argv, usages[actionIdx++], USAGE_LEN))
{
result = testOneTimeBuffer() ? SUCCESS : FAILURE;
}
assert(actionIdx <= NUM_ACTIONS); // try to remember to up the number of actions
if ( result == NO_ACTION)
{
printf("usage:\n");
printf("%s", usages[0]);
printf("\n");
int ii; // max compatibility
for (ii = 1; ii < NUM_ACTIONS; ii++)
{
printf("or\n");
printf("%s", usages[ii]);
printf("\n");
}
}
exit(result != SUCCESS);
}