diff options
author | Oskar <[email protected]> | 2024-06-02 17:19:48 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-06-02 17:19:48 +0200 |
commit | 7a4372aace921fa78bfab14a450867f535d557b2 (patch) | |
tree | 01935a6b04fba816404dbe65f6292e8149b9736a | |
parent | 0b64bb4cc2ff464639d02a7c8e499b73f2c9eb95 (diff) |
specify IP
-rw-r--r-- | client.c | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -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; } |