reset optind before getopt() -- fixes 'make -k clean' failure
[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 *
5b519e94 5 * Redistribution and use in source and binary forms are permitted
50c7758a
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
5b519e94 16 *
22d9d71b 17 * @(#)raw_cb.c 7.10 (Berkeley) %G%
cb1c44c2 18 */
785d93ac 19
20666ad3
JB
20#include "param.h"
21#include "systm.h"
22#include "mbuf.h"
23#include "socket.h"
24#include "socketvar.h"
829f867e
MK
25#include "domain.h"
26#include "protosw.h"
20666ad3 27#include "errno.h"
f4d55810 28
20666ad3
JB
29#include "if.h"
30#include "route.h"
31#include "raw_cb.h"
9e9695c7 32#include "../netinet/in.h"
f4d55810 33
0e6c0944 34#include "machine/mtpr.h"
785d93ac
BJ
35
36/*
37 * Routines to manage the raw protocol control blocks.
38 *
39 * TODO:
40 * hash lookups by protocol family/protocol + address family
ee787340 41 * take care of unique address problems per AF?
1e25d807 42 * redo address binding to allow wildcards
785d93ac
BJ
43 */
44
73379934
MK
45u_long raw_sendspace = RAWSNDQ;
46u_long raw_recvspace = RAWRCVQ;
47
785d93ac
BJ
48/*
49 * Allocate a control block and a nominal amount
50 * of buffer space for the socket.
51 */
829f867e 52raw_attach(so, proto)
785d93ac 53 register struct socket *so;
829f867e 54 int proto;
785d93ac 55{
b72a6efb 56 register struct rawcb *rp = sotorawcb(so);
22d9d71b 57 int error;
785d93ac 58
b72a6efb
KS
59 /*
60 * It is assumed that raw_attach is called
61 * after space has been allocated for the
62 * rawcb.
63 */
64 if (rp == 0)
785d93ac 65 return (ENOBUFS);
22d9d71b
MK
66 if (error = soreserve(so, raw_sendspace, raw_recvspace))
67 return (error);
785d93ac 68 rp->rcb_socket = so;
829f867e
MK
69 rp->rcb_proto.sp_family = so->so_proto->pr_domain->dom_family;
70 rp->rcb_proto.sp_protocol = proto;
71 insque(rp, &rawcb);
785d93ac 72 return (0);
785d93ac
BJ
73}
74
75/*
76 * Detach the raw connection block and discard
77 * socket resources.
78 */
79raw_detach(rp)
80 register struct rawcb *rp;
81{
82 struct socket *so = rp->rcb_socket;
83
785d93ac
BJ
84 so->so_pcb = 0;
85 sofree(so);
86 remque(rp);
b72a6efb
KS
87#ifdef notdef
88 if (rp->rcb_laddr)
89 m_freem(dtom(rp->rcb_laddr));
90 rp->rcb_laddr = 0;
91#endif
92 free((caddr_t)(rp), M_PCB);
785d93ac
BJ
93}
94
95/*
96 * Disconnect and possibly release resources.
97 */
98raw_disconnect(rp)
99 struct rawcb *rp;
100{
4053be18 101
b72a6efb
KS
102#ifdef notdef
103 if (rp->rcb_faddr)
104 m_freem(dtom(rp->rcb_faddr));
105 rp->rcb_faddr = 0;
106#endif
f832270b 107 if (rp->rcb_socket->so_state & SS_NOFDREF)
785d93ac
BJ
108 raw_detach(rp);
109}
110
b72a6efb 111#ifdef notdef
14fa60f2
BJ
112raw_bind(so, nam)
113 register struct socket *so;
114 struct mbuf *nam;
115{
116 struct sockaddr *addr = mtod(nam, struct sockaddr *);
14fa60f2
BJ
117 register struct rawcb *rp;
118
119 if (ifnet == 0)
120 return (EADDRNOTAVAIL);
af0b24db 121 rp = sotorawcb(so);
b72a6efb
KS
122 nam = m_copym(nam, 0, M_COPYALL, M_WAITOK);
123 rp->rcb_laddr = mtod(nam, struct sockaddr *);
14fa60f2
BJ
124 return (0);
125}
b72a6efb 126#endif