summaryrefslogtreecommitdiff
path: root/lib/kernel/test/inet_sockopt_SUITE_data/sockopt_helper.c
blob: fb3c622909cfe3c211ee271ff7f364326877ebaf (plain)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#if defined(VXWORKS) || defined(__OSE__)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int sockopt_helper(void){
    return 0;
}
#else

#if defined(__WIN32__)
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <windows.h>
#include <process.h>
#include <stdio.h>
#include <stdlib.h>

#else /* Unix */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#ifdef HAVE_LINUX_TCP_H
#ifdef HAVE_SANE_LINUX_TCP_H
#include <linux/tcp.h>
#endif
#endif
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>
#include <signal.h>

#endif

#define C_GET_IPPROTO_TCP          1
#define C_GET_IPPROTO_IP           2
#define C_GET_SOL_SOCKET           3
#define C_GET_SOL_IP               4

#define C_GET_TCP_KEEPIDLE        11
#define C_GET_TCP_LINGER2         12
#define C_GET_TCP_INFO            13
#define C_GET_SO_REUSEADDR        14
#define C_GET_SO_KEEPALIVE        15
#define C_GET_SO_LINGER           16

#define C_GET_LINGER_SIZE         21
#define C_GET_TCP_INFO_SIZE       22

#define C_GET_OFF_LINGER_L_ONOFF  31
#define C_GET_OFF_LINGER_L_LINGER 32
#define C_GET_OFF_TCPI_SACKED     33
#define C_GET_OFF_TCPI_OPTIONS    34

#define C_GET_SIZ_LINGER_L_ONOFF  41
#define C_GET_SIZ_LINGER_L_LINGER 42
#define C_GET_SIZ_TCPI_SACKED     43
#define C_GET_SIZ_TCPI_OPTIONS    44

#define C_QUIT                    99

int get_command(void)
{
    char buff[256];
    int res;
    if (fgets(buff,256,stdin) == NULL)
	exit(1);
    sscanf(buff,"%d",&res);
    return res;
}

void put_answer(int x)
{
    printf("%d\n",x);
}

int main(void){
    int x;
    int res;
    setbuf(stdin,NULL);
    setbuf(stdout,NULL);
    do {
	x = get_command();

	switch(x) {
#ifdef IPPROTO_TCP
	case C_GET_IPPROTO_TCP: 
	    res = IPPROTO_TCP;
	    break;        
#endif
#ifdef IPPROTO_IP
	case C_GET_IPPROTO_IP: 
	    res = IPPROTO_IP;
	    break;         
#endif
#ifdef SOL_SOCKET
	case C_GET_SOL_SOCKET: 
	    res = SOL_SOCKET;
	    break;
#endif         
#ifdef SOL_IP
	case C_GET_SOL_IP : 
	    res = SOL_IP;
	    break;            
#endif
#ifdef TCP_KEEPIDLE	    
	case C_GET_TCP_KEEPIDLE: 
	    res = TCP_KEEPIDLE;
	    break;       
#endif
#ifdef TCP_LINGER2
	case C_GET_TCP_LINGER2: 
	    res = TCP_LINGER2;
	    break;        
#endif
#ifdef TCP_INFO
	case C_GET_TCP_INFO: 
	    res = TCP_INFO;
	    break;         
#endif
#ifdef SO_REUSEADDR  
	case C_GET_SO_REUSEADDR: 
	    res = SO_REUSEADDR;
	    break;       
#endif
#ifdef SO_KEEPALIVE
	case C_GET_SO_KEEPALIVE: 
	    res = SO_KEEPALIVE;
	    break;       
#endif
#ifdef SO_LINGER
	case C_GET_SO_LINGER: 
	    res = SO_LINGER;
	    break;          
#endif
#ifdef SO_LINGER
	case C_GET_LINGER_SIZE: 
	    res = sizeof(struct linger);
	    break;        
#endif
#if defined(TCP_INFO) && defined(HAVE_LINUX_TCP_H)
	case C_GET_TCP_INFO_SIZE: 
	    res = sizeof(struct tcp_info);
	    break;      
#endif
#ifdef SO_LINGER
	case C_GET_OFF_LINGER_L_ONOFF:
	    {
		struct linger l;
		res = ((char *) &(l.l_onoff)) - ((char *) &l);
	    }
	    break; 
	case C_GET_OFF_LINGER_L_LINGER: 
	    {
		struct linger l;
		res = ((char *) &(l.l_linger)) - ((char *) &l);
	    }
	    break;
#endif
#if defined(TCP_INFO) && defined(HAVE_LINUX_TCP_H)
	case C_GET_OFF_TCPI_SACKED: 
	    {
		struct tcp_info ti;
		res = ((char *) &(ti.tcpi_sacked)) - ((char *) &(ti));
	    }
	    break;    
	case C_GET_OFF_TCPI_OPTIONS: 
	    {
		struct tcp_info ti;
		res = ((char *) &(ti.tcpi_options)) - ((char *) &(ti));
	    }
	    break;   
#endif
#ifdef SO_LINGER
	case C_GET_SIZ_LINGER_L_ONOFF: 
	    {
		struct linger l;
		res = sizeof(l.l_onoff);
	    }
	    break; 
	case C_GET_SIZ_LINGER_L_LINGER: 
	    {
		struct linger l;
		res = sizeof(l.l_linger);
	    }
	    break;
#endif
#if defined(TCP_INFO) && defined(HAVE_LINUX_TCP_H)
	case C_GET_SIZ_TCPI_SACKED: 
	    {
		struct tcp_info ti;
		res = sizeof(ti.tcpi_sacked);
	    }
	    break;    
	case C_GET_SIZ_TCPI_OPTIONS: 
	    {
		struct tcp_info ti;
		res = sizeof(ti.tcpi_options);
	    }
	    break;   
#endif
	case C_QUIT:
	    res = 0;
	    break;
	default:
	    res = -1;
	}
	put_answer(res);
    } while (x != C_QUIT);
    return 0;
}
#endif