MCPcopy Create free account
hub / github.com/MaxBelkov/visualsyslog / SimpleOpen

Method SimpleOpen

sourcecommon/udp.cpp:177–258  ·  view source on GitHub ↗

---------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

175}
176//---------------------------------------------------------------------------
177bool TUDP::SimpleOpen(char * local, WORD lport, char * dest, WORD dport)
178{
179 Error = 0;
180 WSAError = 0;
181
182 if( handle || !local || !dest )
183 {
184 WSAError = MYERROR_UNKNOWNPARAMS;
185 Error = 1;
186 if( Exceptions ) throw 0;
187 return !Error;
188 }
189
190 in_addr l;
191 l.S_un.S_addr = inet_addr(local);
192 if( l.S_un.S_addr==4294967295 ) // host name OR error in IP address
193 {
194 // try to resolve host name and copy to l
195 HOSTENT * hostent = gethostbyname(local);
196 if( hostent )
197 {
198 // hostent->h_name ---> Full local name
199 l.S_un = ((in_addr *)hostent->h_addr_list[0])->S_un;
200 }
201 else
202 {
203 //l.S_un.S_addr = INADDR_ANY; // ��������� ����� ����� ���� �������
204 WSAError = WSAGetLastError();
205 Error = 2;
206 if( Exceptions ) throw 0;
207 return !Error;
208 }
209 }
210 in_addr d;
211 d.S_un.S_addr = inet_addr(dest);
212 if( d.S_un.S_addr==4294967295 ) // host name OR error in IP address
213 {
214 // try to resolve host name and copy to d
215 HOSTENT * hostent = gethostbyname(dest);
216 if( hostent )
217 {
218 // hostent->h_name ---> Full dest name
219 d.S_un = ((in_addr *)hostent->h_addr_list[0])->S_un;
220 }
221 else
222 {
223 //d.S_un.S_addr = INADDR_ANY; // ��������� ����� ����� ���� �������
224 WSAError = WSAGetLastError();
225 Error = 3;
226 if( Exceptions ) throw 0;
227 return !Error;
228 }
229 }
230
231 SOCKET h;
232
233 // open a TCP socket
234 h = socket(AF_INET, SOCK_DGRAM, 0);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected