]> arthur.barton.de Git - netatalk.git/blob - sys/solaris/ddp.c
massive commenting/autoconf changes
[netatalk.git] / sys / solaris / ddp.c
1 /*
2  * $Id: ddp.c,v 1.2 2001-06-29 14:14:47 rufustfirefly Exp $
3  */
4
5 #ifdef HAVE_CONFIG_H
6 #include "config.h"
7 #endif /* HAVE_CONFIG_H */
8
9 #include <sys/types.h>
10 #include <sys/stream.h>
11 #include <sys/cmn_err.h>
12 #include <sys/socket.h>
13 #include <sys/errno.h>
14 #include <sys/tihdr.h>
15 #include <sys/ddi.h>
16 #include <sys/ethernet.h>
17 #include <net/if.h>
18
19 #include <string.h>
20
21 #include <netatalk/endian.h>
22 #include <netatalk/ddp.h>
23 #include <netatalk/at.h>
24
25 #include "if.h"
26 #include "sock.h"
27
28     int
29 ddp_rput( struct atif_data *aid, mblk_t *m )
30 {
31     struct atif_data    *daid;
32     struct ddpehdr      *deh;
33     struct sockaddr_at  sat;
34     struct sock_data    *sd;
35
36     if ( m->b_wptr - m->b_rptr < sizeof( struct ddpehdr )) {
37         cmn_err( CE_NOTE, "ddp_rput short packet\n" );
38         freemsg( m );
39         return( EINVAL );
40     }
41
42     deh = (struct ddpehdr *)m->b_rptr;
43
44     sat.sat_addr.s_net = deh->deh_dnet;
45     sat.sat_addr.s_node = deh->deh_dnode;
46     sat.sat_port = deh->deh_dport;
47
48     if (( daid = if_dest( aid, &sat )) != NULL ) {
49         if (( sd = sock_dest( daid, &sat )) != NULL ) {
50             if ( sd->sd_state != TS_IDLE ) {
51                 freemsg( m );
52                 return( EHOSTDOWN );
53             }
54             bzero( (caddr_t)&sat, sizeof( struct sockaddr_at ));
55             sat.sat_family = AF_APPLETALK;
56             sat.sat_addr.s_net = deh->deh_snet;
57             sat.sat_addr.s_node = deh->deh_snode;
58             sat.sat_port = deh->deh_sport;
59             adjmsg( m, sizeof( struct ddpehdr ));
60             t_unitdata_ind( WR( sd->sd_q ), m, &sat );
61         } else {
62             /* toss it */
63             freemsg( m );
64             return( EHOSTDOWN );
65         }
66     } else {
67         /* route it */
68         freemsg( m );
69         return( ENETUNREACH );
70     }
71     return( 0 );
72 }