summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-06-02 17:19:48 +0200
committerOskar <[email protected]>2024-06-02 17:19:48 +0200
commit7a4372aace921fa78bfab14a450867f535d557b2 (patch)
tree01935a6b04fba816404dbe65f6292e8149b9736a
parent0b64bb4cc2ff464639d02a7c8e499b73f2c9eb95 (diff)
specify IP
-rw-r--r--client.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/client.c b/client.c
index 2b0488f..5977713 100644
--- a/client.c
+++ b/client.c
@@ -40,7 +40,12 @@ int talk_to_server (int sockfd) {
return 0;
}
-int main () {
+int main (int argc, char *argv[]) {
+
+ if (argc != 2) {
+ fprintf(stderr, "USAGE: %s [IP]\n", argv[0]);
+ exit(__FAIL);
+ }
int sockfd = -1;
int gai_result;
@@ -53,9 +58,9 @@ int main () {
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
- gai_result = getaddrinfo("192.168.1.18", __PORT, &hints, &res);
+ gai_result = getaddrinfo(argv[1], __PORT, &hints, &res);
if (gai_result != 0) {
- fprintf(stderr, "getaddrinfo: %d", gai_result);
+ fprintf(stderr, "getaddrinfo: %d\n", gai_result);
exit(__FAIL);
}
@@ -78,11 +83,8 @@ int main () {
exit(__FAIL);
}
-
- //char *msg = "Client says hello!\n";
- //size_t len = strlen(msg);
-
- talk_to_server(sockfd);
freeaddrinfo(res);
+ talk_to_server(sockfd);
+
return 0;
}