I am trying to implement a simple client and server in C and I can't find online an example how to set a specific IP address to the client. This is what I got so far:
sockfd = socket(PF_INET, SOCK_STREAM, 0);
if (sockfd == -1)
{
<some code to handle error>
}
address.sin_family = AF_INET;
address.sin_addr.s_addr = inet_addr(<addressOfTheServer>);
address.sin_port = htons(<portToConnectToServer>);
len = sizeof(address);
int result = connect(sockfd, (struct sockaddr *)&address, len);
On the server side I check for the client IP Address and I always get 127.0.0.1
I want to change it something different.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…