1 | /*
|
---|
2 | Copyright (C) 1996
|
---|
3 |
|
---|
4 | This program is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2 of the License, or
|
---|
7 | (at your option) any later version.
|
---|
8 |
|
---|
9 | This program is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License
|
---|
15 | along with this program; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
17 |
|
---|
18 | The author can be contacted via Email at [email protected]
|
---|
19 | */
|
---|
20 |
|
---|
21 | /*
|
---|
22 | Module Name: Net IO
|
---|
23 | Purpose: High level Socket IO and Misc socket routines
|
---|
24 | Public Functions:
|
---|
25 | InitNetIO
|
---|
26 | CleanUpNetIO
|
---|
27 |
|
---|
28 | GetLocalIP
|
---|
29 | GetLocalName
|
---|
30 |
|
---|
31 | CreateListeningSocket
|
---|
32 | AnswerListeningSocket
|
---|
33 | DestroyListeningSocket
|
---|
34 |
|
---|
35 | CloseSocket
|
---|
36 |
|
---|
37 | GetData
|
---|
38 | GetLine
|
---|
39 |
|
---|
40 | SendData
|
---|
41 | SendFile
|
---|
42 | */
|
---|
43 |
|
---|
44 | //Public definitions
|
---|
45 | //Max line size for GetLine
|
---|
46 | #define NETIO_MAX_LINE 300
|
---|
47 |
|
---|
48 | //Public Functions
|
---|
49 |
|
---|
50 | /*
|
---|
51 | Function Name: Init Net IO
|
---|
52 | Purpose: Initializes the module so calls can be made querying network
|
---|
53 | information for the local macnine.
|
---|
54 | Notes: MUST be called before GetLocalIP and GetLocalName
|
---|
55 | */
|
---|
56 |
|
---|
57 | // returns 0 on success,
|
---|
58 | // WSASYSNOTREADY, WSAVERNOTSUPPORTED, or WSAEINVAL on failure
|
---|
59 | int InitNetIO();
|
---|
60 |
|
---|
61 | /*
|
---|
62 | Function Name: Cleanup Net IO
|
---|
63 | Purpose: Cleans up the module and unloads Winsock
|
---|
64 | */
|
---|
65 | void CleanUpNetIO();
|
---|
66 |
|
---|
67 | /*
|
---|
68 | Function Name: Reset Net IO
|
---|
69 | Purpose: Resets internal data in NetIO to reflect registry changes, etc.
|
---|
70 | */
|
---|
71 | void ResetNetIO();
|
---|
72 |
|
---|
73 | /*
|
---|
74 | Function Name: Get Local IP
|
---|
75 | Purpose: Gets the local IP number
|
---|
76 | Returns: The local IP number as an double word (4 bytes)
|
---|
77 | */
|
---|
78 | DWORD GetLocalIP();
|
---|
79 |
|
---|
80 | /*
|
---|
81 | Function Name: Get Local Name
|
---|
82 | Purpose: Gets the local Domain name, or if there is none, then the server
|
---|
83 | address in dotted format.
|
---|
84 | Returns: A string containing the local address
|
---|
85 | */
|
---|
86 | char *GetLocalName(HINSTANCE hInstance);
|
---|
87 |
|
---|
88 | // returns 0 on success, and a WSA error message on failure.
|
---|
89 | // possible error messages include:
|
---|
90 | // WSANOTINITIALISED, WSAENETDOWN, WSAEAFNOSUPPORT, WSAEINPROGRESS, WSAEMFILE,
|
---|
91 | // WSAENOBUFS, WSAEPROTONOSUPPORT, WSAEPROTOTYPE, WSAESOCKTNOSUPPORT,
|
---|
92 | // WSAEADDRINUSE, WSAEINVAL, WSAEISCONN, WSAENOTSOCK, WSAEOPNOTSUPP
|
---|
93 | int CreateListeningSocket(int &PortNum, HWND MsgWindow, WORD SocketMsg, SOCKET &ServerSocket);
|
---|
94 |
|
---|
95 | int AnswerListeningSocket(SOCKET ServerSocket, SOCKET &ClientSocket, SOCKADDR_IN &ClientSockAddr, int AddrLen);
|
---|
96 |
|
---|
97 | void DestroyListeningSocket(SOCKET &ServerSocket, HWND MsgWindow);
|
---|
98 |
|
---|
99 | void CloseSocket(SOCKET &TargetSocket);
|
---|
100 |
|
---|
101 | /*
|
---|
102 | Function Name: Get Data
|
---|
103 | Purpose: Gets data from a socket with muli-threaded debugging
|
---|
104 | Parameters:
|
---|
105 | ClientSocket - The socket to get data from
|
---|
106 | IOBuffer - A pointer to a chunk of memory to put data in
|
---|
107 | IOBufferSize - Size of the buffer
|
---|
108 | ThreadNum - Number of the thread that called this functions used for debugging
|
---|
109 |
|
---|
110 | Returns: -1 on error, else the number of bytes received
|
---|
111 |
|
---|
112 | Notes:
|
---|
113 | Removed socket error checking because I was unable to isolate what
|
---|
114 | errors I was getting when getting a "rude" disconnect
|
---|
115 | */
|
---|
116 | int GetData(SOCKET ClientSocket, BYTE *IOBuffer, int IOBufferSize, int ThreadNum);
|
---|
117 |
|
---|
118 | /*
|
---|
119 | Function Name: Get Line
|
---|
120 | Purpose: Gets a line of text (ended by a LF (10)) from a socket with buffered
|
---|
121 | input. If the buffer is empty this function fills the buffer, else it
|
---|
122 | just changes an index. Also has the ability to do multi-threaded debuging
|
---|
123 | Parameters:
|
---|
124 | OutStr - Varible were output is put (a length of NETIO_MAX_LINE is assumed)
|
---|
125 | ClientSocket - The socket to get data from
|
---|
126 | IOBuffer - A pointer to a chunk of memory to put data in
|
---|
127 | IOBufferSize - Size of the buffer
|
---|
128 | BufferIndex - A zero based index of what charactor in the buffer we're at
|
---|
129 | DataInBuffer - Amount of data in the buffer
|
---|
130 | ThreadNum - Number of the thread that called this functions used for debugging
|
---|
131 |
|
---|
132 | Returns: -1 on disconnect or error (abort connection), 0 on success
|
---|
133 | */
|
---|
134 | int GetLine(char *OutStr, SOCKET ClientSocket, BYTE *IOBuffer, int IOBufferSize, int &BufferIndex, int &DataInBuffer, int ThreadNum);
|
---|
135 |
|
---|
136 | /*
|
---|
137 | Function Name: Send Data
|
---|
138 | Purpose: Sends data to a socket with muli-thread debugging
|
---|
139 | Parameters:
|
---|
140 | ClientSocket - The socket to get data from
|
---|
141 | SendBuffer - A pointer to a chunk of memory to put data in
|
---|
142 | NumToSend - Number of bytes to send from buffer
|
---|
143 | ThreadNum - Number of the thread that called this functions used for debugging
|
---|
144 |
|
---|
145 | Returns: -1 on error, 0 on success
|
---|
146 |
|
---|
147 | Notes:
|
---|
148 | Removed socket error checking because I was unable to isolate what
|
---|
149 | errors I was getting when getting a "rude" disconnect
|
---|
150 | */
|
---|
151 | int SendData(SOCKET ClientSocket, BYTE *SendBuffer, int NumToSend, int ThreadNum);
|
---|