]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
de355530 A |
6 | * The contents of this file constitute Original Code as defined in and |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
1c79356b | 11 | * |
de355530 A |
12 | * This Original Code and all software distributed under the License are |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
de355530 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
1c79356b A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * Copyright (c) 1988, 1989, 1997, 1998 Apple Computer, Inc. | |
24 | * | |
25 | * Modified for MP, 1996 by Tuyen Nguyen | |
26 | * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX. | |
27 | */ | |
28 | ||
29 | /* ddp_proto.c: 2.0, 1.23; 10/18/93; Apple Computer, Inc. */ | |
30 | ||
31 | #include <sys/errno.h> | |
32 | #include <sys/types.h> | |
33 | #include <sys/param.h> | |
34 | #include <machine/spl.h> | |
35 | #include <sys/systm.h> | |
36 | #include <sys/kernel.h> | |
37 | #include <sys/proc.h> | |
38 | #include <sys/filedesc.h> | |
39 | #include <sys/fcntl.h> | |
40 | #include <sys/mbuf.h> | |
41 | #include <sys/ioctl.h> | |
42 | #include <sys/malloc.h> | |
43 | #include <sys/socket.h> | |
44 | #include <sys/socketvar.h> | |
45 | #include <sys/buf.h> | |
46 | ||
47 | #include <net/if.h> | |
48 | ||
49 | #include <netat/sysglue.h> | |
50 | #include <netat/appletalk.h> | |
51 | #include <netat/at_var.h> | |
52 | #include <netat/ddp.h> | |
53 | #include <netat/zip.h> | |
54 | #include <netat/at_pcb.h> | |
55 | ||
56 | extern at_ifaddr_t *ifID_home; | |
57 | ||
58 | void ddp_putmsg(gref, mp) | |
59 | gref_t *gref; | |
60 | gbuf_t *mp; | |
61 | { | |
62 | u_char socket; | |
63 | register ioc_t *iocbp; | |
64 | register int error; | |
65 | at_ddp_t *ddp; | |
66 | ||
67 | switch(gbuf_type(mp)) { | |
68 | case MSG_DATA : | |
69 | /* If this message is going out on a socket that's not bound, | |
70 | * nail it. | |
71 | */ | |
72 | ddp = (at_ddp_t *)gbuf_rptr(mp); | |
73 | if ((ddp->type == DDP_ATP) || (ddp->type == DDP_ADSP)) { | |
74 | if ((gref == 0) || (gref->lport == 0)) { | |
75 | int src_addr_included = | |
76 | ((ddp->type==DDP_ATP) && ddp->src_node)? 1 : 0; | |
77 | (void)ddp_output(&mp, ddp->src_socket, | |
78 | src_addr_included); | |
79 | return; | |
80 | } | |
81 | } | |
82 | ||
83 | if (gref && (gref->lport == 0)) { | |
84 | gbuf_freel(mp); | |
85 | atalk_notify(gref, ENOTCONN); | |
86 | return; | |
87 | } | |
88 | if ((error = ddp_output(&mp, gref->lport, 0)) != 0) { | |
89 | if (gref) | |
90 | atalk_notify(gref, error); | |
91 | } | |
92 | return; | |
93 | ||
94 | case MSG_IOCTL : | |
95 | iocbp = (ioc_t *)gbuf_rptr(mp); | |
96 | if (DDP_IOC_MYIOCTL(iocbp->ioc_cmd)) { | |
97 | switch(iocbp->ioc_cmd) { | |
98 | case DDP_IOC_GET_CFG : | |
99 | /* Note that DDP_IOC_GET_CFG / AppleTalk ddp_config() | |
100 | fills in the net and node of the ddp_addr_t param | |
101 | with the net and node of the default interface, | |
102 | not the net and node that has been bound, as | |
103 | getsockname() and sockopt DDP_GETSOCKNAME do. | |
104 | */ | |
105 | #ifdef APPLETALK_DEBUG | |
106 | kprintf("ddp_putmsg: DDP_IOC_GET_CFG\n"); | |
107 | #endif | |
108 | if (gbuf_cont(mp)) | |
109 | gbuf_freem(gbuf_cont(mp)); | |
110 | if ((gbuf_cont(mp) = | |
9bccf70c | 111 | gbuf_alloc(sizeof(ddp_addr_t), |
1c79356b A |
112 | PRI_MED)) == NULL) { |
113 | ioc_ack(ENOBUFS, mp, gref); | |
114 | break; | |
115 | } | |
116 | { | |
117 | /* *** was ddp_get_cfg() *** */ | |
118 | ddp_addr_t *cfgp = | |
119 | (ddp_addr_t *)gbuf_rptr(gbuf_cont(mp)); | |
120 | cfgp->inet.net = ifID_home->ifThisNode.s_net; | |
121 | cfgp->inet.node = ifID_home->ifThisNode.s_node; | |
122 | #ifdef NOT_YET | |
123 | cfgp->inet.net = gref->laddr.s_net; | |
124 | cfgp->inet.node = gref->laddr.s_node; | |
125 | #endif | |
126 | cfgp->inet.socket = gref->lport; | |
127 | cfgp->ddptype = gref->ddptype; | |
128 | } | |
129 | gbuf_wset(gbuf_cont(mp), sizeof(ddp_addr_t)); | |
130 | iocbp->ioc_count = sizeof(ddp_addr_t); | |
131 | ioc_ack(0, mp, gref); | |
132 | break; | |
133 | default: | |
134 | ioc_ack(EINVAL, mp, gref); | |
135 | break; | |
136 | } | |
137 | } else { | |
138 | /* Unknown ioctl */ | |
139 | ioc_ack(EINVAL, mp, gref); | |
140 | } | |
141 | break; | |
142 | default : | |
143 | #ifdef APPLETALK_DEBUG | |
144 | kprintf("unexpected message type in ddp_putmsg: %d/n", | |
145 | gbuf_type(mp)); | |
146 | #endif | |
147 | gbuf_freem(mp); | |
148 | break; | |
149 | } | |
150 | return; | |
151 | } /* ddp_putmsg */ | |
152 | ||
153 | gbuf_t *ddp_compress_msg(mp) | |
154 | register gbuf_t *mp; | |
155 | { | |
156 | register gbuf_t *tmp; | |
157 | ||
158 | while (gbuf_len(mp) == 0) { | |
159 | tmp = mp; | |
160 | mp = gbuf_cont(mp); | |
161 | gbuf_freeb(tmp); | |
162 | ||
163 | if (mp == NULL) | |
164 | break; | |
165 | } | |
166 | return (mp); | |
167 | } |