// 獲取本地以及遠程的IP和port setsockopt(clientfd, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, (char *)&listenfd, sizeof(listenfd)); struct sockaddr_in laddr, raddr; int laddr_len = sizeof(sockaddr_in), raddr_len = sizeof(sockaddr_in); getsockname(clientfd, (struct sockaddr*)&laddr, &laddr_len); getpeername(clientfd, (struct sockaddr*)&raddr, &raddr_len); logc(CT_TURQUOISE, CT_HIGHLIGHT, "local addr: %s %d ", inet_ntoa(laddr.sin_addr), ntohs(laddr.sin_port)); logc(CT_TURQUOISE, CT_HIGHLIGHT, "remote addr: %s %d ", inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port));
在接收到遠程連接之後調用上面的代碼,就是顯示IP和端口,本地的以及遠端的