Hi everyone,
I'm looking for a function to retrieve the IP-Adress of a client TCP Socket. I found this function as part of other driver frameworks already so I'm quite shure there is a way to do so. Does anybody has an idea?
Many Thanks,
Jonathan
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi everyone,
I'm looking for a function to retrieve the IP-Adress of a client TCP Socket. I found this function as part of other driver frameworks already so I'm quite shure there is a way to do so. Does anybody has an idea?
Many Thanks,
Jonathan
Hi Jonathan,
After the TCP server's accept call returns a non-negative value, you can access the first 4 octets of the client IP address through
tSocketClientAddr.sa_data[5],
tSocketClientAddr.sa_data[4],
tSocketClientAddr.sa_data[3],
tSocketClientAddr.sa_data[2],
Where tSocketClientAddr is defined as sockaddr tSocketClientAddr;
You can place a call to 'accept' as shown below:
sock = accept(ulSocket,
&tSocketClientAddr,
(socklen_t *)sizeof(tSocketClientAddr));
Regards,
Raghavendra
How do I apply this to Arduino Mega with CC3000 Shield? I do not understand how it gets used!
William