Help needed linux socket programming in c

Good evening everyone! :slight_smile:

I'm doing a small client / server application for sharing files in C, and I am trying to implement the following:

The client of my application sends to the address 255.255.255.255 a message requesting a particular file.In the network there is only one server, however, there may be multiple clients.
The server responds with an ACK if it has the file specified by the client.Until now,everythings' allright.
The question arises now,as I want the client, after receiving the confirmation (ACK) from the server, making sure that the reply message comes from the server or if the message is of uknown origin.As so,I have the following code in Client:

 ... 
 msg_tam = recvfrom (socketfd, buffer, BUFFERSIZE, 0, (struct sockaddr *) & serv_addr, & Nbytes); 

     if (msg_tam <0) 
      Abort ("..."); 

     buffer [msg_tam] = 0; 

    if (SERV_HOST_PORT == ntohs (serv_addr.sin_port) & & strcmp (SERV_HOST_ADDR, (char *) inet_ntoa (serv_addr.sin_addr) == 0) 
 ( 
 ... 
 ) 
 else 
     printf ( "message of unknown origin!"); 

The SERV_HOST_ADDR is set to "255.255.255.255" so the client can send the file request to the network and the port is also set with a value.Well, the problem arises when the call to the function recvfrom is made, where the ip address of who sent the message is filled in the structure.That address is ,thus, the address where the server is.
As so, when making the comparison between the SERV_HOST_ADDR in the if statement with the address serv_addr.sin_addr filled in the recvfrom call, they will never be the same (even if the reply has come from the server) ,as a it will always enter the else statement.

I would appreciate if someone could help me solve this problem, so that it would be a way the client could check you check whether the reply comes from the server where the client sent the message or from another place.

Thanks in advance for your help!

The last IP address in a network range is always considered unusable. It is, in fact, used for broadcast messages, meaning that (to my knowledge), you cannot create sockets with it. Also in the code above you have a space between the two ampersands. (& &). If that isn't just an artifact of copying the code into a webform, it's a bug.