summaryrefslogtreecommitdiffstats
path: root/usr.bin/finger
diff options
context:
space:
mode:
authorwollman <wollman@FreeBSD.org>1995-12-17 21:04:36 +0000
committerwollman <wollman@FreeBSD.org>1995-12-17 21:04:36 +0000
commit360eaa7e3c653a77886be48b7b1a7fcfee5f396c (patch)
tree0bf849f405e7cb5f2b9e6677db3d809036a55d92 /usr.bin/finger
parent20aa19ef2fb2f3616aee0c954f574469a05c70e4 (diff)
downloadFreeBSD-src-360eaa7e3c653a77886be48b7b1a7fcfee5f396c.zip
FreeBSD-src-360eaa7e3c653a77886be48b7b1a7fcfee5f396c.tar.gz
Implement client-side transaction TCP. This has little effect
if the server doesn't support it. (This is intended mostly as an example.)
Diffstat (limited to 'usr.bin/finger')
-rw-r--r--usr.bin/finger/net.c52
1 files changed, 39 insertions, 13 deletions
diff --git a/usr.bin/finger/net.c b/usr.bin/finger/net.c
index ee83d58..f5789ad 100644
--- a/usr.bin/finger/net.c
+++ b/usr.bin/finger/net.c
@@ -50,6 +50,7 @@ static char sccsid[] = "@(#)net.c 8.3 (Berkeley) 1/2/94";
#include <stdio.h>
#include <ctype.h>
#include <string.h>
+#include <sys/uio.h>
#include "finger.h"
void
@@ -65,6 +66,8 @@ netfinger(name)
struct sockaddr_in sin;
int s;
char *alist[1], *host;
+ struct iovec iov[3];
+ struct msghdr msg;
if (!(host = rindex(name, '@')))
return;
@@ -96,18 +99,31 @@ netfinger(name)
/* have network connection; identify the host connected with */
(void)printf("[%s]\n", hp->h_name);
- if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
- perror("finger: connect");
- (void)close(s);
- return;
- }
+
+ msg.msg_name = (void *)&sin;
+ msg.msg_namelen = sizeof sin;
+ msg.msg_iov = iov;
+ msg.msg_iovlen = 0;
+ msg.msg_control = 0;
+ msg.msg_controllen = 0;
+ msg.msg_flags = MSG_EOF;
/* -l flag for remote fingerd */
- if (lflag)
- write(s, "/W ", 3);
+ if (lflag) {
+ iov[msg.msg_iovlen].iov_base = "/W ";
+ iov[msg.msg_iovlen++].iov_len = 3;
+ }
/* send the name followed by <CR><LF> */
- (void)write(s, name, strlen(name));
- (void)write(s, "\r\n", 2);
+ iov[msg.msg_iovlen].iov_base = name;
+ iov[msg.msg_iovlen++].iov_len = strlen(name);
+ iov[msg.msg_iovlen].iov_base = "\r\n";
+ iov[msg.msg_iovlen++].iov_len = 2;
+
+ if (sendmsg(s, &msg, MSG_EOF) < 0) {
+ perror("finger: sendmsg");
+ close(s);
+ return;
+ }
/*
* Read from the remote system; once we're connected, we assume some
@@ -121,7 +137,9 @@ netfinger(name)
* it isn't a space, we can simply set the 7th bit. Every ASCII
* character with bit 7 set is printable.
*/
- if (fp = fdopen(s, "r"))
+ if (fp = fdopen(s, "r")) {
+ int lastc = '\n';
+
while ((c = getc(fp)) != EOF) {
c &= 0x7f;
if (c == 0x0d) {
@@ -141,7 +159,15 @@ netfinger(name)
}
putchar(c);
}
- if (lastc != '\n')
- putchar('\n');
- (void)fclose(fp);
+ if (lastc != '\n')
+ putchar('\n');
+
+ if (ferror(fp)) {
+ /*
+ * Assume that whatever it was set errno...
+ */
+ perror("finger: read");
+ }
+ (void)fclose(fp);
+ }
}
OpenPOWER on IntegriCloud