]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/ddp_proto.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1988, 1989, 1997, 1998 Apple Computer, Inc.
31 * Modified for MP, 1996 by Tuyen Nguyen
32 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
35 /* ddp_proto.c: 2.0, 1.23; 10/18/93; Apple Computer, Inc. */
37 #include <sys/errno.h>
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <machine/spl.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
44 #include <sys/filedesc.h>
45 #include <sys/fcntl.h>
47 #include <sys/ioctl.h>
48 #include <sys/malloc.h>
49 #include <sys/socket.h>
50 #include <sys/socketvar.h>
54 #include <netat/sysglue.h>
55 #include <netat/appletalk.h>
56 #include <netat/at_pcb.h>
57 #include <netat/at_var.h>
58 #include <netat/ddp.h>
59 #include <netat/zip.h>
61 extern at_ifaddr_t
*ifID_home
;
63 void ddp_putmsg(gref
, mp
)
67 register ioc_t
*iocbp
;
71 switch(gbuf_type(mp
)) {
73 /* If this message is going out on a socket that's not bound,
76 ddp
= (at_ddp_t
*)gbuf_rptr(mp
);
77 if ((ddp
->type
== DDP_ATP
) || (ddp
->type
== DDP_ADSP
)) {
78 if ((gref
== 0) || (gref
->lport
== 0)) {
79 int src_addr_included
=
80 ((ddp
->type
==DDP_ATP
) && ddp
->src_node
)? 1 : 0;
81 (void)ddp_output(&mp
, ddp
->src_socket
,
87 if ((gref
== 0) || (gref
->lport
== 0)) {
90 atalk_notify(gref
, ENOTCONN
);
93 if ((error
= ddp_output(&mp
, gref
->lport
, 0)) != 0) {
95 atalk_notify(gref
, error
);
100 iocbp
= (ioc_t
*)gbuf_rptr(mp
);
101 if (DDP_IOC_MYIOCTL(iocbp
->ioc_cmd
)) {
102 switch(iocbp
->ioc_cmd
) {
103 case DDP_IOC_GET_CFG
:
104 /* Note that DDP_IOC_GET_CFG / AppleTalk ddp_config()
105 fills in the net and node of the ddp_addr_t param
106 with the net and node of the default interface,
107 not the net and node that has been bound, as
108 getsockname() and sockopt DDP_GETSOCKNAME do.
110 #ifdef APPLETALK_DEBUG
111 kprintf("ddp_putmsg: DDP_IOC_GET_CFG\n");
114 gbuf_freem(gbuf_cont(mp
));
116 gbuf_alloc(sizeof(ddp_addr_t
),
118 ioc_ack(ENOBUFS
, mp
, gref
);
122 /* *** was ddp_get_cfg() *** */
124 (ddp_addr_t
*)gbuf_rptr(gbuf_cont(mp
));
125 cfgp
->inet
.net
= ifID_home
->ifThisNode
.s_net
;
126 cfgp
->inet
.node
= ifID_home
->ifThisNode
.s_node
;
128 cfgp
->inet
.net
= gref
->laddr
.s_net
;
129 cfgp
->inet
.node
= gref
->laddr
.s_node
;
131 cfgp
->inet
.socket
= gref
->lport
;
132 cfgp
->ddptype
= gref
->ddptype
;
134 gbuf_wset(gbuf_cont(mp
), sizeof(ddp_addr_t
));
135 iocbp
->ioc_count
= sizeof(ddp_addr_t
);
136 ioc_ack(0, mp
, gref
);
139 ioc_ack(EINVAL
, mp
, gref
);
144 ioc_ack(EINVAL
, mp
, gref
);
148 #ifdef APPLETALK_DEBUG
149 kprintf("unexpected message type in ddp_putmsg: %d/n",
158 gbuf_t
*ddp_compress_msg(mp
)
161 register gbuf_t
*tmp
;
163 while (gbuf_len(mp
) == 0) {