source: trunk/third/ssh/packet.h @ 12646

Revision 12646, 7.1 KB checked in by danw, 26 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r12645, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2
3packet.h
4
5Author: Tatu Ylonen <ylo@cs.hut.fi>
6
7Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8                   All rights reserved
9
10Created: Sat Mar 18 02:02:14 1995 ylo
11
12Interface for the packet protocol functions.
13
14*/
15
16/*
17 * $Id: packet.h,v 1.1.1.3 1999-03-08 17:43:43 danw Exp $
18 * $Log: not supported by cvs2svn $
19 * Revision 1.6  1998/03/27  16:59:16  kivinen
20 *      Added socks.h include.
21 *
22 * Revision 1.5  1997/04/05 17:29:14  ylo
23 *      Added packet_get_len (returns the remaining length of incoming
24 *      packet).
25 *
26 * Revision 1.4  1997/03/26 07:11:41  kivinen
27 *      Fixed prototypes.
28 *
29 * Revision 1.3  1997/03/19 19:26:16  kivinen
30 *      Added packet_get_all prototype.
31 *
32 * Revision 1.2  1996/11/24 08:24:14  kivinen
33 *      Fixed the comment of packet_send_debug.
34 *
35 * Revision 1.1.1.1  1996/02/18 21:38:10  ylo
36 *      Imported ssh-1.2.13.
37 *
38 * Revision 1.4  1995/09/24  23:59:20  ylo
39 *      Added packet_get_protocol_flags.
40 *
41 * Revision 1.3  1995/07/27  02:17:53  ylo
42 *      Pass as argument to packet_set_encryption_key whether running
43 *      as the client or the server.
44 *
45 * Revision 1.2  1995/07/13  01:27:54  ylo
46 *      Removed "Last modified" header.
47 *      Added cvs log.
48 *
49 * $Endlog$
50 */
51
52#ifndef PACKET_H
53#define PACKET_H
54
55#include <gmp.h>
56#include "randoms.h"
57
58#if defined(SOCKS5) && defined(HAVE_SOCKS_H)
59#include <socks.h>
60#endif
61
62/* Sets the socket used for communication.  Disables encryption until
63   packet_set_encryption_key is called.  It is permissible that fd_in
64   and fd_out are the same descriptor; in that case it is assumed to
65   be a socket. */
66void packet_set_connection(int fd_in, int fd_out, RandomState *state);
67
68/* Puts the connection file descriptors into non-blocking mode. */
69void packet_set_nonblocking(void);
70
71/* Returns the file descriptor used for input. */
72int packet_get_connection_in(void);
73
74/* Returns the file descriptor used for output. */
75int packet_get_connection_out(void);
76
77/* Closes the connection (both descriptors) and clears and frees
78   internal data structures. */
79void packet_close(void);
80
81/* Causes any further packets to be encrypted using the given key.  The same
82   key is used for both sending and reception.  However, both directions
83   are encrypted independently of each other.  Cipher types are
84   defined in ssh.h. */
85void packet_set_encryption_key(const unsigned char *key, unsigned int keylen,
86                               int cipher_type, int is_client);
87
88/* Sets remote side protocol flags for the current connection.  This can
89   be called at any time. */
90void packet_set_protocol_flags(unsigned int flags);
91
92/* Returns the remote protocol flags set earlier by the above function. */
93unsigned int packet_get_protocol_flags(void);
94
95/* Enables compression in both directions starting from the next packet. */
96void packet_start_compression(int level);
97
98/* Informs that the current session is interactive.  Sets IP flags for optimal
99   performance in interactive use. */
100void packet_set_interactive(int interactive, int keepalives);
101
102/* Returns true if the current connection is interactive. */
103int packet_is_interactive(void);
104
105/* Starts constructing a packet to send. */
106void packet_start(int type);
107
108/* Appends a character to the packet data. */
109void packet_put_char(int ch);
110
111/* Appends an integer to the packet data. */
112void packet_put_int(unsigned int value);
113
114/* Appends an arbitrary precision integer to packet data. */
115void packet_put_mp_int(MP_INT *value);
116
117/* Appends a string to packet data. */
118void packet_put_string(const char *buf, unsigned int len);
119
120/* Finalizes and sends the packet.  If the encryption key has been set,
121   encrypts the packet before sending. */
122void packet_send(void);
123
124/* Waits until a packet has been received, and returns its type. */
125int packet_read(void);
126
127/* Waits until a packet has been received, verifies that its type matches
128   that given, and gives a fatal error and exits if there is a mismatch. */
129void packet_read_expect(int type);
130
131/* Checks if a full packet is available in the data received so far via
132   packet_process_incoming.  If so, reads the packet; otherwise returns
133   SSH_MSG_NONE.  This does not wait for data from the connection.
134   
135   SSH_MSG_DISCONNECT is handled specially here.  Also,
136   SSH_MSG_IGNORE messages are skipped by this function and are never returned
137   to higher levels. */
138int packet_read_poll(void);
139
140/* Buffers the given amount of input characters.  This is intended to be
141   used together with packet_read_poll. */
142void packet_process_incoming(const char *buf, unsigned int len);
143
144/* Returns the remaining number of bytes in the incoming packet. */
145unsigned int packet_get_len(void);
146
147/* Returns a character (0-255) from the packet data. */
148unsigned int packet_get_char(void);
149
150/* Returns an integer from the packet data. */
151unsigned int packet_get_int(void);
152
153/* Returns an arbitrary precision integer from the packet data.  The integer
154   must have been initialized before this call. */
155void packet_get_mp_int(MP_INT *value);
156
157/* Returns a string from the packet data.  The string is allocated using
158   xmalloc; it is the responsibility of the calling program to free it when
159   no longer needed.  The length_ptr argument may be NULL, or point to an
160   integer into which the length of the string is stored. */
161char *packet_get_string(unsigned int *length_ptr);
162
163/* Clears incoming data buffer */
164void packet_get_all(void);
165     
166/* Logs the error in syslog using LOG_INFO, constructs and sends a disconnect
167   packet, closes the connection, and exits.  This function never returns.
168   The error message should not contain a newline.  The total length of the
169   message must not exceed 1024 bytes. */
170void packet_disconnect(const char *fmt, ...);
171
172/* Sends a diagnostic message to the other side.  This message
173   can be sent at any time (but not while constructing another message).
174   The message is printed immediately, but only if the client is being
175   executed in verbose mode. If the first character of the message is '*'
176   the message is printed to stderr always.
177   These messages are primarily intended to ease debugging authentication
178   problems. The total length of the message must not exceed 1024 bytes. This
179   will automatically call packet_write_wait. If the remote side protocol flags
180   do not indicate that it supports SSH_MSG_DEBUG, this will do nothing. */
181void packet_send_debug(const char *fmt, ...);
182
183/* Checks if there is any buffered output, and tries to write some of the
184   output. */
185void packet_write_poll(void);
186
187/* Waits until all pending output data has been written. */
188void packet_write_wait(void);
189
190/* Returns true if there is buffered data to write to the connection. */
191int packet_have_data_to_write(void);
192
193/* Returns true if there is not too much data to write to the connection. */
194int packet_not_very_much_data_to_write(void);
195
196/* Sets the maximum packet size that can be sent to the other side. */
197void packet_set_max_size(unsigned int max_size);
198
199/* Returns the maximum packet size that can be sent to the other side. */
200unsigned int packet_max_size(void);
201
202/* Stores tty modes from the fd into current packet. */
203void tty_make_modes(int fd);
204
205/* Parses tty modes for the fd from the current packet. */
206void tty_parse_modes(int fd);
207
208#endif /* PACKET_H */
Note: See TracBrowser for help on using the repository browser.