commit 7996854cd93bcd9adcdb11b0842ba4c7a560b9d0
parent 09d6e654ee6860cdf058b74443750e3be447280f
Author: Naveen Narayanan <zerous@nocebo.space>
Date: Sat, 25 Sep 2021 18:35:08 +0200
Fix bug
ssize_t is returned by recv and send
Fix style
Diffstat:
M | finger.c | | | 31 | ++++++++++++++++--------------- |
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/finger.c b/finger.c
@@ -52,7 +52,8 @@ main(int argc, char **argv)
struct addrinfo *res, *p;
char buf[BUFSZ], hostname[MAXHOSTNAMELEN+1], user[32];
char *msg;
- int status, sockfd, byt, len, err, tosend;
+ ssize_t n;
+ int status, sockfd, ulen, len, err;
err = 0;
msg = buf;
@@ -72,7 +73,7 @@ main(int argc, char **argv)
goto err1;
}
- len = strlen(user);
+ ulen = strlen(user);
for (p = res; p != NULL; p = p->ai_next) {
sockfd = socket(res->ai_family, res->ai_socktype,
res->ai_protocol);
@@ -90,34 +91,34 @@ main(int argc, char **argv)
goto err3;
}
- memcpy(msg, user, len);
- msg[len] = '\r';
- msg[len+1] = '\n';
- tosend = len+2;
+ memcpy(msg, user, ulen);
+ msg[ulen] = '\r';
+ msg[ulen+1] = '\n';
+ len = ulen+2;
do {
- byt = send(sockfd, msg, tosend, 0);
- if (byt == -1) {
+ n = send(sockfd, msg, len, 0);
+ if (n == -1) {
fprintf(stderr, "send failed: %s\n", strerror(errno));
err = 1;
goto err3;
}
- tosend -= byt;
- msg += byt;
- } while (tosend > 0);
+ len -= n;
+ msg += n;
+ } while (len > 0);
do {
- byt = recv(sockfd, msg, BUFSZ, 0);
- if (byt == -1) {
+ n = recv(sockfd, msg, BUFSZ, 0);
+ if (n == -1) {
fprintf(stderr, "recv failed: %s\n",
strerror(errno));
goto err3;
}
- while (msg - buf < byt)
+ while (msg - buf < n)
putchar(*msg++);
msg = buf;
- } while (byt > 0);
+ } while (n > 0);
}
err3: