Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MNSocket Class Reference

#include <MNSocket.h>

Inheritance diagram for MNSocket:

Inheritance graph
[legend]
Collaboration diagram for MNSocket:

Collaboration graph
[legend]
List of all members.

Public Types

enum  SocketFlags { TakeoverFlag = 0x1 }

Public Member Functions

bool mcast_join_new (struct sockaddr *sa, char *ifname)
int mcast_leave (int sockfd, const struct sockaddr *sa, char *ifname)
int mcast_set_if (int sockfd, const char *ifname)
int mcast_set_loop (int sockfd, int onoff)
int mcast_set_ttl (int sockfd, int val)
int mcast_get_if (int sockfd)
int mcast_get_loop (int sockfd)
int mcast_get_ttl (int sockfd)
void make_socket (int type)
void make_socket (int domain, int type)
void remake_socket (int type)
void remake_socket (int domain, int type)
void listen ()
int bind (int port)
int bind (int port, const char *hostname)
void broadcast ()
const char * get_ipaddr (char *buffer, size_t len)
bool get_sock_name (struct sockaddr_in &addr) const
bool get_addr (struct sockaddr_in &addr) const
 another name for get_sock_name, may be easier to remember
int get_socktype ()
 Returns SOCK_STREAM if socket is TCP and SOCK_DGRAM if socket is UDP.
 MNSocket (MNSocket &orig, int socketflags=0)
 MNSocket ()
 MNSocket (int sock)
virtual ~MNSocket ()
int ok ()
int port ()
void master (bool controlSocket)
virtual int get_sockdesc () const
virtual void set_sockdesc (int socket)
virtual void update_ports ()
virtual bool isUdp () const =0
int l1_receive (struct msghdr *hdr)
int l1_receive (struct iovec *iov, int iovlen, struct sockaddr_in *dest)
int l1_receive (char *buffer, int max_len)
int send (struct iovec *iov, int iov_count, const struct sockaddr_in *dest)
void reuseaddress ()
void linger ()
void nolinger ()
void nodelay ()
void noblock ()
virtual void connection_closed ()
virtual const char * get_title ()

Static Public Member Functions

bool set_addr (int port, const char *hostname, struct sockaddr_in &server_addr)
bool isMulticast (const char *hname)
const char * getLocalNameForAddr (struct in_addr *addr, char *buffer)

Member Enumeration Documentation

enum MNSocket::SocketFlags
 

Enumeration values:
TakeoverFlag 


Constructor & Destructor Documentation

MNSocket::MNSocket MNSocket orig,
int  socketflags = 0
 

Make a copy of the current socket. Either forbid the new object to control the socket (controlSocket==false) or pass the control. In the latter case, the caller must release the control of the original.

MNSocket::MNSocket  ) 
 

MNSocket::MNSocket int  sock  ) 
 

virtual MNSocket::~MNSocket  )  [virtual]
 


Member Function Documentation

int MNSocket::bind int  port,
const char *  hostname
 

Bind the valid, open socket to the given port. If the hostname parameter is a multicast address in dotted decimal notation, the try to join the multicast group as well. If the hostname is the name of an interface of the localhost, try to bind to that interface instead of INADDR_ANY.

int MNSocket::bind int  port  ) 
 

Bind the valid, open socket to the given port on an OS-selected interface (INADDR_ANY).

void MNSocket::broadcast  ) 
 

virtual void MNSocket::connection_closed  )  [virtual]
 

bool MNSocket::get_addr struct sockaddr_in &  addr  )  const [inline]
 

another name for get_sock_name, may be easier to remember

const char* MNSocket::get_ipaddr char *  buffer,
size_t  len
 

Initialized or overwrite the internal variables my_port and my_address with the actual information of this bound and connected socket. If a buffer is provided, the dotted decimal notation of the address for this socket is written into the buffer, if possible, and a pointer to the buffer is returned. If no buffer is provided, the return value must be ignored.

Parameters:
buffer A buffer to some space that will holds the IP address in dotted decimal notation on return, if the return value is non-NULL. The parameter may be NULL.
len The length of the buffer.
Return values:
undefined If the buffer parameter is NULL or if the len parameter is NULL.
NULL If no IP4 hostname for the current socket could be determined.
otherwise A pointer to buffer.

bool MNSocket::get_sock_name struct sockaddr_in &  addr  )  const
 

Write the sockaddr_in structure for this socket into the OUT parameter that the caller provide.

Parameters:
addr An OUT parameter that holds the sockaddr information of this MNSocket on return if the return value is true.
Return values:
true if the address structure has been filled successfully.
false If something went wrong and the structure is invalid. An error message has been printed in this case.

virtual int MNSocket::get_sockdesc  )  const [inline, virtual]
 

Implements MNSocketBase.

int MNSocket::get_socktype  ) 
 

Returns SOCK_STREAM if socket is TCP and SOCK_DGRAM if socket is UDP.

virtual const char* MNSocket::get_title  )  [virtual]
 

const char* MNSocket::getLocalNameForAddr struct in_addr *  addr,
char *  buffer
[static]
 

Helper function to retrieve on of the local hostnames, specifically the one that we need. It is useful when we have a client socket that was bound to the correct interface automatically using INADDR_ANY and now we want to communicate over the same interface again (as server socket, as UDP socket, etc). Using information about the existing socket, its name is established for passing to a remote host or process.

Parameters:
addr This structure holds information about the existing socket.
buffer This parameter points to a buffer that will contain the name of the interface on return. It is expected that this buffer is INET_ADDRSTRLEN bytes long.
Returns:
A pointer to the buffer, or NULL in case of failure.

bool MNSocket::isMulticast const char *  hname  )  [static]
 

Check whether the given string is a multicast address in dotted decimal notation.

Parameters:
hname A hostname
Return values:
true is returned when the given string represents a valid multicast address in dotted decimal notation.
false is returned if the given string is not in dotted decimal notation or if the address is not in the range of addresses that are reserved for IP multicast.

virtual bool MNSocket::isUdp  )  const [inline, pure virtual]
 

Function is used in child classes to tell the world what kind of protocol the socket is besed on. UDP child classes will return true and TCP child classes will return false.

Returns:
A boolean that returns true for UDP and false for TCP.

Implemented in MNTCPSocket, and MNUDPSocket.

int MNSocket::l1_receive char *  buffer,
int  max_len
 

int MNSocket::l1_receive struct iovec *  iov,
int  iovlen,
struct sockaddr_in *  dest
 

int MNSocket::l1_receive struct msghdr *  hdr  ) 
 

void MNSocket::linger  ) 
 

void MNSocket::listen  ) 
 

void MNSocket::make_socket int  domain,
int  type
 

void MNSocket::make_socket int  type  ) 
 

void MNSocket::master bool  controlSocket  ) 
 

int MNSocket::mcast_get_if int  sockfd  ) 
 

int MNSocket::mcast_get_loop int  sockfd  ) 
 

int MNSocket::mcast_get_ttl int  sockfd  ) 
 

bool MNSocket::mcast_join_new struct sockaddr *  sa,
char *  ifname
 

This function tries to join the given multicast interface with this valid, open socket. The advantage over the bind function with two parameters is that the local bind operation is explicit. Furthermore, an interface can be chosen explicitely. This doesn't work with the two-parameter bind call. But a three parameter bind call may be in order that solves both of these issues at the same time. Function works only for the first linux interface (eth0). a new function must be added that finds all interfaces on the machine and determines which are capable of multicast.

Return values:
true The join operation was successfully initiated. This doesn't mean that the routers react accordingly.
false Something failed locally in the join operation.

int MNSocket::mcast_leave int  sockfd,
const struct sockaddr *  sa,
char *  ifname
 

int MNSocket::mcast_set_if int  sockfd,
const char *  ifname
 

int MNSocket::mcast_set_loop int  sockfd,
int  onoff
 

int MNSocket::mcast_set_ttl int  sockfd,
int  val
 

void MNSocket::noblock  ) 
 

void MNSocket::nodelay  ) 
 

void MNSocket::nolinger  ) 
 

int MNSocket::ok  ) 
 

int MNSocket::port  ) 
 

void MNSocket::remake_socket int  domain,
int  type
 

void MNSocket::remake_socket int  type  ) 
 

void MNSocket::reuseaddress  ) 
 

int MNSocket::send struct iovec *  iov,
int  iov_count,
const struct sockaddr_in *  dest
 

send prepares the iovec structure for transmission with sendmsg and sends it to the given target.

Parameters:
iov A pointer to an array of iovec structures.
iov_count The number of iovec structures in the array.
dest The sockaddr structure of the target to which the buffers in the iovec will be sent.
Returns:
The number of bytes written, or -1 in case of error.

bool MNSocket::set_addr int  port,
const char *  hostname,
struct sockaddr_in &  server_addr
[static]
 

This function fills the sockaddr_in structure in for the given port number and host name. If this is successful, true is returned, and false otherwise. The old version of the function returned the sockaddr_in structure itself, which had three disadvantages: It was not possible to know whether the operation was successful or not The entire structure had to be copied back and forth a few times, while a call-by-reference allows to fill in the target structure directly An extension for IPv6 is simple, and nearly interface compatible except for the return value.

Parameters:
port The port number to be filled into the sockaddr_in structure.
hostname The name of the host, whose IP address will be filled into the sockaddr_in structure. Right now, this is only IPv4.
server_addr A reference to buffer space that can take a sockaddr_in structure. This is an OUT-variable.
Returns:
True if the operation was successful, false is it was not successful. The operation fails only if the hostname resolution via gethostbyname() fails.

virtual void MNSocket::set_sockdesc int  socket  )  [inline, virtual]
 

virtual void MNSocket::update_ports  )  [virtual]
 


The documentation for this class was generated from the following file:
Generated on Sun Mar 6 13:36:02 2005 for Komssys by doxygen 1.3.8