File: socket.c

package info (click to toggle)
ibcs 971113-3
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 1,108 kB
  • ctags: 2,061
  • sloc: ansic: 14,910; makefile: 280; sh: 203; asm: 47; perl: 18; pascal: 2
file content (194 lines) | stat: -rw-r--r-- 4,383 bytes parent folder | download | duplicates (2)
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
/*
 *  linux/ibcs/socket.c
 *
 *  Copyright (C) 1994, 1996  Mike Jagdis (jaggy@purplet.demon.co.uk)
 *
 * $Id: socket.c,v 1.7 1996/03/29 17:33:33 mike Exp $
 * $Source: /usr/CVS/ibcs/iBCSemul/socket.c,v $
 */

#include <linux/config.h>

#include <linux/module.h>
#include <linux/version.h>

#include <asm/segment.h>
#ifndef KERNEL_DS
#include <linux/segment.h>
#endif

#include <linux/types.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/ptrace.h>
#include <linux/net.h>
#include <linux/socket.h>
#include <linux/sys.h>

#include <ibcs/ibcs.h>
#include <ibcs/socket.h>
#include <ibcs/map.h>
#include <ibcs/trace.h>


int
ibcs_setsockopt(unsigned long *sp)
{
	int error;
	int level, optname;

	error = verify_area(VERIFY_READ,
			((unsigned long *)sp),
			5*sizeof(long));
	if (error)
		return error;

	level = (int)get_fs_long(((unsigned long *)sp)+1);
	optname = (int)get_fs_long(((unsigned long *)sp)+2);

	switch (level) {
		case 0xffff:
			put_fs_long(SOL_SOCKET, ((unsigned long *)sp)+1);
			optname = map_value(sopt_map, optname, 0);
			put_fs_long(optname, ((unsigned long *)sp)+2);

			switch (optname) {
				/* The following are not currently implemented
				 * under Linux so we must fake them in
				 * reasonable ways. (Only SO_PROTOTYPE is
				 * documented in SCO's man page).
				 */
				case SO_PROTOTYPE:
				case SO_ORDREL:
				case SO_SNDTIMEO:
				case SO_RCVTIMEO:
					return -ENOPROTOOPT;

				case SO_USELOOPBACK:
				case SO_SNDLOWAT:
				case SO_RCVLOWAT:
					return 0;

				/* The following are not currenty implemented
				 * under Linux and probably aren't settable
				 * anyway.
				 */
				case SO_IMASOCKET:
					return -ENOPROTOOPT;
			}

		default:
			/* FIXME: We assume everything else uses the
			 * same level and option numbers. This is true
			 * for IPPROTO_TCP(/SOL_TCP) and TCP_NDELAY
			 * but is known to be incorrect for other
			 * potential options :-(.
			 */
			break;
	}

	return SYS(socketcall)(SYS_SETSOCKOPT, sp);
}


int
ibcs_getsockopt(unsigned long *sp)
{
	int error;
	int level, optname;
	char *optval;
	long *optlen;

	error = verify_area(VERIFY_READ,
			((unsigned long *)sp),
			5*sizeof(long));
	if (error)
		return error;

	level = (int)get_fs_long(((unsigned long *)sp)+1);
	optname = (int)get_fs_long(((unsigned long *)sp)+2);
	optval = (char *)get_fs_long(((unsigned long *)sp)+3);
	optlen = (long *)get_fs_long(((unsigned long *)sp)+4);

#ifdef IBCS_TRACE
	if ((ibcs_trace & (TRACE_STREAMS|TRACE_SOCKSYS))) {
		printk(KERN_DEBUG "iBCS: getsockopt level=%d, "
			"optname=%d, optval=0x%08lx, optlen=0x%08lx\n",
			level, optname, (unsigned long)optval,
			(unsigned long)optlen);
	}
#endif

	switch (level) {
		case 0xffff:
			put_fs_long(SOL_SOCKET, ((unsigned long *)sp)+1);
			optname = map_value(sopt_map, optname, 0);
			put_fs_long(optname, ((unsigned long *)sp)+2);

			switch (optname) {
				/* The following are not currently implemented
				 * under Linux so we must fake them in
				 * reasonable ways. (Only SO_PROTOTYPE is
				 * documented in SCO's man page).
				 */
				case SO_PROTOTYPE: {
					error = verify_area(VERIFY_WRITE,
							(char *)optlen,
							sizeof(long));
					if (error)
						return error;
					if (get_fs_long(optlen) < sizeof(long))
						return -EINVAL;

					error = verify_area(VERIFY_WRITE,
							(char *)optval,
							sizeof(long));
					if (!error) {
						put_fs_long(0, optval);
						put_fs_long(sizeof(long),
							optlen);
					}
					return error;
				}

				case SO_ORDREL:
				case SO_SNDTIMEO:
				case SO_RCVTIMEO:
					return -ENOPROTOOPT;

				case SO_USELOOPBACK:
				case SO_SNDLOWAT:
				case SO_RCVLOWAT:
				case SO_IMASOCKET: {
					error = verify_area(VERIFY_WRITE,
							(char *)optlen,
							sizeof(long));
					if (error)
						return error;
					if (get_fs_long(optlen) < sizeof(long))
						return -EINVAL;

					error = verify_area(VERIFY_WRITE,
							(char *)optval,
							sizeof(long));
					if (!error) {
						put_fs_long(1, optval);
						put_fs_long(sizeof(long),
							optlen);
					}
					return error;
				}
			}

		default:
			/* FIXME: We assume everything else uses the
			 * same level and option numbers. This is true
			 * for IPPROTO_TCP(/SOL_TCP) and TCP_NDELAY
			 * but is known to be incorrect for other
			 * potential options :-(.
			 */
			break;
	}

	return SYS(socketcall)(SYS_GETSOCKOPT, sp);
}