/* * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. The rights granted to you under the License * may not be used to create, or enable the creation or redistribution of, * unlawful or unlicensed copies of an Apple operating system, or to * circumvent, violate, or enable the circumvention or violation of, any * terms of an Apple operating system software license agreement. * * Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* * Copyright (c) 1988, 1989, 1997, 1998 Apple Computer, Inc. * * Modified for MP, 1996 by Tuyen Nguyen * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX. */ /* ddp_proto.c: 2.0, 1.23; 10/18/93; Apple Computer, Inc. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include extern at_ifaddr_t *ifID_home; void ddp_putmsg(gref, mp) gref_t *gref; gbuf_t *mp; { register ioc_t *iocbp; register int error; at_ddp_t *ddp; switch(gbuf_type(mp)) { case MSG_DATA : /* If this message is going out on a socket that's not bound, * nail it. */ ddp = (at_ddp_t *)gbuf_rptr(mp); if ((ddp->type == DDP_ATP) || (ddp->type == DDP_ADSP)) { if ((gref == 0) || (gref->lport == 0)) { int src_addr_included = ((ddp->type==DDP_ATP) && ddp->src_node)? 1 : 0; (void)ddp_output(&mp, ddp->src_socket, src_addr_included); return; } } if ((gref == 0) || (gref->lport == 0)) { gbuf_freel(mp); if (gref) atalk_notify(gref, ENOTCONN); return; } if ((error = ddp_output(&mp, gref->lport, 0)) != 0) { if (gref) atalk_notify(gref, error); } return; case MSG_IOCTL : iocbp = (ioc_t *)gbuf_rptr(mp); if (DDP_IOC_MYIOCTL(iocbp->ioc_cmd)) { switch(iocbp->ioc_cmd) { case DDP_IOC_GET_CFG : /* Note that DDP_IOC_GET_CFG / AppleTalk ddp_config() fills in the net and node of the ddp_addr_t param with the net and node of the default interface, not the net and node that has been bound, as getsockname() and sockopt DDP_GETSOCKNAME do. */ #ifdef APPLETALK_DEBUG kprintf("ddp_putmsg: DDP_IOC_GET_CFG\n"); #endif if (gbuf_cont(mp)) gbuf_freem(gbuf_cont(mp)); if ((gbuf_cont(mp) = gbuf_alloc(sizeof(ddp_addr_t), PRI_MED)) == NULL) { ioc_ack(ENOBUFS, mp, gref); break; } { /* *** was ddp_get_cfg() *** */ ddp_addr_t *cfgp = (ddp_addr_t *)gbuf_rptr(gbuf_cont(mp)); cfgp->inet.net = ifID_home->ifThisNode.s_net; cfgp->inet.node = ifID_home->ifThisNode.s_node; #ifdef NOT_YET cfgp->inet.net = gref->laddr.s_net; cfgp->inet.node = gref->laddr.s_node; #endif cfgp->inet.socket = gref->lport; cfgp->ddptype = gref->ddptype; } gbuf_wset(gbuf_cont(mp), sizeof(ddp_addr_t)); iocbp->ioc_count = sizeof(ddp_addr_t); ioc_ack(0, mp, gref); break; default: ioc_ack(EINVAL, mp, gref); break; } } else { /* Unknown ioctl */ ioc_ack(EINVAL, mp, gref); } break; default : #ifdef APPLETALK_DEBUG kprintf("unexpected message type in ddp_putmsg: %d/n", gbuf_type(mp)); #endif gbuf_freem(mp); break; } return; } /* ddp_putmsg */ gbuf_t *ddp_compress_msg(mp) register gbuf_t *mp; { register gbuf_t *tmp; while (gbuf_len(mp) == 0) { tmp = mp; mp = gbuf_cont(mp); gbuf_freeb(tmp); if (mp == NULL) break; } return (mp); }