diff options
author | Niklas Halle <niklas@niklashalle.net> | 2020-06-01 15:05:36 +0200 |
---|---|---|
committer | Niklas Halle <niklas@niklashalle.net> | 2020-06-01 15:05:36 +0200 |
commit | 85131d8acfca55810205af625d65358f006f3de7 (patch) | |
tree | 6075f28c7552b06bbc3343375c317442dbabb183 /03_exercise/cli/client.c | |
parent | d6c6df06b0fcfa275cd4a6e3de15cd29f4693088 (diff) | |
download | betriebssysteme-85131d8acfca55810205af625d65358f006f3de7.tar.gz betriebssysteme-85131d8acfca55810205af625d65358f006f3de7.zip |
improvements
Diffstat (limited to '03_exercise/cli/client.c')
-rw-r--r-- | 03_exercise/cli/client.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/03_exercise/cli/client.c b/03_exercise/cli/client.c index 3cd6f1b..a98942d 100644 --- a/03_exercise/cli/client.c +++ b/03_exercise/cli/client.c @@ -10,6 +10,8 @@ #define PORT 9000 #define HOST "127.0.0.1" +#define BUF_SIZE 256 + static inline void die(const char *msg) { perror(msg); exit(-1); @@ -21,7 +23,7 @@ int main() { .sin_port = htons(PORT), .sin_addr.s_addr = inet_addr(HOST) }; - char buf[256]; + char buf[BUF_SIZE]; int cfd; if ((cfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) @@ -35,6 +37,7 @@ int main() { __ssize_t length; while (1) { + printf("%s > ", HOST); if ((length = getline(&line, &cap, stdin)) < 0) { fprintf(stderr, "Failed to read from STDIN"); fflush(stderr); @@ -54,13 +57,14 @@ int main() { strncpy(buf, line, strlen(line)); - if (write(cfd, buf, sizeof(buf)) < 0) + if (write(cfd, buf, BUF_SIZE) < 0) die("Could not send message"); - if (read(cfd, buf, sizeof(buf)) < 0) + if (read(cfd, buf, BUF_SIZE) < 0) die("Could not receive message"); - printf("$> %s\n", buf); + printf("%s\n", buf); + memset(buf, 0, BUF_SIZE); } close(cfd); |