note semi-working version with only listen and bind changes
[unix-history] / usr / src / sys / net / raw_cb.c
CommitLineData
cb1c44c2 1/*
1810611d 2 * Copyright (c) 1980, 1986 Regents of the University of California.
5b519e94 3 * All rights reserved.
cb1c44c2 4 *
dbf0c423 5 * %sccs.include.redist.c%
5b519e94 6 *
dbf0c423 7 * @(#)raw_cb.c 7.11 (Berkeley) %G%
cb1c44c2 8 */
785d93ac 9
20666ad3
JB
10#include "param.h"
11#include "systm.h"
12#include "mbuf.h"
13#include "socket.h"
14#include "socketvar.h"
829f867e
MK
15#include "domain.h"
16#include "protosw.h"
20666ad3 17#include "errno.h"
f4d55810 18
20666ad3
JB
19#include "if.h"
20#include "route.h"
21#include "raw_cb.h"
9e9695c7 22#include "../netinet/in.h"
f4d55810 23
0e6c0944 24#include "machine/mtpr.h"
785d93ac
BJ
25
26/*
27 * Routines to manage the raw protocol control blocks.
28 *
29 * TODO:
30 * hash lookups by protocol family/protocol + address family
ee787340 31 * take care of unique address problems per AF?
1e25d807 32 * redo address binding to allow wildcards
785d93ac
BJ
33 */
34
73379934
MK
35u_long raw_sendspace = RAWSNDQ;
36u_long raw_recvspace = RAWRCVQ;
37
785d93ac
BJ
38/*
39 * Allocate a control block and a nominal amount
40 * of buffer space for the socket.
41 */
829f867e 42raw_attach(so, proto)
785d93ac 43 register struct socket *so;
829f867e 44 int proto;
785d93ac 45{
b72a6efb 46 register struct rawcb *rp = sotorawcb(so);
22d9d71b 47 int error;
785d93ac 48
b72a6efb
KS
49 /*
50 * It is assumed that raw_attach is called
51 * after space has been allocated for the
52 * rawcb.
53 */
54 if (rp == 0)
785d93ac 55 return (ENOBUFS);
22d9d71b
MK
56 if (error = soreserve(so, raw_sendspace, raw_recvspace))
57 return (error);
785d93ac 58 rp->rcb_socket = so;
829f867e
MK
59 rp->rcb_proto.sp_family = so->so_proto->pr_domain->dom_family;
60 rp->rcb_proto.sp_protocol = proto;
61 insque(rp, &rawcb);
785d93ac 62 return (0);
785d93ac
BJ
63}
64
65/*
66 * Detach the raw connection block and discard
67 * socket resources.
68 */
69raw_detach(rp)
70 register struct rawcb *rp;
71{
72 struct socket *so = rp->rcb_socket;
73
785d93ac
BJ
74 so->so_pcb = 0;
75 sofree(so);
76 remque(rp);
b72a6efb
KS
77#ifdef notdef
78 if (rp->rcb_laddr)
79 m_freem(dtom(rp->rcb_laddr));
80 rp->rcb_laddr = 0;
81#endif
82 free((caddr_t)(rp), M_PCB);
785d93ac
BJ
83}
84
85/*
86 * Disconnect and possibly release resources.
87 */
88raw_disconnect(rp)
89 struct rawcb *rp;
90{
4053be18 91
b72a6efb
KS
92#ifdef notdef
93 if (rp->rcb_faddr)
94 m_freem(dtom(rp->rcb_faddr));
95 rp->rcb_faddr = 0;
96#endif
f832270b 97 if (rp->rcb_socket->so_state & SS_NOFDREF)
785d93ac
BJ
98 raw_detach(rp);
99}
100
b72a6efb 101#ifdef notdef
14fa60f2
BJ
102raw_bind(so, nam)
103 register struct socket *so;
104 struct mbuf *nam;
105{
106 struct sockaddr *addr = mtod(nam, struct sockaddr *);
14fa60f2
BJ
107 register struct rawcb *rp;
108
109 if (ifnet == 0)
110 return (EADDRNOTAVAIL);
af0b24db 111 rp = sotorawcb(so);
b72a6efb
KS
112 nam = m_copym(nam, 0, M_COPYALL, M_WAITOK);
113 rp->rcb_laddr = mtod(nam, struct sockaddr *);
14fa60f2
BJ
114 return (0);
115}
b72a6efb 116#endif