- Always check if the file descriptor we are using is a socket.

- Make sure we get an so_internal state allocated, even if we
  did not open the socket ourselves.
This commit is contained in:
christos 1996-06-05 19:07:37 +00:00
parent 29811afbb6
commit dd1fe33d2e
2 changed files with 34 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: svr4_net.c,v 1.9 1996/04/11 12:52:41 christos Exp $ */
/* $NetBSD: svr4_net.c,v 1.10 1996/06/05 19:07:37 christos Exp $ */
/*
* Copyright (c) 1994 Christos Zoulas
@ -43,6 +43,8 @@
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/protosw.h>
#include <sys/domain.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sys/proc.h>
@ -107,7 +109,6 @@ svr4_netopen(dev, flag, mode, p)
struct socket *so;
int error;
int family;
struct svr4_strm *st;
DPRINTF(("netopen("));
@ -178,12 +179,9 @@ svr4_netopen(dev, flag, mode, p)
fp->f_type = DTYPE_SOCKET;
fp->f_ops = &svr4_netops;
st = malloc(sizeof(struct svr4_strm), M_NETADDR, M_WAITOK);
/* XXX: This is unused; ask for a field and make this legal */
st->s_family = family;
so->so_internal = st;
st->s_cmd = ~0;
fp->f_data = (caddr_t)so;
(void) svr4_stream_get(fp);
DPRINTF(("ok);\n"));
p->p_dupfd = fd;
@ -200,3 +198,29 @@ svr4_soo_close(fp, p)
free(so->so_internal, M_NETADDR);
return soo_close(fp, p);
}
struct svr4_strm *
svr4_stream_get(fp)
struct file *fp;
{
struct socket *so;
struct svr4_strm *st;
if (fp == NULL || fp->f_type != DTYPE_SOCKET)
return NULL;
so = (struct socket *) fp->f_data;
if (so->so_internal)
return so->so_internal;
/* Allocate a new one. */
fp->f_ops = &svr4_netops;
st = malloc(sizeof(struct svr4_strm), M_NETADDR, M_WAITOK);
st->s_family = so->so_proto->pr_domain->dom_family;
st->s_cmd = ~0;
so->so_internal = st;
return st;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: svr4_stropts.h,v 1.6 1996/04/11 12:50:31 christos Exp $ */
/* $NetBSD: svr4_stropts.h,v 1.7 1996/06/05 19:07:38 christos Exp $ */
/*
* Copyright (c) 1994 Christos Zoulas
@ -129,4 +129,6 @@ struct svr4_netaddr_un {
#define SVR4_ADDROF(sc) (void *) (((char *) (sc)) + (sc)->offs)
struct svr4_strm *svr4_stream_get __P((struct file *fp));
#endif /* !_SVR4_STROPTS */