6

Socket programming in C...print clients IP and queue number...

view full story
linux-howto

http://www.linuxquestions.org – Hello all, I'm messing around with socket programming in C. Basically trying to learn how to wait for client connection and print their IP and which host number are they in the current connection. I can't get the code to show the IP and which client in the queue are they.. Code: ... skt = socket(PF_INET,SOCK_STREAM,0); if( skt == -1 ) die("Error with Socket()"); memset(&nodeSkt,0,sizeof (nodeSkt)); nodeSkt.sin_family = AF_INET; nodeSkt.sin_port = htons(atoi(nodePort)); nodeSkt.sin_addr.s_addr = inet_addr(nodeAddr);         len_inet = sizeof(nodeSkt); state = bind(skt,(struct sockaddr *)&nodeSkt,len_inet); state = listen(skt,3); len_inet = sizeof(clntSkt); Clntsocket = accept(skt, (struct sockaddr *) &clntSkt,&len_inet);   printf("Client OK!");   if ( Clntsocket == -1 ) die("Error"); strcpy(data_buffer, "Your IP is: " && (struct sockaddr *) &clntSkt && "  Your are a connected client number: " ??????????); bytes = strlen(data_buffer); state = write(Clntsocket,data_buffer,bytes); ... I have most of the code working, but I'm having issues with the line: Code: strcpy(data_buffer, "Your IP is: " && (struct sockaddr *) &clntSkt && "  Your are a connected client number: " ??????????); I'm not sure if the IP of the client is being returned and not sure how to get the number of connected client from "listen(skt,3)" Thank you for the help in advance...I'm real new to this so sorry for the errors... (HowTos)