artdaq  v3_04_01
TCPConnect.hh File Reference
#include <netinet/in.h>

Go to the source code of this file.

Functions

int ResolveHost (char const *host_in, in_addr &addr)
 Convert a string hostname to a in_addr suitable for socket communication. More...
 
int GetIPOfInterface (std::string interface_name, in_addr &addr)
 Get the IP address associated with a given interface name. More...
 
int AutodetectPrivateInterface (in_addr &addr)
 Pick a private IP address on this host. More...
 
int GetInterfaceForNetwork (char const *host_in, in_addr &addr)
 Convert an IP address to the network address of the interface sharing the subnet mask. More...
 
int ResolveHost (char const *host_in, int dflt_port, sockaddr_in &sin)
 Convert a string hostname and port to a sockaddr_in suitable for socket communication. More...
 
int TCPConnect (char const *host_in, int dflt_port, long flags=0, int sndbufsiz=0)
 Connect to a host on a given port. More...
 

Detailed Description

Provides utility functions for connecting TCP sockets

Definition in file TCPConnect.hh.

Function Documentation

int AutodetectPrivateInterface ( in_addr &  addr)

Pick a private IP address on this host.

Parameters
[out]addrin_addr object populated with resolved host
Returns
0 if success, -1 if gethostbyname fails, 2 if defaulted to 0.0.0.0 (No matching interfaces)

The following preference order is used:

  1. 192.168.0.0/16
  2. 172.16.0.0/12
  3. 10.0.0.0/8
  4. 131.225.0.0/16
  5. 0.0.0.0 (returns 2)

Definition at line 127 of file TCPConnect.cc.

int GetInterfaceForNetwork ( char const *  host_in,
in_addr &  addr 
)

Convert an IP address to the network address of the interface sharing the subnet mask.

Parameters
host_inIP to resolve
[out]addrin_addr object populated with resolved host
Returns
0 if success, -1 if gethostbyname fails, 2 if defaulted to 0.0.0.0 (No matching interfaces)

Definition at line 217 of file TCPConnect.cc.

int GetIPOfInterface ( std::string  interface_name,
in_addr &  addr 
)

Get the IP address associated with a given interface name.

Parameters
interface_nameName of the interface to resolve
[out]addrin_addr object populated with interface IP
Returns
0 if success, -1 if gethostbyname fails, 2 if defaulted to 0.0.0.0 (No matching interfaces)

Definition at line 75 of file TCPConnect.cc.

int ResolveHost ( char const *  host_in,
in_addr &  addr 
)

Convert a string hostname to a in_addr suitable for socket communication.

Parameters
host_inName or IP of host to resolve
[out]addrin_addr object populated with resolved host
Returns
0 if success, -1 if gethostbyname fails

Definition at line 33 of file TCPConnect.cc.

int ResolveHost ( char const *  host_in,
int  dflt_port,
sockaddr_in &  sin 
)

Convert a string hostname and port to a sockaddr_in suitable for socket communication.

Parameters
host_inName or IP of host to resolve
dflt_portPOrt to populate in output
[out]sinsockaddr_in object populated with resolved host and port
Returns
0 if success, -1 if gethostbyname fails

Definition at line 306 of file TCPConnect.cc.

int TCPConnect ( char const *  host_in,
int  dflt_port,
long  flags = 0,
int  sndbufsiz = 0 
)

Connect to a host on a given port.

Parameters
host_inName or IP of the host to connect to
dflt_portPort to connect to
flagsTCP flags to use for the socket
sndbufsizSize of the send buffer. Set to 0 for automatic send buffer management
Returns
File descriptor of connected socket.

Definition at line 358 of file TCPConnect.cc.