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