I have to send the client's IP according to the protocol, but I don't know how.
I am making Socket TCP communication server in C according to the protocol.
As soon as the client accesses, the data must be sent to that IP.
The protocol includes: SendIP(16BYTE) DestinationIP(16BYTE) ...
IP digits must match like 000.000.000.000- (ex. 127.000.000.001)
Please give me some hint!
I put the IP I received in the structure and received the digits of . If the subtracted value was not 4, I shifted the digits one by one.
struct UserData {
char Ip_Address[16];
char port[10];
char strConnTime[30];
char strCloseTime[30];
};
UserData m_user_list[10];
while(1)
{
dlg->accept_sock = accept(dlg->server_sock, (SOCKADDR*)&dlg->accept_addr, &size);
if (dlg->accept_sock == SOCKET_ERROR)
{
break;
}
strcpy(m_user_list[index].Ip_Address, inet_ntoa(dlg->accept_addr.sin_addr));
int count = 0;
int dotcount[3];
for (int i = 0; i <= 16; i++)
{
if (m_user_list[index].Ip_Address[i] == '.')
{
dotcount[count++] = i;
}
}
if (dotcount[0] - dotcount[1] != 4)
{
for (int j = 0; j <= 16; j++)
{
m_user_list[index].Ip_Address[j + 1] = m_user_list[index].Ip_Address[j];
}
}
}