1 | /* Copyright (c) 2001, Stanford University
|
---|
2 | * All rights reserved
|
---|
3 | *
|
---|
4 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include "cr_net.h"
|
---|
8 | #include "cr_mem.h"
|
---|
9 | #include "cr_error.h"
|
---|
10 | #include "net_internals.h"
|
---|
11 |
|
---|
12 | static void
|
---|
13 | crDevnullWriteExact( CRConnection *conn, const void *buf, unsigned int len )
|
---|
14 | {
|
---|
15 | (void) conn;
|
---|
16 | (void) buf;
|
---|
17 | (void) len;
|
---|
18 | }
|
---|
19 |
|
---|
20 | static void *
|
---|
21 | crDevnullAlloc( CRConnection *conn )
|
---|
22 | {
|
---|
23 | return crAlloc( conn->buffer_size );
|
---|
24 | }
|
---|
25 |
|
---|
26 | static void
|
---|
27 | crDevnullSingleRecv( CRConnection *conn, void *buf, unsigned int len )
|
---|
28 | {
|
---|
29 | crError( "You can't receive data on a devnull connection!" );
|
---|
30 | (void) conn;
|
---|
31 | (void) buf;
|
---|
32 | (void) len;
|
---|
33 | }
|
---|
34 |
|
---|
35 | static void
|
---|
36 | crDevnullFree( CRConnection *conn, void *buf )
|
---|
37 | {
|
---|
38 | crFree( buf );
|
---|
39 | (void) conn;
|
---|
40 | }
|
---|
41 |
|
---|
42 | static void
|
---|
43 | crDevnullSend( CRConnection *conn, void **bufp,
|
---|
44 | const void *start, unsigned int len )
|
---|
45 | {
|
---|
46 |
|
---|
47 | if (bufp)
|
---|
48 | {
|
---|
49 | /* We're sending somethnig we've allocated. It's now ours.
|
---|
50 | * If the callers wants to send something else, he'll allocate
|
---|
51 | * something else.
|
---|
52 | *
|
---|
53 | * ENFORCE IT! */
|
---|
54 |
|
---|
55 | crDevnullFree( conn, *bufp );
|
---|
56 | }
|
---|
57 | (void) conn;
|
---|
58 | (void) bufp;
|
---|
59 | (void) start;
|
---|
60 | (void) len;
|
---|
61 | }
|
---|
62 |
|
---|
63 | int
|
---|
64 | crDevnullRecv( void )
|
---|
65 | {
|
---|
66 | crError( "You can't receive data on a DevNull network, stupid." );
|
---|
67 | return 0;
|
---|
68 | }
|
---|
69 |
|
---|
70 | void
|
---|
71 | crDevnullInit( CRNetReceiveFuncList *rfl, CRNetCloseFuncList *cfl, unsigned int mtu )
|
---|
72 | {
|
---|
73 | (void) rfl;
|
---|
74 | (void) cfl;
|
---|
75 | (void) mtu;
|
---|
76 | }
|
---|
77 |
|
---|
78 | static void
|
---|
79 | crDevnullAccept( CRConnection *conn, const char *hostname, unsigned short port )
|
---|
80 | {
|
---|
81 | crError( "Well, you *could* accept a devnull client, but you'd be disappointed. ");
|
---|
82 | (void) conn;
|
---|
83 | (void) port;
|
---|
84 | }
|
---|
85 |
|
---|
86 | static int
|
---|
87 | crDevnullDoConnect( CRConnection *conn )
|
---|
88 | {
|
---|
89 | (void) conn;
|
---|
90 | return 1;
|
---|
91 | }
|
---|
92 |
|
---|
93 | static void
|
---|
94 | crDevnullDoDisconnect( CRConnection *conn )
|
---|
95 | {
|
---|
96 | (void) conn;
|
---|
97 | }
|
---|
98 |
|
---|
99 | void crDevnullConnection( CRConnection *conn )
|
---|
100 | {
|
---|
101 | conn->type = CR_DROP_PACKETS;
|
---|
102 | conn->Alloc = crDevnullAlloc;
|
---|
103 | conn->Send = crDevnullSend;
|
---|
104 | conn->SendExact = crDevnullWriteExact;
|
---|
105 | conn->Recv = crDevnullSingleRecv;
|
---|
106 | conn->Free = crDevnullFree;
|
---|
107 | conn->Accept = crDevnullAccept;
|
---|
108 | conn->Connect = crDevnullDoConnect;
|
---|
109 | conn->Disconnect = crDevnullDoDisconnect;
|
---|
110 | conn->actual_network = 0;
|
---|
111 | }
|
---|
112 |
|
---|
113 | CRConnection** crDevnullDump( int * num )
|
---|
114 | {
|
---|
115 | *num = 0;
|
---|
116 | return NULL;
|
---|
117 | }
|
---|