ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/socket++-1.10/sockinet.h
Revision: 1.1
Committed: Mon Feb 26 15:01:39 2001 UTC (23 years, 9 months ago) by ab11
Content type: text/plain
Branch: MAIN
CVS Tags: PROJECT_COMPLETION
Log Message:
Networking class. Assumed to be bug free.

File Contents

# User Rev Content
1 ab11 1.1 // sockinet.h -*- C++ -*- socket library
2     // Copyright (C) 1992,1993,1994 Gnanasekaran Swaminathan <gs4t@virginia.edu>
3     //
4     // Permission is granted to use at your own risk and distribute this software
5     // in source and binary forms provided the above copyright
6     // notice and this paragraph are preserved on all copies.
7     // This software is provided "as is" with no express or implied warranty.
8     //
9     // Version: 17Oct95 1.10
10    
11     #ifndef _SOCKINET_H
12     #define _SOCKINET_H
13    
14     #include <sockstream.h>
15     #include <netinet/in.h>
16    
17     class sockinetaddr: public sockAddr, public sockaddr_in {
18     protected:
19     void setport (const char* sn, const char* pn="tcp");
20     void setaddr (const char* hn);
21     public:
22     ~sockinetaddr () {}
23     sockinetaddr ();
24     sockinetaddr (unsigned long addr, int port_no=0);
25     sockinetaddr (const char* host_name, int port_no=0);
26     sockinetaddr (unsigned long addr,
27     const char* service_name,
28     const char* protocol_name="tcp");
29     sockinetaddr (const char* host_name,
30     const char* service_name,
31     const char* protocol_name="tcp");
32     sockinetaddr (const sockinetaddr& sina);
33     operator void* () const { return (sockaddr_in*)this; }
34    
35     int size() const { return sizeof (sockaddr_in); }
36     int family() const { return sin_family; }
37     sockaddr* addr() const {return (sockaddr*)((sockaddr_in*)this); }
38    
39     int getport() const;
40     const char* gethostname() const;
41     };
42    
43     class sockinetbuf: public sockbuf {
44     protected:
45     sockinetbuf& operator=(const sockbuf& si); // needs to be fixed
46     sockinetbuf& operator=(const sockinetbuf& si); // needs fixing
47     public:
48     enum domain { af_inet = AF_INET };
49    
50     sockinetbuf (const sockbuf& si): sockbuf(si) {}
51     sockinetbuf (const sockinetbuf& si): sockbuf (si) {}
52     sockinetbuf (sockbuf::type ty, int proto=0);
53    
54     sockbuf* open (sockbuf::type, int proto=0);
55    
56     sockinetaddr localaddr() const;
57     int localport() const;
58     const char* localhost() const;
59    
60     sockinetaddr peeraddr() const;
61     int peerport() const;
62     const char* peerhost() const;
63    
64     int bind_until_success (int portno);
65    
66     virtual int bind (sockAddr& sa);
67     int bind ();
68     int bind (unsigned long addr, int port_no=0);
69     int bind (const char* host_name, int port_no=0);
70     int bind (unsigned long addr,
71     const char* service_name,
72     const char* protocol_name="tcp");
73     int bind (const char* host_name,
74     const char* service_name,
75     const char* protocol_name="tcp");
76    
77     virtual int connect (sockAddr& sa);
78     int connect (unsigned long addr, int port_no=0);
79     int connect (const char* host_name, int port_no=0);
80     int connect (unsigned long addr,
81     const char* service_name,
82     const char* protocol_name="tcp");
83     int connect (const char* host_name,
84     const char* service_name,
85     const char* protocol_name="tcp");
86    
87     };
88    
89     class isockinet: public isockstream
90     {
91     public:
92     isockinet (const sockbuf& sb);
93     isockinet (sockbuf::type ty=sockbuf::sock_stream,
94     int proto=0);
95     ~isockinet ();
96    
97     sockinetbuf* rdbuf () { return (sockinetbuf*)ios::rdbuf (); }
98     sockinetbuf* operator -> () { return rdbuf (); }
99     };
100    
101     class osockinet: public osockstream
102     {
103     public:
104     osockinet (const sockbuf& sb);
105     osockinet (sockbuf::type ty=sockbuf::sock_stream,
106     int proto=0);
107     ~osockinet ();
108    
109     sockinetbuf* rdbuf () { return (sockinetbuf*)ios::rdbuf (); }
110     sockinetbuf* operator -> () { return rdbuf (); }
111     };
112    
113     class iosockinet: public iosockstream
114     {
115     public:
116     iosockinet (const sockbuf& sb);
117     iosockinet (sockbuf::type ty=sockbuf::sock_stream,
118     int proto=0);
119     ~iosockinet ();
120    
121     sockinetbuf* rdbuf () { return (sockinetbuf*)ios::rdbuf (); }
122     sockinetbuf* operator -> () { return rdbuf (); }
123     };
124    
125     #endif // _SOCKINET_H