add AUTO_CRLF flag
diff --git a/README b/README
index dc332a3..838928e 100644
--- a/README
+++ b/README
@@ -75,7 +75,17 @@
    The flags parameter can be any of the following flag constants
    bit-or'd together, or 0 to leave all options disabled.
 
-    LIBTELNET_FLAG_PROXY   - operate in proxy mode
+    LIBTELNET_FLAG_PROXY
+      Operate in proxy mode.  This disables the RFC1143 support and
+      enables automatic detection of COMPRESS2 streams.
+
+    LIBTELNET_FLAG_AUTO_CRLF
+      Automatically translate C newlines (\n) into the TELNET
+      newline marker, CRLF (\r\n).  This also translates the C
+      carriage return (\r) into the TELNET-correct CRNUL (\r\0).
+
+      Note that this only affects data that is sent.  Received
+      data is untranslated, even with this flag set.
  
  boid libtelnet_free(libtelnet_t *telnet);
    Releases any internal memory allocated by libtelnet.  This must
diff --git a/libtelnet.c b/libtelnet.c
index 8ac3a31..78e58e2 100644
--- a/libtelnet.c
+++ b/libtelnet.c
@@ -794,7 +794,10 @@
 /* send non-command data (escapes IAC bytes) */
 void libtelnet_send_data(libtelnet_t *telnet, unsigned char *buffer,
 		unsigned int size) {
+	static unsigned char CRLF[] = { '\r', '\n' };
+	static unsigned char CRNUL[] = { '\r', '\0' };
 	unsigned int i, l;
+
 	for (l = i = 0; i != size; ++i) {
 		/* dump prior portion of text, send escaped bytes */
 		if (buffer[i] == LIBTELNET_IAC) {
@@ -805,6 +808,20 @@
 
 			/* send escape */
 			libtelnet_send_command(telnet, LIBTELNET_IAC);
+
+		/* automatic translation of \n -> CRLF and \r -> CRNUL */
+		} else if (telnet->flags & LIBTELNET_FLAG_AUTO_CRLF &&
+				(buffer[i] == '\r' || buffer[i] == '\n')) {
+			/* dump prior text if any */
+			if (i != l)
+				_send(telnet, buffer + l, i - l);
+			l = i + 1;
+
+			/* translate */
+			if (buffer[i] == '\r')
+				_send(telnet, CRNUL, 2);
+			else
+				_send(telnet, CRLF, 2);
 		}
 	}
 
diff --git a/libtelnet.h b/libtelnet.h
index 1e6f837..a129438 100644
--- a/libtelnet.h
+++ b/libtelnet.h
@@ -92,6 +92,7 @@
 
 /* libtelnet feature flags */
 #define LIBTELNET_FLAG_PROXY (1<<0)
+#define LIBTELNET_FLAG_AUTO_CRLF (1<<1)
 
 #define LIBTELNET_PFLAG_DEFLATE (1<<7)