From 8c90613ed8765eb25a9973309c66d85767ceb838 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Thu, 2 May 2013 09:31:41 -0400 Subject: Adds "ip" command to look up peer IP --- check_user_name.h | 23 +++++++++++++++++++++++ user_command.h | 12 ++++++++++++ 2 files changed, 35 insertions(+) diff --git a/check_user_name.h b/check_user_name.h index 77051ce..1660001 100644 --- a/check_user_name.h +++ b/check_user_name.h @@ -24,4 +24,27 @@ int check_user_name(const char * username) { return 0; +} + +void get_ip_by_username(char * username) { + + int i; + + pthread_mutex_lock(&peer_table_lock); + + for (i = 0; i < num_peers_in_table; i++) { + if (strcmp(peers[i].username, username) == 0) { + + printf("IP: %s \n", peers[i].ip); + pthread_mutex_unlock(&peer_table_lock); + return; + + } + } + + printf("%s does not exist. \n", username); + + pthread_mutex_unlock(&peer_table_lock); + return; + } \ No newline at end of file diff --git a/user_command.h b/user_command.h index 9e0df5a..3fcd40c 100644 --- a/user_command.h +++ b/user_command.h @@ -111,12 +111,24 @@ void process_user_command() { } + } else if (strcmp(command, "ip\n") == 0) { + + char user[32]; + + printf("user: "); + fgets(user, 32, stdin); + + user[strlen(user) - 1] = 0; + + get_ip_by_username(user); + } else if (strcmp(command, "help\n") == 0 || strcmp(command, "?\n") == 0) { printf("Command Summary: \n"); printf(" who: display a list of online peers \n"); printf(" chat: initiate a chat session \n"); printf(" quit: exit the localchat program \n"); + printf(" ip: display the IP address of a user \n"); } else if (strcmp(command, "\n") == 0) { // no command, do nothing. -- cgit v1.2.3