OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [ecos-2.0/] [packages/] [net/] [tcpip/] [v2_0/] [src/] [sys/] [kern/] [sys_socket.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1254 phoenix
//==========================================================================
2
//
3
//      sys/kern/sys_socket.c
4
//
5
//     
6
//
7
//==========================================================================
8
//####BSDCOPYRIGHTBEGIN####
9
//
10
// -------------------------------------------
11
//
12
// Portions of this software may have been derived from OpenBSD or other sources,
13
// and are covered by the appropriate copyright disclaimers included herein.
14
//
15
// -------------------------------------------
16
//
17
//####BSDCOPYRIGHTEND####
18
//==========================================================================
19
//#####DESCRIPTIONBEGIN####
20
//
21
// Author(s):    gthomas
22
// Contributors: gthomas
23
// Date:         2000-01-10
24
// Purpose:      
25
// Description:  
26
//              
27
//
28
//####DESCRIPTIONEND####
29
//
30
//==========================================================================
31
 
32
 
33
/*      $OpenBSD: sys_socket.c,v 1.3 1997/08/31 20:42:23 deraadt Exp $  */
34
/*      $NetBSD: sys_socket.c,v 1.13 1995/08/12 23:59:09 mycroft Exp $  */
35
 
36
/*
37
 * Copyright (c) 1982, 1986, 1990, 1993
38
 *      The Regents of the University of California.  All rights reserved.
39
 *
40
 * Redistribution and use in source and binary forms, with or without
41
 * modification, are permitted provided that the following conditions
42
 * are met:
43
 * 1. Redistributions of source code must retain the above copyright
44
 *    notice, this list of conditions and the following disclaimer.
45
 * 2. Redistributions in binary form must reproduce the above copyright
46
 *    notice, this list of conditions and the following disclaimer in the
47
 *    documentation and/or other materials provided with the distribution.
48
 * 3. All advertising materials mentioning features or use of this software
49
 *    must display the following acknowledgement:
50
 *      This product includes software developed by the University of
51
 *      California, Berkeley and its contributors.
52
 * 4. Neither the name of the University nor the names of its contributors
53
 *    may be used to endorse or promote products derived from this software
54
 *    without specific prior written permission.
55
 *
56
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66
 * SUCH DAMAGE.
67
 *
68
 *      @(#)sys_socket.c        8.1 (Berkeley) 6/10/93
69
 */
70
 
71
#include <sys/param.h>
72
#ifdef __ECOS
73
#include <cyg/io/file.h>
74
#else
75
#include <sys/systm.h>
76
#include <sys/file.h>
77
#include <sys/proc.h>
78
#endif
79
#include <sys/mbuf.h>
80
#include <sys/protosw.h>
81
#include <sys/socket.h>
82
#include <sys/socketvar.h>
83
#include <sys/ioctl.h>
84
#ifndef __ECOS
85
#include <sys/stat.h>
86
#endif
87
 
88
#include <net/if.h>
89
#include <net/route.h>
90
 
91
struct  fileops socketops =
92
    { soo_read, soo_write, soo_ioctl, soo_select, soo_close };
93
 
94
#ifdef __ECOS
95
/* ARGSUSED */
96
int
97
soo_read(struct file *fp, struct uio *uio)
98
#else
99
/* ARGSUSED */
100
int
101
soo_read(fp, uio, cred)
102
        struct file *fp;
103
        struct uio *uio;
104
        struct ucred *cred;
105
#endif
106
{
107
 
108
        return (soreceive((struct socket *)fp->f_data, (struct mbuf **)0,
109
                uio, (struct mbuf **)0, (struct mbuf **)0, (int *)0));
110
}
111
 
112
#ifdef __ECOS
113
int
114
soo_write(struct file *fp, struct uio *uio)
115
#else
116
/* ARGSUSED */
117
int
118
soo_write(fp, uio, cred)
119
        struct file *fp;
120
        struct uio *uio;
121
        struct ucred *cred;
122
#endif
123
{
124
 
125
        return (sosend((struct socket *)fp->f_data, (struct mbuf *)0,
126
                uio, (struct mbuf *)0, (struct mbuf *)0, 0));
127
}
128
 
129
#ifdef __ECOS
130
int
131
soo_ioctl(struct file *fp, CYG_ADDRWORD cmd, CYG_ADDRWORD data)
132
#else
133
int
134
soo_ioctl(fp, cmd, data, p)
135
        struct file *fp;
136
        u_long cmd;
137
        register caddr_t data;
138
        struct proc *p;
139
#endif
140
{
141
        register struct socket *so = (struct socket *)fp->f_data;
142
#ifdef __ECOS
143
        void *p = 0;
144
#endif
145
 
146
        switch (cmd) {
147
 
148
        case FIONBIO:
149
                if (*(int *)data)
150
                        so->so_state |= SS_NBIO;
151
                else
152
                        so->so_state &= ~SS_NBIO;
153
                return (0);
154
 
155
        case FIOASYNC:
156
                if (*(int *)data) {
157
                        so->so_state |= SS_ASYNC;
158
                        so->so_rcv.sb_flags |= SB_ASYNC;
159
                        so->so_snd.sb_flags |= SB_ASYNC;
160
                } else {
161
                        so->so_state &= ~SS_ASYNC;
162
                        so->so_rcv.sb_flags &= ~SB_ASYNC;
163
                        so->so_snd.sb_flags &= ~SB_ASYNC;
164
                }
165
                return (0);
166
 
167
        case FIONREAD:
168
                *(int *)data = so->so_rcv.sb_cc;
169
                return (0);
170
 
171
#ifndef __ECOS
172
        case SIOCSPGRP:
173
                so->so_pgid = *(int *)data;
174
                so->so_siguid = p->p_cred->p_ruid;
175
                so->so_sigeuid = p->p_ucred->cr_uid;
176
                return (0);
177
 
178
        case SIOCGPGRP:
179
                *(int *)data = so->so_pgid;
180
                return (0);
181
#endif
182
 
183
        case SIOCATMARK:
184
                *(int *)data = (so->so_state&SS_RCVATMARK) != 0;
185
                return (0);
186
        }
187
        /*
188
         * Interface/routing/protocol specific ioctls:
189
         * interface and routing ioctls should have a
190
         * different entry since a socket's unnecessary
191
         */
192
        if (IOCGROUP(cmd) == 'i')
193
                return (ifioctl(so, (u_long)cmd, (caddr_t)data, p));
194
        if (IOCGROUP(cmd) == 'r')
195
                return (rtioctl((u_long)cmd, (caddr_t)data, p));
196
        return ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
197
            (struct mbuf *)cmd, (struct mbuf *)data, (struct mbuf *)0));
198
}
199
 
200
#ifdef __ECOS
201
int
202
soo_select(struct file *fp, int which)
203
#else
204
int
205
soo_select(fp, which, p)
206
        struct file *fp;
207
        int which;
208
        struct proc *p;
209
#endif
210
{
211
        register struct socket *so = (struct socket *)fp->f_data;
212
        register int s = splsoftnet();
213
#ifdef __ECOS
214
        void *p = 0;
215
#endif
216
 
217
        switch (which) {
218
 
219
        case FREAD:
220
                if (soreadable(so)) {
221
                        splx(s);
222
                        return (1);
223
                }
224
                selrecord(p, &so->so_rcv.sb_sel);
225
                so->so_rcv.sb_flags |= SB_SEL;
226
                break;
227
 
228
        case FWRITE:
229
                if (sowriteable(so)) {
230
                        splx(s);
231
                        return (1);
232
                }
233
                selrecord(p, &so->so_snd.sb_sel);
234
                so->so_snd.sb_flags |= SB_SEL;
235
                break;
236
 
237
        case 0:
238
                if (so->so_oobmark || (so->so_state & SS_RCVATMARK)) {
239
                        splx(s);
240
                        return (1);
241
                }
242
                selrecord(p, &so->so_rcv.sb_sel);
243
                so->so_rcv.sb_flags |= SB_SEL;
244
                break;
245
        }
246
        splx(s);
247
        return (0);
248
}
249
 
250
#ifndef __ECOS
251
int
252
soo_stat(so, ub)
253
        register struct socket *so;
254
        register struct stat *ub;
255
{
256
 
257
        bzero((caddr_t)ub, sizeof (*ub));
258
        ub->st_mode = S_IFSOCK;
259
        return ((*so->so_proto->pr_usrreq)(so, PRU_SENSE,
260
            (struct mbuf *)ub, (struct mbuf *)0,
261
            (struct mbuf *)0));
262
}
263
#endif
264
 
265
#ifdef __ECOS
266
int
267
soo_close(struct file *fp)
268
#else
269
/* ARGSUSED */
270
int
271
soo_close(fp, p)
272
        struct file *fp;
273
        struct proc *p;
274
#endif
275
{
276
        int error = 0;
277
 
278
        if (fp->f_data)
279
                error = soclose((struct socket *)fp->f_data);
280
        fp->f_data = 0;
281
        return (error);
282
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.