mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-12-26 21:13:11 +01:00
Implement client-side transaction TCP. This has little effect
if the server doesn't support it. (This is intended mostly as an example.)
This commit is contained in:
parent
dd07a8677b
commit
1e474c62ca
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=12909
@ -50,6 +50,7 @@ static char sccsid[] = "@(#)net.c 8.3 (Berkeley) 1/2/94";
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/uio.h>
|
||||||
#include "finger.h"
|
#include "finger.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -65,6 +66,8 @@ netfinger(name)
|
|||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
int s;
|
int s;
|
||||||
char *alist[1], *host;
|
char *alist[1], *host;
|
||||||
|
struct iovec iov[3];
|
||||||
|
struct msghdr msg;
|
||||||
|
|
||||||
if (!(host = rindex(name, '@')))
|
if (!(host = rindex(name, '@')))
|
||||||
return;
|
return;
|
||||||
@ -96,18 +99,31 @@ netfinger(name)
|
|||||||
|
|
||||||
/* have network connection; identify the host connected with */
|
/* have network connection; identify the host connected with */
|
||||||
(void)printf("[%s]\n", hp->h_name);
|
(void)printf("[%s]\n", hp->h_name);
|
||||||
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
|
|
||||||
perror("finger: connect");
|
msg.msg_name = (void *)&sin;
|
||||||
(void)close(s);
|
msg.msg_namelen = sizeof sin;
|
||||||
return;
|
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 */
|
/* -l flag for remote fingerd */
|
||||||
if (lflag)
|
if (lflag) {
|
||||||
write(s, "/W ", 3);
|
iov[msg.msg_iovlen].iov_base = "/W ";
|
||||||
|
iov[msg.msg_iovlen++].iov_len = 3;
|
||||||
|
}
|
||||||
/* send the name followed by <CR><LF> */
|
/* send the name followed by <CR><LF> */
|
||||||
(void)write(s, name, strlen(name));
|
iov[msg.msg_iovlen].iov_base = name;
|
||||||
(void)write(s, "\r\n", 2);
|
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
|
* 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
|
* it isn't a space, we can simply set the 7th bit. Every ASCII
|
||||||
* character with bit 7 set is printable.
|
* 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) {
|
while ((c = getc(fp)) != EOF) {
|
||||||
c &= 0x7f;
|
c &= 0x7f;
|
||||||
if (c == 0x0d) {
|
if (c == 0x0d) {
|
||||||
@ -141,7 +159,15 @@ netfinger(name)
|
|||||||
}
|
}
|
||||||
putchar(c);
|
putchar(c);
|
||||||
}
|
}
|
||||||
if (lastc != '\n')
|
if (lastc != '\n')
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
(void)fclose(fp);
|
|
||||||
|
if (ferror(fp)) {
|
||||||
|
/*
|
||||||
|
* Assume that whatever it was set errno...
|
||||||
|
*/
|
||||||
|
perror("finger: read");
|
||||||
|
}
|
||||||
|
(void)fclose(fp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user