summaryrefslogtreecommitdiff
path: root/packet.h
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>1999-10-27 13:42:43 +1000
committerDamien Miller <djm@mindrot.org>1999-10-27 13:42:43 +1000
commitd4a8b7e34dd619a4debf9a206c81db26d1402ea6 (patch)
treea47d770a2f790f40d18b0982d4e55fa7cfb1fa3b /packet.h
Initial revision
Diffstat (limited to 'packet.h')
-rw-r--r--packet.h166
1 files changed, 166 insertions, 0 deletions
diff --git a/packet.h b/packet.h
new file mode 100644
index 000000000..fb84e6c11
--- /dev/null
+++ b/packet.h
@@ -0,0 +1,166 @@
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/* RCSID("$Id: packet.h,v 1.1 1999/10/27 03:42:44 damien Exp $"); */
17
18#ifndef PACKET_H
19#define PACKET_H
20
21#include <openssl/bn.h>
22
23/* Sets the socket used for communication. Disables encryption until
24 packet_set_encryption_key is called. It is permissible that fd_in
25 and fd_out are the same descriptor; in that case it is assumed to
26 be a socket. */
27void packet_set_connection(int fd_in, int fd_out);
28
29/* Puts the connection file descriptors into non-blocking mode. */
30void packet_set_nonblocking(void);
31
32/* Returns the file descriptor used for input. */
33int packet_get_connection_in(void);
34
35/* Returns the file descriptor used for output. */
36int packet_get_connection_out(void);
37
38/* Closes the connection (both descriptors) and clears and frees
39 internal data structures. */
40void packet_close(void);
41
42/* Causes any further packets to be encrypted using the given key. The same
43 key is used for both sending and reception. However, both directions
44 are encrypted independently of each other. Cipher types are
45 defined in ssh.h. */
46void packet_set_encryption_key(const unsigned char *key, unsigned int keylen,
47 int cipher_type, int is_client);
48
49/* Sets remote side protocol flags for the current connection. This can
50 be called at any time. */
51void packet_set_protocol_flags(unsigned int flags);
52
53/* Returns the remote protocol flags set earlier by the above function. */
54unsigned int packet_get_protocol_flags(void);
55
56/* Enables compression in both directions starting from the next packet. */
57void packet_start_compression(int level);
58
59/* Informs that the current session is interactive. Sets IP flags for optimal
60 performance in interactive use. */
61void packet_set_interactive(int interactive, int keepalives);
62
63/* Returns true if the current connection is interactive. */
64int packet_is_interactive(void);
65
66/* Starts constructing a packet to send. */
67void packet_start(int type);
68
69/* Appends a character to the packet data. */
70void packet_put_char(int ch);
71
72/* Appends an integer to the packet data. */
73void packet_put_int(unsigned int value);
74
75/* Appends an arbitrary precision integer to packet data. */
76void packet_put_bignum(BIGNUM *value);
77
78/* Appends a string to packet data. */
79void packet_put_string(const char *buf, unsigned int len);
80
81/* Finalizes and sends the packet. If the encryption key has been set,
82 encrypts the packet before sending. */
83void packet_send(void);
84
85/* Waits until a packet has been received, and returns its type. */
86int packet_read(int *payload_len_ptr);
87
88/* Waits until a packet has been received, verifies that its type matches
89 that given, and gives a fatal error and exits if there is a mismatch. */
90void packet_read_expect(int *payload_len_ptr, int type);
91
92/* Checks if a full packet is available in the data received so far via
93 packet_process_incoming. If so, reads the packet; otherwise returns
94 SSH_MSG_NONE. This does not wait for data from the connection.
95
96 SSH_MSG_DISCONNECT is handled specially here. Also,
97 SSH_MSG_IGNORE messages are skipped by this function and are never returned
98 to higher levels. */
99int packet_read_poll(int *packet_len_ptr);
100
101/* Buffers the given amount of input characters. This is intended to be
102 used together with packet_read_poll. */
103void packet_process_incoming(const char *buf, unsigned int len);
104
105/* Returns a character (0-255) from the packet data. */
106unsigned int packet_get_char(void);
107
108/* Returns an integer from the packet data. */
109unsigned int packet_get_int(void);
110
111/* Returns an arbitrary precision integer from the packet data. The integer
112 must have been initialized before this call. */
113void packet_get_bignum(BIGNUM *value, int *length_ptr);
114
115/* Returns a string from the packet data. The string is allocated using
116 xmalloc; it is the responsibility of the calling program to free it when
117 no longer needed. The length_ptr argument may be NULL, or point to an
118 integer into which the length of the string is stored. */
119char *packet_get_string(unsigned int *length_ptr);
120
121/* Logs the error in syslog using LOG_INFO, constructs and sends a disconnect
122 packet, closes the connection, and exits. This function never returns.
123 The error message should not contain a newline. The total length of the
124 message must not exceed 1024 bytes. */
125void packet_disconnect(const char *fmt, ...);
126
127/* Sends a diagnostic message to the other side. This message
128 can be sent at any time (but not while constructing another message).
129 The message is printed immediately, but only if the client is being
130 executed in verbose mode. These messages are primarily intended to
131 ease debugging authentication problems. The total length of the message
132 must not exceed 1024 bytes. This will automatically call
133 packet_write_wait. If the remote side protocol flags do not indicate
134 that it supports SSH_MSG_DEBUG, this will do nothing. */
135void packet_send_debug(const char *fmt, ...);
136
137/* Checks if there is any buffered output, and tries to write some of the
138 output. */
139void packet_write_poll(void);
140
141/* Waits until all pending output data has been written. */
142void packet_write_wait(void);
143
144/* Returns true if there is buffered data to write to the connection. */
145int packet_have_data_to_write(void);
146
147/* Returns true if there is not too much data to write to the connection. */
148int packet_not_very_much_data_to_write(void);
149
150/* Stores tty modes from the fd into current packet. */
151void tty_make_modes(int fd);
152
153/* Parses tty modes for the fd from the current packet. */
154void tty_parse_modes(int fd, int *n_bytes_ptr);
155
156#define packet_integrity_check(payload_len, expected_len, type) \
157do { \
158 int _p = (payload_len), _e = (expected_len); \
159 if (_p != _e) { \
160 log("Packet integrity error (%d != %d) at %s:%d", \
161 _p, _e, __FILE__, __LINE__); \
162 packet_disconnect("Packet integrity error. (%d)", (type)); \
163 } \
164} while (0)
165
166#endif /* PACKET_H */