summaryrefslogtreecommitdiff
path: root/netcat.c
diff options
context:
space:
mode:
Diffstat (limited to 'netcat.c')
-rw-r--r--netcat.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/netcat.c b/netcat.c
index 6700f89cfe5b9..508712388dfda 100644
--- a/netcat.c
+++ b/netcat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: netcat.c,v 1.93 2009/06/05 00:18:10 claudio Exp $ */
+/* $OpenBSD: netcat.c,v 1.95 2010/02/27 00:58:56 nicm Exp $ */
/*
* Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
*
@@ -403,8 +403,10 @@ main(int argc, char *argv[])
uflag ? "udp" : "tcp");
}
- printf("Connection to %s %s port [%s/%s] succeeded!\n",
- host, portlist[i], uflag ? "udp" : "tcp",
+ fprintf(stderr,
+ "Connection to %s %s port [%s/%s] "
+ "succeeded!\n", host, portlist[i],
+ uflag ? "udp" : "tcp",
sv ? sv->s_name : "*");
}
if (!zflag)
@@ -681,27 +683,27 @@ atelnet(int nfd, unsigned char *buf, unsigned int size)
unsigned char *p, *end;
unsigned char obuf[4];
- end = buf + size;
- obuf[0] = '\0';
+ if (size < 3)
+ return;
+ end = buf + size - 2;
for (p = buf; p < end; p++) {
if (*p != IAC)
- break;
+ continue;
obuf[0] = IAC;
p++;
if ((*p == WILL) || (*p == WONT))
obuf[1] = DONT;
- if ((*p == DO) || (*p == DONT))
+ else if ((*p == DO) || (*p == DONT))
obuf[1] = WONT;
- if (obuf) {
- p++;
- obuf[2] = *p;
- obuf[3] = '\0';
- if (atomicio(vwrite, nfd, obuf, 3) != 3)
- warn("Write Error!");
- obuf[0] = '\0';
- }
+ else
+ continue;
+
+ p++;
+ obuf[2] = *p;
+ if (atomicio(vwrite, nfd, obuf, 3) != 3)
+ warn("Write Error!");
}
}