Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

get_port takes socket-number

  • Loading branch information...
commit ca5187fb0389ce35dc029545668c904e5ee97ba4 1 parent 46a0092
Robert A authored
Showing with 3 additions and 2 deletions.
  1. +3 −2 duoit.c
View
5 duoit.c
@@ -104,6 +104,7 @@ int initialize_server() {
* initialize head of user-list
*/
int ini_user_list(int newfd, usr **user) {
+ int sock = get_port(newfd);
*user = calloc(1, sizeof(struct usr));
(*user)->csocket = newfd;
(*user)->dsocket = 0;
@@ -283,13 +284,13 @@ int quit_command(instruc *instruction, usr *user, fd_set *master) {
* find the PORT of the user's socket
*/
-int get_port(usr *user) {
+int get_port(int sockfd) {
socklen_t len;
struct sockaddr_storage addr;
int port;
len = sizeof(struct sockaddr_storage);
- getpeername(user->csocket, (struct sockaddr*)&addr, &len);
+ getpeername(sockfd, (struct sockaddr*)&addr, &len);
//deal with both IPv4 and IPv6
if (addr.ss_family == AF_INET) {
struct sockaddr_in *sock = (struct sockaddr_in *)&addr;
Please sign in to comment.
Something went wrong with that request. Please try again.