1 /* Low-level protocol for MCFS.
3 Copyright (C) 1995, 1996 Miguel de Icaza
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License
7 as published by the Free Software Foundation; either version 2 of
8 the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
28 #include <sys/types.h>
30 #include <sys/socket.h>
31 #include <netinet/in.h>
32 #ifdef HAVE_ARPA_INET_H
33 #include <arpa/inet.h>
38 #include <rpc/pmap_prot.h>
39 #ifdef HAVE_RPC_PMAP_CLNT_H
40 #include <rpc/pmap_clnt.h>
46 #include "../src/global.h"
47 #include "../src/tty.h" /* enable/disable interrupt key */
48 #include "../src/wtools.h" /* message() */
49 #include "../src/main.h" /* print_vfs_message */
53 #include "mcfs.h" /* tcp_invalidate_socket() */
55 #define CHECK_SIG_PIPE(sock) if (got_sigpipe) \
56 { tcp_invalidate_socket (sock); return got_sigpipe = 0; }
58 /* Reads a block on dest for len bytes from sock */
59 /* Returns a boolean indicating the success status */
61 socket_read_block (int sock
, char *dest
, int len
)
65 for (nread
= 0; nread
< len
;) {
66 n
= read (sock
, dest
+ nread
, len
- nread
);
68 tcp_invalidate_socket (sock
);
77 socket_write_block (int sock
, const char *buffer
, int len
)
81 for (left
= len
; left
> 0;) {
82 status
= write (sock
, buffer
, left
);
83 CHECK_SIG_PIPE (sock
);
93 rpc_send (int sock
, ...)
95 long int tmp
, len
, cmd
;
102 cmd
= va_arg (ap
, int);
109 tmp
= htonl (va_arg (ap
, int));
110 write (sock
, &tmp
, sizeof (tmp
));
111 CHECK_SIG_PIPE (sock
);
115 text
= va_arg (ap
, char *);
118 write (sock
, &tmp
, sizeof (tmp
));
119 CHECK_SIG_PIPE (sock
);
120 write (sock
, text
, len
);
121 CHECK_SIG_PIPE (sock
);
125 len
= va_arg (ap
, int);
126 text
= va_arg (ap
, char *);
128 write (sock
, text
, len
);
129 CHECK_SIG_PIPE (sock
);
133 vfs_die ("Unknown rpc message\n");
139 rpc_get (int sock
, ...)
142 char *text
, **str_dest
;
149 cmd
= va_arg (ap
, int);
156 if (socket_read_block (sock
, (char *) &tmp
, sizeof (tmp
)) == 0) {
160 dest
= va_arg (ap
, int *);
164 /* returns an allocated string */
165 case RPC_LIMITED_STRING
:
167 if (socket_read_block (sock
, (char *) &tmp
, sizeof (tmp
)) == 0) {
172 if (cmd
== RPC_LIMITED_STRING
)
173 if (len
> 16 * 1024) {
177 if (len
> 128 * 1024)
180 /* Don't use glib functions here - this code is used by mcserv */
181 text
= malloc (len
+ 1);
182 if (socket_read_block (sock
, text
, len
) == 0) {
189 str_dest
= va_arg (ap
, char **);
194 len
= va_arg (ap
, int);
195 text
= va_arg (ap
, char *);
196 if (socket_read_block (sock
, text
, len
) == 0) {
203 vfs_die ("Unknown rpc message\n");
207 #endif /* WITH_MCFS */