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

MNSocket.h

Go to the documentation of this file.
00001 /* Copyright (C) 2000 KOM/Darmstadt University of Technology 00002 * 00003 * You are allowed to use all other parts of the code under the following terms: 00004 * 00005 * For non-commercial use, code may be used in unmodified form provided 00006 * that this copyright notice and this permission notice appear in 00007 * supporting documentation. 00008 * 00009 * This software is provided "as is" and without any express or implied 00010 * warranties, including, without limitation, the implied warranty of 00011 * fitness for a particular purpose. 00012 * 00013 * The code may be subjected to the GNU General Public License, Version 2, 00014 * and re-distributed under the terms of this license. 00015 * As a special exception, permission is granted to link this code 00016 * with the Qt library and distribute executables, as long as you 00017 * follow the requirements of the GNU GPL in regard to all of the 00018 * software in the executable aside from Qt. 00019 * 00020 * Commercial use other than under the terms of the GNU General Public 00021 * License is allowed only after express negotiation of conditions 00022 * with the authors. 00023 */ 00024 #ifndef MN_OS_NET_SOCKET_H 00025 #define MN_OS_NET_SOCKET_H 00026 00027 #include <config.h> 00028 00029 /************************************************************* 00030 * Classes defined in this header file: 00031 * MNSocket 00032 */ 00033 00034 /************************************************************* 00035 * MNSocket 00036 */ 00037 00038 00039 #include <sys/types.h> 00040 #include <sys/socket.h> 00041 #include <net/if.h> 00042 #include <sys/ioctl.h> 00043 #include <netinet/in.h> 00044 00045 #include "mnstream.h" 00046 #include "MNSocketBase.h" 00047 00048 class MNSelector; 00049 00050 #define IFI_NAME 16 /* same as IFNAMSIZ in <net/if.h> */ 00051 #define IFI_HADDR 8 /* allow for 64-bit EUI-64 in future */ 00052 #define IFI_ALIAS 1 /* ifi_addr is an alias */ 00053 00054 ostream& operator<<( ostream& ostr, const struct sockaddr_in& addr ); 00055 00056 /*********************************************************************** 00057 * ifi_info - interface information 00058 ***********************************************************************/ 00059 00060 struct ifi_info 00061 { 00062 char ifi_name[IFI_NAME]; /* interface name, null terminated */ 00063 u_char ifi_haddr[IFI_HADDR]; /* hardware address */ 00064 u_short ifi_hlen; /* #bytes in hardware address: 0, 6, 8 */ 00065 short ifi_flags; /* IFF_xxx constants from <net/if.h> */ 00066 short ifi_myflags; /* our own IFI_xxx flags */ 00067 struct sockaddr *ifi_addr; /* primary address */ 00068 struct sockaddr *ifi_brdaddr;/* broadcast address */ 00069 struct sockaddr *ifi_dstaddr;/* destination address */ 00070 struct ifi_info *ifi_next; /* next of these structures */ 00071 }; 00072 00073 /*********************************************************************** 00074 * MNSocket 00075 ***********************************************************************/ 00076 00077 class MNSocket 00078 : public MNSocketBase 00079 { 00080 int my_socket; 00081 int my_ok; 00082 int my_port; 00083 struct in_addr my_address; 00084 bool _master; 00085 bool _is_mc; 00086 00087 public: 00088 /* 00089 * socketflags for the modified copy constructor 00090 */ 00091 enum SocketFlags 00092 { 00093 TakeoverFlag = 0x1 00094 }; 00095 00096 public: 00112 bool mcast_join_new( struct sockaddr *sa, char *ifname ); 00113 int mcast_leave(int sockfd, const struct sockaddr *sa, char *ifname); 00114 int mcast_set_if(int sockfd, const char *ifname); 00115 int mcast_set_loop(int sockfd, int onoff); 00116 int mcast_set_ttl(int sockfd, int val); 00117 int mcast_get_if(int sockfd); 00118 int mcast_get_loop(int sockfd); 00119 int mcast_get_ttl(int sockfd); 00120 00147 static bool set_addr ( int port, 00148 const char* hostname, 00149 struct sockaddr_in& server_addr ); 00150 00151 void make_socket ( int type ); 00152 void make_socket ( int domain, int type ); 00153 void remake_socket ( int type ); // close and reopen 00154 void remake_socket ( int domain, int type ); // close and reopen 00155 void listen ( ); 00156 00160 int bind ( int port ); 00161 00168 int bind ( int port, const char* hostname ); 00169 00170 void broadcast ( ); 00171 00194 const char* get_ipaddr( char* buffer, size_t len ); 00195 00205 bool get_sock_name( struct sockaddr_in& addr ) const; 00206 00208 inline bool get_addr( struct sockaddr_in& addr ) const { 00209 return get_sock_name( addr ); 00210 } 00211 00213 int get_socktype(); 00214 00215 private: 00217 MNSocket( const MNSocket& orig ); 00218 00220 MNSocket& operator=( const MNSocket& orig ); 00221 00222 public: 00228 MNSocket ( MNSocket& orig, int socketflags = 0 ); 00229 MNSocket ( ); 00230 MNSocket ( int sock ); 00231 virtual ~MNSocket ( ); 00232 00243 static bool isMulticast( const char* hname ); 00244 00260 static const char* getLocalNameForAddr( struct in_addr* addr, char* buffer ); 00261 00262 int ok ( ); 00263 int port ( ); 00264 void master ( bool controlSocket ); 00265 virtual int get_sockdesc ( ) const { return my_socket; } 00266 virtual void set_sockdesc ( int socket ) { my_socket = socket; } 00267 virtual void update_ports ( ); 00273 inline virtual bool isUdp() const = 0; 00274 00275 int l1_receive ( struct msghdr* hdr ); 00276 int l1_receive ( struct iovec* iov, 00277 int iovlen, 00278 struct sockaddr_in* dest ); 00279 int l1_receive ( char* buffer, int max_len ); 00280 00292 int send ( struct iovec* iov, 00293 int iov_count, 00294 const struct sockaddr_in* dest ); 00295 00296 void reuseaddress ( ); 00297 void linger ( ); 00298 void nolinger ( ); 00299 void nodelay ( ); 00300 void noblock ( ); 00301 // const char* str_errno ( ); 00302 00303 virtual void connection_closed ( ); 00304 00305 virtual const char* get_title ( ); 00306 }; 00307 00308 #endif /* MN_OS_NET_SOCKET_H */ 00309

Generated on Sun Mar 6 13:35:49 2005 for Komssys by doxygen 1.3.8