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. */
21 * \brief Source: Low-level protocol for MCFS
22 * \author Miguel de Icaza
35 #include <sys/types.h>
37 #include <sys/socket.h>
38 #include <netinet/in.h>
39 #ifdef HAVE_ARPA_INET_H
40 #include <arpa/inet.h>
45 #include <rpc/pmap_prot.h>
46 #ifdef HAVE_RPC_PMAP_CLNT_H
47 #include <rpc/pmap_clnt.h>
53 #include "../src/global.h"
54 #include "../src/tty.h" /* enable/disable interrupt key */
55 #include "../src/wtools.h" /* message() */
56 #include "../src/main.h" /* print_vfs_message */
60 #include "mcfs.h" /* tcp_invalidate_socket() */
62 #define CHECK_SIG_PIPE(sock) if (got_sigpipe) \
63 { tcp_invalidate_socket (sock); return got_sigpipe = 0; }
65 /* Reads a block on dest for len bytes from sock */
66 /* Returns a boolean indicating the success status */
68 socket_read_block (int sock
, char *dest
, int len
)
72 for (nread
= 0; nread
< len
;) {
73 n
= read (sock
, dest
+ nread
, len
- nread
);
75 tcp_invalidate_socket (sock
);
84 socket_write_block (int sock
, const char *buffer
, int len
)
88 for (left
= len
; left
> 0;) {
89 status
= write (sock
, buffer
, left
);
90 CHECK_SIG_PIPE (sock
);
100 rpc_send (int sock
, ...)
102 long int tmp
, len
, cmd
;
109 cmd
= va_arg (ap
, int);
116 tmp
= htonl (va_arg (ap
, int));
117 write (sock
, &tmp
, sizeof (tmp
));
118 CHECK_SIG_PIPE (sock
);
122 text
= va_arg (ap
, char *);
125 write (sock
, &tmp
, sizeof (tmp
));
126 CHECK_SIG_PIPE (sock
);
127 write (sock
, text
, len
);
128 CHECK_SIG_PIPE (sock
);
132 len
= va_arg (ap
, int);
133 text
= va_arg (ap
, char *);
135 write (sock
, text
, len
);
136 CHECK_SIG_PIPE (sock
);
140 vfs_die ("Unknown rpc message\n");
146 rpc_get (int sock
, ...)
149 char *text
, **str_dest
;
156 cmd
= va_arg (ap
, int);
163 if (socket_read_block (sock
, (char *) &tmp
, sizeof (tmp
)) == 0) {
167 dest
= va_arg (ap
, int *);
171 /* returns an allocated string */
172 case RPC_LIMITED_STRING
:
174 if (socket_read_block (sock
, (char *) &tmp
, sizeof (tmp
)) == 0) {
179 if (cmd
== RPC_LIMITED_STRING
)
180 if (len
> 16 * 1024) {
184 if (len
> 128 * 1024)
187 /* Don't use glib functions here - this code is used by mcserv */
188 text
= malloc (len
+ 1);
189 if (socket_read_block (sock
, text
, len
) == 0) {
196 str_dest
= va_arg (ap
, char **);
201 len
= va_arg (ap
, int);
202 text
= va_arg (ap
, char *);
203 if (socket_read_block (sock
, text
, len
) == 0) {
210 vfs_die ("Unknown rpc message\n");
215 void mcfsutil__unused(void)
218 CFLAGS="-ansi -pedantic -Wall -Wextra -Werror"
221 #endif /* WITH_MCFS */