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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [tcpip/] [current/] [src/] [sys/] [kern/] [sys_socket.c] - Blame information for rev 786

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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