#include <sys/errno.h>
#include <sys/types.h>
#include <sys/param.h>
#include <machine/spl.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/filedesc.h>
#include <sys/fcntl.h>
#include <sys/mbuf.h>
#include <sys/ioctl.h>
#include <sys/malloc.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/buf.h>
#include <net/if.h>
#include <netat/sysglue.h>
#include <netat/appletalk.h>
#include <netat/at_var.h>
#include <netat/ddp.h>
#include <netat/zip.h>
#include <netat/at_pcb.h>
extern at_ifaddr_t *ifID_home;
void ddp_putmsg(gref, mp)
gref_t *gref;
gbuf_t *mp;
{
u_char socket;
register ioc_t *iocbp;
register int error;
at_ddp_t *ddp;
switch(gbuf_type(mp)) {
case MSG_DATA :
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 && (gref->lport == 0)) {
gbuf_freel(mp);
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 :
#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(at_inet_t),
PRI_MED)) == NULL) {
ioc_ack(ENOBUFS, mp, gref);
break;
}
{
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 {
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;
}
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);
}