// Objective: Packaging sockets can be used to send to the network, receive data. Blocking the call function. // Description: This class is extracted and modified from the "VC 6.0 technology insider"
#if! defined (_socket_h) #define _socket_h
#include
#pragma comment (Lib, "WS2_32.LIB")
class CSockAddr: public sockaddr_in {public: // Constructor CSockAddr () {sin_family = AF_INET; sin_port = 0; sin_addr.s_addr = 0;} // Default CSockAddr (const SOCKADDR & sa) {memcpy (this, & sa, sizeof (SOCKADDR ));} Csockaddr (const sockaddr_in & sin) {memcpy (this, & sin));} // uLaddr is INADDR_ANY, default is that the unit is an IP CSOCKADDR (Const Ulong ULADDR, Const USHORT Ushport = 0) / / parms are host byte ordered {sin_family = AF_INET; sin_port = htons (ushPort); sin_addr.s_addr = htonl (ulAddr);} CSockAddr (const char * pchIP, const USHORT ushPort = 0) // dotted IP addr string {sin_family = AF_INET; sin_port = htons (ushPort); sin_addr.s_addr = inet_addr (pchIP);} // already network byte ordered // return address LPCTSTR GetIPDottedDecimal point format () {return inet_ntoa (sin_addr);} // Get the port and Address (Host Sequence) Ushort port () const {return ntoHS (SIN_PORT);} // Get an IP address (host order) ulong ipaddr () const {return ntohl (sin_addr.s_addr);} // Conversion and assignment const CsockAddr & Operator = (const SockAddr & Sa) {Memcpy (th is, & sa, sizeof (SOCKADDR)); return * this;} const CSockAddr & operator = (const SOCKADDR_IN & sin) {memcpy (this, & sin, sizeof (SOCKADDR_IN)); return * this;} operator SOCKADDR () {return * ( (Lpsockaddr);} Operator lpsockAddr () {Return (lpsockAddr) this;} Operator lpsockaddr_in () {return (lpsockaddr_in).