Skip to content

Commit

Permalink
Macro'ed out GETHOSTBYNAME, and fixed if-statement braces to be on a …
Browse files Browse the repository at this point in the history
…new line for consistency
  • Loading branch information
frederickproctor committed Oct 30, 2014
1 parent aa9b575 commit 5592ff9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions simple_message/include/simple_message/socket/simple_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#endif
#define INET_ADDR(str) inet_addr(str)
#define SOCKLEN_T socklen_t
#define GETHOSTBYNAME(str) gethostbyname(str)

#endif

Expand Down Expand Up @@ -110,6 +111,7 @@ extern "C" STATUS setsockopt ( /* remove "extern C", if you're using C instead
#define HTONS(num) mpHtons(num)
#define INET_ADDR(str) mpInetAddr(str)
#define SOCKLEN_T unsigned int
#define GETHOSTBYNAME(str) NULL

#endif

Expand Down
2 changes: 1 addition & 1 deletion simple_message/include/simple_message/socket/tcp_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

#ifdef LINUXSOCKETS
#include "sys/socket.h"
#include "netdb.h" /* gethostbyname */
#include "netdb.h"
#include "arpa/inet.h"
#include "string.h"
#include "unistd.h"
Expand Down
10 changes: 7 additions & 3 deletions simple_message/src/socket/tcp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,18 @@ bool TcpClient::init(char *buff, int port_num)
LOG_WARN("Failed to set no socket delay, sending data can be delayed by up to 250ms");
}


// Initialize address data structure
memset(&this->sockaddr_, 0, sizeof(this->sockaddr_));
this->sockaddr_.sin_family = AF_INET;
if (NULL != (ent = gethostbyname(buff))) {

// Check for 'buff' as hostname, and use that, otherwise assume IP address
if (NULL != (ent = GETHOSTBYNAME(buff)))
{
in_a = (struct in_addr *) ent->h_addr_list[0];
this->sockaddr_.sin_addr.s_addr = in_a->s_addr;
} else {
}
else
{
this->sockaddr_.sin_addr.s_addr = INET_ADDR(buff);
}
this->sockaddr_.sin_port = HTONS(port_num);
Expand Down

0 comments on commit 5592ff9

Please sign in to comment.