/* uipc_syscalls.c 4.3 81/11/16 */
#include "../h/protocol.h"
#include "../h/protosw.h"
#include "../h/socketvar.h"
#include "../net/inet_systm.h"
* Socket system call interface.
* These routines interface the socket routines to UNIX,
* isolating the system interface from the socket-protocol interface.
static struct in_addr localaddr
= { PF_LOCAL
};
* Pipe system call interface.
register struct file
*rf
, *wf
;
struct socket
*rso
, *wso
;
u
.u_error
= socket(&rso
, SOCK_STREAM
, &localaddr
, SO_ACCEPTCONN
);
u
.u_error
= socket(&wso
, SOCK_STREAM
, &localaddr
, 0);
rf
->f_flag
= FREAD
|FSOCKET
;
wf
->f_flag
= FWRITE
|FSOCKET
;
u
.u_r
.r_val2
= u
.u_r
.r_val1
;
if (pi_connect(rso
, wso
) == 0)
u
.u_ofile
[u
.u_r
.r_val1
] = 0;
* Splice system call interface.
} *ap
= (struct a
*)u
.u_ap
;
if ((f1
->f_flag
& FSOCKET
) == 0 || (f2
->f_flag
& FSOCKET
) == 0) {
if (f1
->f_count
> 1 || f2
->f_count
> 1) {
u
.u_error
= ETOOMANYREFS
;
u
.u_error
= pi_splice(f1
->f_socket
, f2
->f_socket
);
* Socket system call interface. Copy in arguments
* set up file descriptor and call internal socket
} *uap
= (struct a
*)u
.u_ap
;
register struct file
*fp
;
if ((fp
= falloc()) == NULL
)
fp
->f_flag
= FSOCKET
|FREAD
|FWRITE
;
if (copyin((caddr_t
)uap
->ain
, (caddr_t
)&in
, sizeof (in
))) {
u
.u_error
= socket(&so0
, uap
->type
, &in
, uap
->options
);
u
.u_ofile
[u
.u_r
.r_val1
] = 0;
* Connect socket to foreign peer; system call
* interface. Copy in arguments and call internal routine.
} *uap
= (struct a
*)u
.u_ap
;
register struct file
*fp
;
register struct socket
*so
;
if (copyin((caddr_t
)uap
->a
, (caddr_t
)&in
, sizeof (in
))) {
if ((fp
->f_flag
& FSOCKET
) == 0) {
u
.u_error
= connect(so
, &in
);
if ((so
->so_options
& SO_NBIO
) &&
(so
->so_state
& SS_ISCONNECTING
)) {
while ((so
->so_state
& SS_ISCONNECTING
) && so
->so_error
== 0)
sleep((caddr_t
)&so
->so_timeo
, PZERO
+1);
u
.u_error
= so
->so_error
;
* Disconnect socket from foreign peer; system call
* interface. Copy in arguments and call internal routine.
} *uap
= (struct a
*)u
.u_ap
;
register struct file
*fp
;
register struct socket
*so
;
copyin((caddr_t
)uap
->addr
, (caddr_t
)&in
, sizeof (in
))) {
if ((fp
->f_flag
& FSOCKET
) == 0) {
u
.u_error
= disconnect(so
, uap
->addr
? &in
: 0);
if ((so
->so_options
&SO_NBIO
) && (so
->so_state
&SS_ISDISCONNECTING
)) {
while (so
->so_state
& SS_ISDISCONNECTING
)
sleep((caddr_t
)&so
->so_timeo
, PZERO
+1);
u
.u_error
= so
->so_error
;
} *uap
= (struct a
*)u
.u_ap
;
register struct file
*fp
;
if ((fp
->f_flag
& FSOCKET
) == 0) {
if (useracc(uap
->cbuf
, uap
->count
, B_READ
) == 0 ||
uap
->ain
&& copyin((caddr_t
)uap
->ain
, (caddr_t
)&in
, sizeof (in
))) {
u
.u_error
= send(fp
->f_socket
, uap
->ain
? &in
: 0);
* Receive data on socket.
} *uap
= (struct a
*)u
.u_ap
;
register struct file
*fp
;
if ((fp
->f_flag
& FSOCKET
) == 0) {
if (useracc(uap
->cbuf
, uap
->count
, B_WRITE
) == 0 ||
uap
->ain
&& copyin((caddr_t
)uap
->ain
, (caddr_t
)&in
, sizeof (in
))) {
receive(fp
->f_socket
, uap
->ain
? &in
: 0);