mirror of
https://gitlab.com/obbart/universal_robots_ros_driver.git
synced 2026-04-12 19:10:47 +02:00
WIP
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <endian.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
|
||||
@@ -94,6 +95,23 @@ void TCPSocket::close()
|
||||
socket_fd_ = -1;
|
||||
}
|
||||
|
||||
std::string TCPSocket::getIP()
|
||||
{
|
||||
sockaddr_in name;
|
||||
socklen_t len = sizeof(name);
|
||||
int res = ::getsockname(socket_fd_, (sockaddr*)&name, &len);
|
||||
|
||||
if(res < 0)
|
||||
{
|
||||
LOG_ERROR("Could not get local IP");
|
||||
return std::string();
|
||||
}
|
||||
|
||||
char buf[128];
|
||||
inet_ntop(AF_INET, &name.sin_addr, buf, sizeof(buf));
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
bool TCPSocket::read(uint8_t *buf, size_t buf_len, size_t &read)
|
||||
{
|
||||
read = 0;
|
||||
|
||||
Reference in New Issue
Block a user