FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
f_stccomm.c
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 #include "f_stccomm.h"
9 
11 /*#define DEBUG 1*/
12 
13 /* %%+HEAD: */
14 /*****************+***********+****************************************/
15 /* */
16 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
17 /* Postfach 11 05 41 */
18 /* D-6100 Darmstadt 11 */
19 /* */
20 /*1+ PLI Main ****************+****************************************/
21 /* */
22 /*+ Module : f_stc_read */
23 /* */
24 /*--------------------------------------------------------------------*/
25 /*+ CALLING : f_stc_read( INTS1 p_buffer , INTS4 i_buflen , */
26 /* INTS4 i_channel , INTS4 i_timeout ) */
27 /* */
28 /*--------------------------------------------------------------------*/
29 /* */
30 /*+ PURPOSE : f_stc_read read bytes from a connected socket */
31 /* and places them in a buffer (p_buffer). */
32 /* */
33 /*+ ARGUMENTS : */
34 /* */
35 /*+ p_buffer : Pointer to free data buffer. */
36 /* */
37 /*+ i_buflen : buffer length. */
38 /* */
39 /*+ i_channel : Id from the connected socket. */
40 /* */
41 /*+ i_timeout : Timeout value ( seconds ) for read from socket. */
42 /*- i_timeout = 0 : Return immediately after */
43 /* checking the connected socket. */
44 /*- i_timeout > 0 : Return when the specified socket */
45 /* is ready for I/O, but don't wait */
46 /* beyond a fixed amount of time. */
47 /*- i_timeout = -1 : Return only when the specified */
48 /* socket is ready for I/O. */
49 /* */
50 /*+ Return type : integer. */
51 /* */
52 /*2+DESCRIPTION***+***********+****************************************/
53 /* */
54 /*+ CALLING : f_stc_read ( INTS1 p_buffer , INTS4 i_buflen , */
55 /* INTS4 i_channel , INTS4 i_timeout ) */
56 /* */
57 /*+ ARGUMENTS : */
58 /* */
59 /*+ p_buffer : Pointer to free data buffer. */
60 /* */
61 /*+ i_buflen : buffer length. */
62 /* */
63 /*+ i_channel : Id from the connected socket. */
64 /* */
65 /*+ i_timeout : Timeout value ( seconds ) for read from socket. */
66 /* */
67 /*- i_timeout = 0 : Return immediately after checking */
68 /* the connected socket. */
69 /*- i_timeout > 0 : Return when the specified socket */
70 /* is ready for I/O, but don't wait */
71 /* beyond a fixed amount of time. */
72 /*- i_timeout = -1 : Return only when the specified */
73 /* socket is ready for I/O. */
74 /* */
75 /*+ FUNCTION : Read bytes from a connected socket and places them */
76 /* in a buffer (p_buffer) */
77 /* The procedure f_stc_read wait max timeout seconds */
78 /* getting data from the socket. */
79 /* */
80 /*+ REMARKS : - */
81 /* */
82 /*2+IMPLEMENTATION************+****************************************/
83 /* */
84 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
85 /*+ Return type : INTEGER */
86 /*+ Status codes: */
87 /*- STC__SUCCESS : success. */
88 /*- STC__FAIlURE : failure. */
89 /*- STC__INVSOCK : invalid socket number. */
90 /*- STC__INVBUF : buffer points outside allocated */
91 /* adress space. */
92 /*- STC__NGBUFSIZE : buffer length is negative. */
93 /*- STC__INVTIME : time limit is unacceptable negativ */
94 /* or to long. */
95 /*- STC__TIMEOUT : timeout read from socket. */
96 /*+ File name : */
97 /*+ Version : 1.01 */
98 /*+ Author : R.Fritzsche */
99 /*+ Last Update : 17-Jul-1995 */
100 /* */
101 /*2+UPDATES*******+***********+*********************************************/
102 /* */
103 /*+ Updates : Date Purpose */
104 /*- 17-Jul-1995 : f_stc_connectserver H.G. */
105 /* close socket in case of failure to avoid */
106 /* hanging sockets */
107 /*- 17-Jul-1995 : f_stc_discclient H.G. */
108 /* remove shutdown (which didn't work and */
109 /* inibited close) and make close in any case */
110 /*- 17-Jul-1995 : f_stc_disperror H.G. */
111 /* new message no.: STC__ECONNREF */
112 /* */
113 /*2+INTERNALS*****+***********+*********************************************/
114 /* */
115 /*+ Utility : EXAMPLES */
116 /*+ Compile lib.: GOOINC.TLB */
117 /*+ Home direct.: GOO$EXAMPLES */
118 /*+ Created : 25-Jan-1994 */
119 /* */
120 /*1- PLI Main ****************+****************************************/
121 /* %%-HEAD: */
122 
123 INTS4 f_stc_read(p_buffer, i_buflen, i_channel, i_timeout) INTS1* p_buffer;
124 INTS4 i_buflen;
125 INTS4 i_channel;
126 INTS4 i_timeout;
127 {
128  INTS4 retval, buflen_tmp;
129  INTS1* p_buffer_tmp;
130  // INTS4 rmask , wmask , emask;
131  INTS4 i_retry = 0;
132  struct timeval read_timeout;
133  fd_set xrmask, xwmask, xemask;
134  INTS4 num_of_bytes_read = 0;
135 
136  buflen_tmp = i_buflen;
137  p_buffer_tmp = p_buffer; /* actual pointer to buffer */
138 
139  FD_ZERO(&xrmask);
140  FD_ZERO(&xemask);
141  FD_ZERO(&xwmask);
142  FD_SET(i_channel, &xrmask);
143  read_timeout.tv_sec = i_timeout;
144  read_timeout.tv_usec = 0;
145 #ifdef DEBUG
146  printf("STC: read %6d bytes channel %d ", i_buflen, i_channel);
147  fflush(stdout);
148 #endif
149  while (num_of_bytes_read < i_buflen && buflen_tmp > 0) {
150  if (i_timeout >= 0) {
151  /*
152  #ifdef GSI__AIX
153  retval = select(32,&xrmask,&xwmask,&xemask,&read_timeout);
154  #else
155  retval = select(32,&rmask,&wmask,&emask,&read_timeout);
156  #endif
157  */
158 
159  /* Changed by S.Linev, 18.09.2007 */
160  // retval = select(32,(fd_set*) &rmask, (fd_set*) &wmask, (fd_set*) &emask,&read_timeout);
161  retval = select(i_channel + 1, &xrmask, &xwmask, &xemask, &read_timeout);
162 
163  switch (retval) {
164  case -1:
165  switch (errno) {
166  case EBADF:
167  return STC__INVSOCK;
168  case EINVAL:
169  return STC__INVTIME;
170  case EINTR:
171  continue;
172  case ECONNRESET:
173  return STC__ECONNRES;
174  default:
175  sprintf(c_msg, "STC select error channel %d", i_channel);
176  perror(c_msg);
177  return STC__FAILURE;
178  }
179  case 0:
180  return STC__TIMEOUT;
181  }
182  }
183  /* ------------------------------------------------------- */
184  /* read data from the connect socket. */
185  /* ------------------------------------------------------- */
186 #ifdef DEBUG
187  printf("read ");
188  fflush(stdout);
189 #endif
190 #ifdef GSI__WINNT
191  retval = recv(i_channel, p_buffer_tmp, buflen_tmp, 0); /* Mohammad Al-Turany 31.07.00 */
192 #else
193  retval = read(i_channel, p_buffer_tmp, buflen_tmp);
194 #endif
195  if (retval == -1) {
196  switch (errno) {
197  case EBADF:
198  return STC__INVSOCK;
199  case EFAULT:
200  return STC__INVBUF;
201  case EINVAL:
202  return STC__NGBUFSIZE;
203  case EINTR:
204  return STC__EINTR;
205  case ECONNRESET:
206  return STC__ECONNRES;
207  default:
208  sprintf(c_msg, "STC read error channel %d", i_channel);
209  perror(c_msg);
210  return STC__FAILURE;
211  } /* switch( errno ) */
212 
213  } /* if( retval == -1 ) */
214 
215  /* ------------------------------------------------------- */
216  /* set the num of bytes to read in the next */
217  /* read statement. */
218  /* ------------------------------------------------------- */
219 
220  num_of_bytes_read += retval;
221  buflen_tmp -= retval;
222  p_buffer_tmp += retval; /* calc actual pointer */
223  if (i_retry == 100000) {
224  printf("Request %d bytes, read %d, timeout after 100000 retries\n", i_buflen, num_of_bytes_read);
225  return STC__NODATA;
226  }
227  ++i_retry;
228 
229  read_timeout.tv_sec = 100;
230  read_timeout.tv_usec = 0;
231 
232  } /* end while */
233 
234 #ifdef DEBUG
235  printf("done\n");
236  fflush(stdout);
237 #endif
238  if (num_of_bytes_read == i_buflen) {
239  return STC__SUCCESS;
240  }
241 
242  return STC__FAILURE;
243 } /* f_stc_read() */
244 
245 /* ------------------------------------------------------------------------- */
246 
247 /* %%+HEAD: */
248 /*****************+***********+****************************************/
249 /* */
250 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
251 /* Postfach 11 05 41 */
252 /* D-6100 Darmstadt 11 */
253 /* */
254 /*1+ PLI Main ****************+****************************************/
255 /* */
256 /*+ Module : f_stc_write */
257 /* */
258 /*--------------------------------------------------------------------*/
259 /*+ CALLING : f_stc_write( INTS1 p_buffer , INTS4 i_buflen , */
260 /* INTS4 i_channel ) */
261 /*--------------------------------------------------------------------*/
262 /* */
263 /*+ PURPOSE : f_stc_write. write a buffer to a connected */
264 /* socket. */
265 /* */
266 /*+ ARGUMENTS : */
267 /* */
268 /*+ p_buffer : Pointer to buffer. */
269 /* */
270 /*+ i_buflen : length of buffer. */
271 /* */
272 /*+ i_channel : Id from the connected socket. */
273 /* */
274 /*+ Return type : integer. */
275 /* */
276 /*2+DESCRIPTION***+***********+****************************************/
277 /* */
278 /*+ CALLING : f_stc_write( INTS1 p_buffer , INTS4 i_buflen , */
279 /* INTS4 i_channel ) */
280 /* */
281 /*+ ARGUMENTS : */
282 /* */
283 /*+ p_buffer : Pointer to buffer. */
284 /* */
285 /*+ i_buflen : length of buffer. */
286 /* */
287 /*+ i_channel : Id from the connected socket. */
288 /* */
289 /*+ FUNCTION : Write a specified buffer to a connected socket */
290 /* */
291 /*+ REMARKS : - */
292 /* */
293 /*2+IMPLEMENTATION************+****************************************/
294 /* */
295 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
296 /*+ Return type : INTEGER */
297 /*+ Status codes: */
298 /*- STC__SUCCESS : success. */
299 /*- STC__FAILURE : failure. */
300 /*- STC__INVSOCK : invalid socket number. */
301 /*- STC__NOTSOCK : socket number points to a file */
302 /* not a socket. */
303 /*- STC__INVADDR : invalid address specified in */
304 /* parameter. */
305 /*+ File name : */
306 /*+ Version : 1.01 */
307 /*+ Author : R.Fritzsche */
308 /*+ Last Update : 27-Jan-1994 */
309 /* */
310 /*2+UPDATES*******+***********+****************************************/
311 /* */
312 /*+ Updates : Date Purpose */
313 /* */
314 /*2+INTERNALS*****+***********+****************************************/
315 /* */
316 /*+ Utility : EXAMPLES */
317 /*+ Compile lib.: GOOINC.TLB */
318 /*+ Home direct.: GOO$EXAMPLES */
319 /*+ Created : 25-Jan-1994 */
320 /* */
321 /*1- PLI Main ****************+****************************************/
322 /* %%-HEAD: */
323 
324 INTS4 f_stc_write(p_buffer, i_buflen, i_channel) INTS1* p_buffer;
325 INTS4 i_buflen;
326 INTS4 i_channel;
327 {
328  INTS4 l_retval;
329 
330  /* ---------------------------------------------------------- */
331  /* send data to server. */
332  /* ---------------------------------------------------------- */
333 
334 #ifdef DEBUG
335  printf("STC: write %5d bytes channel %d ", i_buflen, i_channel);
336  fflush(stdout);
337 #endif
338  l_retval = send(i_channel, p_buffer, i_buflen, 0);
339 
340  switch (l_retval) {
341  case -1:
342  switch (errno) {
343  case EBADF:
344  return STC__INVSOCK;
345  case ENOTSOCK:
346  return STC__NOTSOCK;
347  case EFAULT:
348  return STC__INVADDR;
349  default:
350  sprintf(c_msg, "STC write error channel %d", i_channel);
351  perror(c_msg);
352  return STC__FAILURE;
353  } /* switch( errno ) */
354 
355  } /* switch( l_retval ) */
356 
357  /* ---------------------------------------------------------- */
358  /* send() returns the number of bytes sent. */
359  /* ---------------------------------------------------------- */
360 
361 #ifdef DEBUG
362  printf("done\n");
363  fflush(stdout);
364 #endif
365  if (l_retval == i_buflen) {
366  return STC__SUCCESS;
367  }
368 
369  return STC__FAILURE;
370 } /* end f_stc_write() */
371 
372 /* %%+HEAD: */
373 /*****************+***********+****************************************/
374 /* */
375 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
376 /* Postfach 11 05 41 */
377 /* D-6100 Darmstadt 11 */
378 /* */
379 /*1+ PLI Main ****************+****************************************/
380 /* */
381 /*+ Module : f_stc_connectserver */
382 /* */
383 /*--------------------------------------------------------------------*/
384 /*+ CALLING : f_stc_connectserver( CHARS c_node , INTS4 l_port , */
385 /* INTS4 pi_channel , */
386 /* struct s_tcpcomm ps_client ) */
387 /* */
388 /*--------------------------------------------------------------------*/
389 /* */
390 /*+ PURPOSE : f_stc_connectserver. connect a client process to a */
391 /* server process. */
392 /* */
393 /*+ ARGUMENTS : */
394 /* */
395 /*+ c_node : Name of server node */
396 /* */
397 /*+ l_port : Portnumber from server */
398 /* */
399 /*+ pi_channel : Pointer to channel number. */
400 /* i_channel specifies the address that will be filled */
401 /* in with the actual socket Id. */
402 /* */
403 /*+ pc_client : Pointer to structure s_tcpcomm. */
404 /* s_client specifies the address that will be filled */
405 /* in with the actual communication values. */
406 /* */
407 /* */
408 /*+ Return type : integer. */
409 /* */
410 /*2+DESCRIPTION***+***********+****************************************/
411 /* */
412 /*+ CALLING : f_stc_connectserver( CHARS c_node , INTS4 l_port , */
413 /* INTS4 pi_channel , */
414 /* struct s_tcpcomm ps_client ) */
415 /*+ ARGUMENTS : */
416 /* */
417 /*+ c_node : Name of server node */
418 /* */
419 /*+ l_port : Portnumber from server */
420 /* */
421 /*+ pi_channel : Pointer to channel number. */
422 /* i_channel specifies the address that will be filled */
423 /* in with the actual socket Id. */
424 /* */
425 /*+ ps_client : Pointer to structure s_tcpcomm. */
426 /* s_client specifies the address that will be filled */
427 /* in with the actual communication values. */
428 /* */
429 /*+ FUNCTION : f_stc_connectserver. connect a client process to a */
430 /* server process on node "c_node"*/
431 /* and port "l_port". */
432 /* f_stc_connectserver() modify */
433 /* the channel number and fill the*/
434 /* structure s_tcpcomm. */
435 /* The channel number is required */
436 /* to read and write data, to the */
437 /* connected server. */
438 /*+ REMARKS : - */
439 /* */
440 /*2+IMPLEMENTATION************+****************************************/
441 /* */
442 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
443 /*+ Return type : INTEGER */
444 /*+ Status codes: */
445 /*- STC__SUCCESS : success. */
446 /*- STC__FAILURE : failure. */
447 /*- STC__INVADDRF: The specified address family is not */
448 /* supported. */
449 /*- STC__SOCKNSUP: The specified socket type is not */
450 /* supported. */
451 /*- STC__INVPROTO: The specified protocol is not */
452 /* supported. */
453 /*- STC__SOCKTABF: The per-process descriptor table */
454 /* is full. */
455 /*- STC__SOCKSPAF: No buffer space is available. The */
456 /* socket can't be created. */
457 /*- STC__INVSOCK : invalid socket number. */
458 /*- STC__NOTSOCK : socket number points to a file not a */
459 /* socket. */
460 /*- STC__SOCKISC : socket is already connected. */
461 /*- STC__CONNTOUT: connection timed out without */
462 /* establishing a connection. */
463 /*- STC__NETUNREA: The network is not reachable from */
464 /* this host. */
465 /*- STC__PORTINUS: The specified Internet Address and */
466 /* port is already in use. */
467 /*+ File name : */
468 /*+ Version : 1.01 */
469 /*+ Author : R.Fritzsche */
470 /*+ Last Update : 24-Jan-1994 */
471 /* */
472 /*2+UPDATES*******+***********+****************************************/
473 /* */
474 /*+ Updates : Date Purpose */
475 /* */
476 /*2+INTERNALS*****+***********+****************************************/
477 /* */
478 /*+ Utility : EXAMPLES */
479 /*+ Compile lib.: GOOINC.TLB */
480 /*+ Home direct.: GOO$EXAMPLES */
481 /*+ Created : 24-Jan-1994 */
482 /* */
483 /*1- PLI Main ****************+****************************************/
484 /* %%-HEAD: */
485 
486 INTS4 f_stc_connectserver(c_node, l_port, pi_channel, ps_client) CHARS* c_node;
487 INTS4 l_port;
488 INTS4* pi_channel;
489 struct s_tcpcomm* ps_client;
490 {
491 
492  INTS4 /*shut,*/ retval;
493  // INTS4 thirty = 30;
494  struct s_tcpcomm s_client;
495  memset(&s_client, 0, sizeof(s_client));
496 
497  /* ----------------------------------------------------------------------- */
498  /* init communication socket. */
499  /* ----------------------------------------------------------------------- */
500 
501 #ifdef GSI__WINNT
502  WORD wVersionRequested;
503  WSADATA wsaData;
504  char message1[512];
505  wVersionRequested = MAKEWORD(2, 2);
506  // err = WSAStartup( wVersionRequested, &wsaData );
507  if (WSAStartup(wVersionRequested, &wsaData) != 0) {
508  printf("WinSock NOT found");
509  /* Tell the user that we could not find a usable */
510  /* WinSock DLL. */
511  }
512 
513  if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
514  /* Tell the user that we could not find a usable */
515  /* WinSock DLL.
516  */
517  printf("WinSock %d.%d", LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion));
518  WSACleanup();
519  }
520 
521 #endif
522 
523  s_client.socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
524 
525  *ps_client = s_client;
526  *pi_channel = s_client.socket; /* save channel also in case of error */
527  /* 17.7.95, H.G. */
528  switch (s_client.socket) {
529  case -1:
530  switch (errno) {
531  case EAFNOSUPPORT:
532  return STC__INVADDRF;
533  case ESOCKTNOSUPPORT:
534  return STC__SOCKNSUP;
535  case EPROTONOSUPPORT:
536  return STC__INVPROTO;
537  case EMFILE:
538  return STC__SOCKTABF;
539  case ENOBUFS:
540  return STC__SOCKSPAF;
541  default:
542  return STC__FAILURE;
543  } /* switch( errno ) */
544  } /* switch( s_client.socket) */
545 
546  if ((s_client.hostentptr = gethostbyname(c_node)) == NULL) {
547 
548 #ifdef GSI__WINNT
549  closesocket(s_client.socket); /* Mohammad Al-Turany 31.07.00*/
550 #else
551  close(s_client.socket); /* close socket here and in any case! */
552  /* H.G., 17.7.95 */
553 #endif
554  /* printf("--E--f_stc_connectserver(): error gethostbyname: >%s<\n",c_node);*/
555  return STC__FAILURE;
556  }
557 
558  s_client.hostentstruct = *s_client.hostentptr;
559  s_client.sock.sin_family = s_client.hostentstruct.h_addrtype;
560  s_client.sock.sin_port = htons(l_port);
561  s_client.sock.sin_addr = *((struct in_addr*)s_client.hostentstruct.h_addr);
562 
563  retval = connect(s_client.socket, (struct sockaddr*)&s_client.sock, sizeof(s_client.sock));
564  if (retval == -1) {
565 #ifdef GSI__WINNT
566  closesocket(s_client.socket); /* Mohammad Al-Turany 31.07.00*/
567 #else
568  close(s_client.socket); /* close socket here and in any case! */
569  /* H.G., 17.7.95 */
570 #endif
571  switch (errno) {
572  case EBADF:
573  return STC__INVSOCK;
574  case ENOTSOCK:
575  return STC__NOTSOCK;
576  case EISCONN:
577  return STC__SOCKISC;
578  case ETIMEDOUT:
579  return STC__CONNTOUT;
580  case ENETUNREACH:
581  return STC__NETUNREA;
582  case EADDRINUSE:
583  return STC__PORTINUS;
584  case ECONNREFUSED:
585  return STC__ECONNREF;
586  default:
587  return STC__FAILURE;
588  } /* switch( errno ) */
589  }
590 
591  *ps_client = s_client;
592 
593  return STC__SUCCESS;
594 
595 } /* f_stc_connectserver() */
596 
597 /* %%+HEAD: */
598 /*****************+***********+****************************************/
599 /* */
600 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
601 /* Postfach 11 05 41 */
602 /* D-6100 Darmstadt 11 */
603 /* */
604 /*1+ PLI Main ****************+****************************************/
605 /* */
606 /*+ Module : f_stc_acceptclient */
607 /* */
608 /*--------------------------------------------------------------------*/
609 /*+ CALLING : f_stc_acceptclient( struct s_tcpcomm s_server , */
610 /* INTS4 pi_channel ) */
611 /*--------------------------------------------------------------------*/
612 /* */
613 /*+ PURPOSE : f_stc_acceptclient. completes a connection between */
614 /* server and client. */
615 /* f_stc_acceptclient() modify the */
616 /* channel Id from the accepted */
617 /* client. The channel Id is */
618 /* required to read and write data */
619 /* to the client. */
620 /* */
621 /*+ ARGUMENTS : */
622 /* */
623 /*+ s_server : Pointer to structure s_tcpcomm. */
624 /* */
625 /*+ pi_channel : Id from the connected client. */
626 /* i_channel specifies the address that will be filled */
627 /* in with the actual client socket Id. */
628 /* */
629 /*+ Return type : integer. */
630 /* */
631 /*2+DESCRIPTION***+***********+****************************************/
632 /* */
633 /*+ CALLING : f_stc_acceptclient( struct s_tcpcomm s_server , */
634 /* INTS4 pi_channel ) */
635 /* */
636 /*+ PURPOSE : f_stc_acceptclient. completes a connection between */
637 /* server and client. */
638 /* f_stc_acceptclient() modify the */
639 /* channel Id from the accepted */
640 /* client. The channel Id is */
641 /* required to read and write data */
642 /* to the client. */
643 /* */
644 /*+ ARGUMENTS : */
645 /* */
646 /*+ s_server : Pointer to structure s_tcpcomm. */
647 /* */
648 /*+ pi_channel : Id from the connected client. */
649 /* i_channel specifies the address that will be filled */
650 /* in with the actual client socket id. */
651 /* */
652 /*+ Return type : integer. */
653 /* */
654 /*+ REMARKS : - */
655 /* */
656 /*2+IMPLEMENTATION************+****************************************/
657 /* */
658 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
659 /*+ Return type : INTEGER */
660 /*+ Status codes: Status of last command */
661 /*- STC__SUCCESS : success. */
662 /*- STC__FAILURE : failure. */
663 /*- STC__INVSOCK : invalid socket number. */
664 /*- STC__NOTSOCK : socket number points to a file not */
665 /* a socket. */
666 /*+ File name : GOO$EXAMPLES: */
667 /*+ Version : 1.01 */
668 /*+ Author : R.Fritzsche */
669 /*+ Last Update : 25-Jan-1994 */
670 /* */
671 /*2+UPDATES*******+***********+****************************************/
672 /* */
673 /*+ Updates : Date Purpose */
674 /* */
675 /*2+INTERNALS*****+***********+****************************************/
676 /* */
677 /*+ Utility : EXAMPLES */
678 /*+ Compile lib.: GOOINC.TLB */
679 /*+ Home direct.: GOO$EXAMPLES */
680 /*+ Created : 15-Jan-1994 */
681 /* */
682 /*1- PLI Main ****************+****************************************/
683 /* %%-HEAD: */
684 
685 INTS4 f_stc_acceptclient(ps_server, pi_channel) struct s_tcpcomm* ps_server;
686 INTS4* pi_channel;
687 {
688  // INTS4 i_socket;
689  // struct hostent* he;
690 
691 #ifdef GSI__AIX
692  *pi_channel =
693  accept(ps_server->sock_rw, (struct sockaddr*)&ps_server->sock_name, (socklen_t*)&ps_server->namelength);
694 #else
695  *pi_channel = accept(ps_server->sock_rw, (struct sockaddr*)&ps_server->sock_name, (uint*)&ps_server->namelength);
696 #endif
697  if (*pi_channel == -1) {
698  switch (errno) {
699  case EBADF:
700  return STC__INVSOCK;
701  case ENOTSOCK:
702  return STC__NOTSOCK;
703  default:
704  return STC__FAILURE;
705  } /* switch( errno ) */
706  }
707 
708  /*
709  hostname of remote node.
710  he = gethostbyaddr( ps_server->sock_name.sin_addr.s_addr,
711  sizeof(ps_server->sock_name.sin_addr.s_addr),
712  AF_INET );
713 
714  if( he != NULL )
715  printf("name of client: %s\n",he->h_name);
716  */
717 
718  return STC__SUCCESS;
719 
720 } /* end f_stc_acceptclient() */
721 
722 /* %%+HEAD: */
723 /*****************+***********+****************************************/
724 /* */
725 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
726 /* Postfach 11 05 41 */
727 /* D-6100 Darmstadt 11 */
728 /* */
729 /*1+ PLI Main ****************+****************************************/
730 /* */
731 /*+ Module : f_stc_createserver */
732 /* */
733 /*--------------------------------------------------------------------*/
734 /*+ CALLING : f_stc_createserver( INTS4 pl_port , */
735 /* struct s_tcpcomm ps_server ) */
736 /*--------------------------------------------------------------------*/
737 /* */
738 /*+ PURPOSE : f_stc_createserver creates an endpoint for */
739 /* client-server communications. */
740 /* The endpoint of communication */
741 /* data is not the process name. */
742 /* The client-server communication */
743 /* use portnumbers as endpoints of */
744 /* communications. */
745 /* The port numbers in the range */
746 /* 1 to 1023 are privileged ports. */
747 /* User can use ports in the range */
748 /* 1024 to 65535. */
749 /* also you can use portnumber 0, */
750 /* then f_stc_createserver() search*/
751 /* for a free portnumber and modify*/
752 /* the value from l_port, */
753 /* else f_stc_createserver() */
754 /* returns 0 */
755 /* */
756 /*+ ARGUMENTS : */
757 /* */
758 /*+ l_port : Pointer to Portnumber. ( 1024 - 65535 ) or ( 0 ). */
759 /* */
760 /*+ s_server : Pointer to structure s_tcpcomm */
761 /* s_server specifies the address that will be filled */
762 /* in with the actual communication values. */
763 /* */
764 /*+ Return type : integer. */
765 /* */
766 /*2+DESCRIPTION***+***********+****************************************/
767 /* */
768 /*+ CALLING : f_stc_createserver( INTS4 l_port , */
769 /* struct s_tcpcomm s_server) */
770 /* */
771 /*+ ARGUMENTS : */
772 /* */
773 /*+ l_port : Pointer to Portnumber. ( 1024 - 65535 ) or ( 0 ). */
774 /* l_port specifies the address that will be filled */
775 /* in with the actual server portnumber. */
776 /* */
777 /*+ S_SERVER : Pointer to structure s_tcpcomm */
778 /* s_server specifies the address that will be filled */
779 /* in with the actual communication values. */
780 /* */
781 /*+ FUNCTION : f_stc_createserver creates an endpoint for */
782 /* client - server communications. */
783 /* The endpoint of communication for */
784 /* data is not the a process name. */
785 /* The client - server communication */
786 /* use portnumbers as endpoints of */
787 /* communications. */
788 /* The port numbers in the range */
789 /* 1 to 1023 are privileged ports. */
790 /* User can use ports in the range */
791 /* 1024 to 65535. */
792 /* also you can use portnumber 0, */
793 /* then f_stc_createserver() search */
794 /* for a free portnumber and write */
795 /* the free portnumber to l_port, */
796 /* else f_stc_createserver() */
797 /* returns 0 */
798 /* */
799 /*+ REMARKS : - */
800 /* */
801 /*2+IMPLEMENTATION************+****************************************/
802 /* */
803 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
804 /*+ Return type : INTEGER */
805 /*+ Status codes: */
806 /*- STC__SUCCESS : success. */
807 /*- STC__FAILURE : failure. */
808 /*- STC__INVADDRF : The specified address family is not */
809 /* supported. */
810 /*- STC__SOCKNSUP : The specified socket type is not */
811 /* supported. */
812 /*- STC__INVPROTO : The specified protocol is not */
813 /* supported. */
814 /*- STC__SOCKTABF : The per-process descriptor table */
815 /* is full. */
816 /*- STC__SOCKSPAF : No buffer space is available. */
817 /* The socket can't be created. */
818 /*- STC__INVSOCK : invalid socket number. */
819 /*- STC__NOTSOCK : socket number points to a file not */
820 /* a socket. */
821 /*- STC__PORTINUS : The specified Internet Address */
822 /* and port is already in use. */
823 /*- STC__SOCKISC : socket is already connected. */
824 /*- STC__SOCKISP : socket address is protected and the */
825 /* current user has inadequate */
826 /* permission to access it. */
827 /*+ File name : */
828 /*+ Version : 1.01 */
829 /*+ Author : R.Fritzsche */
830 /*+ Last Update : 25-Jan-1994 */
831 /* */
832 /*2+UPDATES*******+***********+****************************************/
833 /* */
834 /*+ Updates : Date Purpose */
835 /* */
836 /*2+INTERNALS*****+***********+****************************************/
837 /* */
838 /*+ Utility : EXAMPLES */
839 /*+ Compile lib.: GOOINC.TLB */
840 /*+ Home direct.: GOO$EXAMPLES */
841 /*+ Created : 25-Jan-1994 */
842 /* */
843 /*1- PLI Main ****************+****************************************/
844 /* %%-HEAD: */
845 
846 INTS4 f_stc_createserver(pl_port, ps_server) INTS4* pl_port;
847 struct s_tcpcomm* ps_server;
848 
849 {
850 
851  INTS4 retval, /*i,*/ retry, on;
852  // struct protoent* p;
853  struct s_tcpcomm s_server;
854  memset(&s_server, 0, sizeof(s_server));
855 
856 #ifdef GSI__WINNT
857  WORD wVersionRequested;
858  WSADATA wsaData;
859  char message1[512];
860  wVersionRequested = MAKEWORD(2, 2);
861  // err = WSAStartup( wVersionRequested, &wsaData );
862  if (WSAStartup(wVersionRequested, &wsaData) != 0) {
863  printf("WinSock NOT found");
864  /* Tell the user that we could not find a usable */
865  /* WinSock DLL. */
866  }
867 
868  if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
869  /* Tell the user that we could not find a usable */
870  /* WinSock DLL.
871  */
872  printf("WinSock %d.%d", LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion));
873  WSACleanup();
874  }
875 
876 #endif
877 
878  on = 1;
879 
880  if (*pl_port == 0) {
881  retry = 1;
882  *pl_port = 1024;
883  } else {
884  retry = 0;
885  }
886 
887  s_server.sock_rw = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
888 
889  switch (s_server.sock_rw) {
890  case -1:
891  switch (errno) {
892  case EAFNOSUPPORT:
893  return STC__INVADDRF;
894  case ESOCKTNOSUPPORT:
895  return STC__SOCKNSUP;
896  case EPROTONOSUPPORT:
897  return STC__INVPROTO;
898  case EMFILE:
899  return STC__SOCKTABF;
900  case ENOBUFS:
901  return STC__SOCKSPAF;
902  default:
903  return STC__FAILURE;
904  } /* switch( errno ) */
905  } /* switch( s_server.sock_rw) */
906 
907  retval = gethostname(s_server.hostname, sizeof(s_server.hostname));
908  if (retval) {
909  printf("--E--f_stc_createserver() error get local hostname\n");
910  return STC__FAILURE;
911  }
912 
913  if ((s_server.hostentptr = gethostbyname(s_server.hostname)) == NULL) {
914  printf("--E--f_stc_createserver() error get local Internet address\n");
915  return STC__FAILURE;
916  }
917 
918  bzero((CHARS*)&s_server.sock_name, sizeof(s_server.sock_name));
919  s_server.sock_name.sin_family = AF_INET;
920  s_server.sock_name.sin_addr.s_addr = htonl(INADDR_ANY);
921  s_server.sock_name.sin_port = htons(*pl_port);
922 
923  retval = bind(s_server.sock_rw, (struct sockaddr*)&s_server.sock_name, sizeof(s_server.sock_name));
924 
925  if (retval == -1 && retry == 0) {
926 
927  close(s_server.sock_rw);
928 
929  switch (errno) {
930  case EBADF:
931  return STC__INVSOCK;
932  case ENOTSOCK:
933  return STC__NOTSOCK;
934  case EADDRINUSE:
935  return STC__PORTINUS;
936  case EINVAL:
937  return STC__SOCKISC;
938  case EACCES:
939  return STC__SOCKISP;
940  default:
941  return STC__FAILURE;
942  }
943  }
944 
945  retval = -1;
946 
947  while (retval == -1 && retry == 1) {
948 
949  s_server.sock_rw = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
950 
951  switch (s_server.sock_rw) {
952  case -1:
953  switch (errno) {
954  case EAFNOSUPPORT:
955  return STC__INVADDRF;
956  case ESOCKTNOSUPPORT:
957  return STC__SOCKNSUP;
958  case EPROTONOSUPPORT:
959  return STC__INVPROTO;
960  case EMFILE:
961  return STC__SOCKTABF;
962  case ENOBUFS:
963  return STC__SOCKSPAF;
964  default:
965  return STC__FAILURE;
966  }
967  }
968 
969  retval = gethostname(s_server.hostname, sizeof(s_server.hostname));
970  if (retval) {
971  printf("--E--f_stc_createserver() error get local hostname\n");
972  return STC__FAILURE;
973  }
974 
975  if ((s_server.hostentptr = gethostbyname(s_server.hostname)) == NULL) {
976  printf("--E--f_stc_createserver() error get local Internet address\n");
977  return STC__FAILURE;
978  }
979 
980  retval = -1;
981 
982  bzero((CHARS*)&s_server.sock_name, sizeof(s_server.sock_name));
983  s_server.sock_name.sin_family = AF_INET;
984  s_server.sock_name.sin_addr.s_addr = htonl(INADDR_ANY);
985  s_server.sock_name.sin_port = htons(*pl_port);
986 
987  retval = bind(s_server.sock_rw, (struct sockaddr*)&s_server.sock_name, sizeof(s_server.sock_name));
988  if (retval == -1) {
989  close(s_server.sock_rw);
990 
991  *pl_port += 1;
992 
993  if (*pl_port > 65535) {
994  printf("--E--f_stc_createserver() portnumber exceeded > 655535\n");
995 
996  switch (errno) {
997  case EBADF:
998  return STC__INVSOCK;
999  case ENOTSOCK:
1000  return STC__NOTSOCK;
1001  case EADDRINUSE:
1002  return STC__PORTINUS;
1003  case EINVAL:
1004  return STC__SOCKISC;
1005  case EACCES:
1006  return STC__SOCKISP;
1007  default:
1008  return STC__FAILURE;
1009  } /* end switch( errno ) */
1010 
1011  } /* end if *pl_port > ... ) */
1012 
1013  } /* end if (retval == -1 ) */
1014  }
1015 
1016  retval = listen(s_server.sock_rw, 5);
1017  if (retval == -1) {
1018  switch (errno) {
1019  case EBADF:
1020  return STC__INVSOCK;
1021  case ENOTSOCK:
1022  return STC__NOTSOCK;
1023  default:
1024  return STC__FAILURE;
1025  }
1026  }
1027 
1028  s_server.namelength = sizeof(s_server.sock_name);
1029 
1030  *ps_server = s_server;
1031 
1032  return STC__SUCCESS;
1033 } /* end f_stc_createserver() */
1034 
1035 /* %%+HEAD: */
1036 /*****************+***********+****************************************/
1037 /* */
1038 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
1039 /* Postfach 11 05 41 */
1040 /* D-6100 Darmstadt 11 */
1041 /* */
1042 /*1+ PLI Main ****************+****************************************/
1043 /* */
1044 /*+ Module : f_stc_close */
1045 /* */
1046 /*--------------------------------------------------------------------*/
1047 /*+ CALLING : f_stc_close( struct s_tcpcomm ps_tcp ) */
1048 /*--------------------------------------------------------------------*/
1049 /* */
1050 /*+ PURPOSE : f_stc_close close the client server */
1051 /* communication. */
1052 /* */
1053 /*+ ARGUMENTS : */
1054 /* */
1055 /*+ S_TCP : Pointer to structure s_tcpcomm. */
1056 /* */
1057 /*+ Return type : integer. */
1058 /* */
1059 /*2+DESCRIPTION***+***********+****************************************/
1060 /* */
1061 /*+ CALLING : f_stc_close( struct s_tcpcomm ps_tcp ) */
1062 /* */
1063 /*+ ARGUMENTS : */
1064 /* */
1065 /*+ FUNCTION : f_stc_close close the client server */
1066 /* communication. */
1067 /* */
1068 /*+ S_TCP : Pointer to structure s_tcpcomm. */
1069 /* */
1070 /*+ REMARKS : - */
1071 /* */
1072 /*2+IMPLEMENTATION************+****************************************/
1073 /* */
1074 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
1075 /*+ Return type : INTEGER */
1076 /*+ File name : */
1077 /*+ Version : 1.01 */
1078 /*+ Author : R.Fritzsche */
1079 /*+ Last Update : 25-Jan-1994 */
1080 /* */
1081 /*2+UPDATES*******+***********+****************************************/
1082 /* */
1083 /*+ Updates : Date Purpose */
1084 /* */
1085 /*2+INTERNALS*****+***********+****************************************/
1086 /* */
1087 /*+ Utility : EXAMPLES */
1088 /*+ Compile lib.: GOOCINC.TLB */
1089 /*+ Home direct.: GOO$EXAMPLES */
1090 /*+ Created : 25-Jan-1994 */
1091 /* */
1092 /*1- PLI Main ****************+****************************************/
1093 /* %%-HEAD: */
1094 
1095 INTS4 f_stc_close(ps_tcp) struct s_tcpcomm* ps_tcp;
1096 {
1097  INTS4 retval;
1098 
1099  if (ps_tcp->socket) {
1100  retval = shutdown(ps_tcp->socket, 2);
1101  if (retval == -1) {
1102  return STC__FAILURE;
1103  }
1104  retval = close(ps_tcp->socket);
1105  if (retval == -1) {
1106  return STC__FAILURE;
1107  }
1108 
1109  return STC__SUCCESS;
1110  }
1111 
1112  return STC__FAILURE;
1113 } /* f_stc_close() */
1114 
1115 /* %%+HEAD: */
1116 /*****************+***********+****************************************/
1117 /* */
1118 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
1119 /* Postfach 11 05 41 */
1120 /* D-6100 Darmstadt 11 */
1121 /* */
1122 /*1+ PLI Main ****************+****************************************/
1123 /* */
1124 /*+ Module : f_stc_discclient */
1125 /* */
1126 /*--------------------------------------------------------------------*/
1127 /*+ CALLING : f_stc_discclient( INTS4 i_channel ) */
1128 /*--------------------------------------------------------------------*/
1129 /* */
1130 /*+ PURPOSE : f_stc_discclient close the specified client */
1131 /* server communication. */
1132 /* */
1133 /*+ ARGUMENTS : */
1134 /* */
1135 /*+ I_CHANNEL : Channel Id from the specified client. */
1136 /* */
1137 /*+ Return type : integer. */
1138 /* */
1139 /*2+DESCRIPTION***+***********+****************************************/
1140 /* */
1141 /*+ CALLING : f_stc_discclient( INTS4 i_channel ) */
1142 /* */
1143 /*+ ARGUMENTS : */
1144 /* */
1145 /*+ FUNCTION : f_stc_discclient close the specified client */
1146 /* server communication. */
1147 /* */
1148 /*+ I_CHANNEL : Channel Id from the specified client. */
1149 /* */
1150 /*+ REMARKS : - */
1151 /* */
1152 /*2+IMPLEMENTATION************+****************************************/
1153 /* */
1154 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
1155 /*+ Return type : INTEGER */
1156 /*+ File name : */
1157 /*+ Version : 1.01 */
1158 /*+ Author : R.Fritzsche */
1159 /*+ Last Update : 01-Mar-1994 */
1160 /* */
1161 /*2+UPDATES*******+***********+****************************************/
1162 /* */
1163 /*+ Updates : Date Purpose */
1164 /* */
1165 /*2+INTERNALS*****+***********+****************************************/
1166 /* */
1167 /*+ Utility : EXAMPLES */
1168 /*+ Compile lib.: */
1169 /*+ Home direct.: */
1170 /*+ Created : 01-Mar-1994 */
1171 /* */
1172 /*1- PLI Main ****************+****************************************/
1173 /* %%-HEAD: */
1174 
1175 INTS4 f_stc_discclient(i_channel) INTS4 i_channel;
1176 {
1177  INTS4 retval;
1178 
1179  /* call of shutdown removed 17.7.95, H.G. */
1180  retval = close(i_channel);
1181  if (retval == -1) {
1182  return STC__FAILURE;
1183  } else {
1184  return STC__SUCCESS;
1185  }
1186 } /* f_stc_discclient() */
1187 
1188 /* %%+HEAD: */
1189 /*****************+***********+****************************************/
1190 /* */
1191 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
1192 /* Postfach 11 05 41 */
1193 /* D-6100 Darmstadt 11 */
1194 /* */
1195 /*1+ PLI Main ****************+****************************************/
1196 /* */
1197 /*+ Module : f_stc_listenserver */
1198 /* */
1199 /*--------------------------------------------------------------------*/
1200 /*+ CALLING : f_stc_listenserver( struct s_tcpcomm ps_server ) */
1201 /*--------------------------------------------------------------------*/
1202 /* */
1203 /*+ PURPOSE : f_stc_listenserver look for a pending client */
1204 /* connection on the specified */
1205 /* server. */
1206 /* */
1207 /*+ ARGUMENTS : */
1208 /* */
1209 /*+ PS_SERVER : Pointer to structure s_tcpcomm. */
1210 /* */
1211 /*+ Return type : integer. */
1212 /* */
1213 /*2+DESCRIPTION***+***********+****************************************/
1214 /* */
1215 /*+ CALLING : f_stc_listenserver( struct s_tcpcomm ps_server ) */
1216 /* */
1217 /*+ ARGUMENTS : */
1218 /* */
1219 /*+ FUNCTION : f_stc_listenserver look for a pending client */
1220 /* connection on the specified */
1221 /* server. */
1222 /* */
1223 /*+ PS_SERVER : Pointer to structure s_tcpcomm. */
1224 /* */
1225 /*+ REMARKS : - */
1226 /* */
1227 /*2+IMPLEMENTATION************+****************************************/
1228 /* */
1229 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
1230 /*+ Return type : INTEGER */
1231 /*+ Status codes: */
1232 /*- STC__SUCCESS : success. */
1233 /*- STC__FAIlURE : failure. */
1234 /*- STC__INVSOCK : invalid socket number. */
1235 /*- STC__TIMEOUT : timeout. */
1236 /*- STC__INVTIME : time limit is unacceptable */
1237 /* negativ or to long. */
1238 /*+ File name : */
1239 /*+ Version : 1.01 */
1240 /*+ Author : R.Fritzsche */
1241 /*+ Last Update : 25-Jan-1994 */
1242 /* */
1243 /*2+UPDATES*******+***********+****************************************/
1244 /* */
1245 /*+ Updates : Date Purpose */
1246 /* */
1247 /*2+INTERNALS*****+***********+****************************************/
1248 /* */
1249 /*+ Utility : EXAMPLES */
1250 /*+ Compile lib.: GOOCINC.TLB */
1251 /*+ Home direct.: GOO$EXAMPLES */
1252 /*+ Created : 25-Jan-1994 */
1253 /* */
1254 /*1- PLI Main ****************+****************************************/
1255 /* %%-HEAD: */
1256 
1257 INTS4 f_stc_listenserver(ps_server) struct s_tcpcomm* ps_server;
1258 {
1259  struct timeval read_timeout;
1260  fd_set rset, allset, wset, eset;
1261  INTS4 listenfd, maxfd, sts;
1262 
1263  read_timeout.tv_sec = 0;
1264  read_timeout.tv_usec = 0;
1265 
1266  listenfd = ps_server->sock_rw;
1267 
1268  FD_ZERO(&rset);
1269  FD_ZERO(&wset);
1270  FD_ZERO(&eset);
1271  FD_ZERO(&allset);
1272  FD_SET(listenfd, &rset);
1273  FD_SET(listenfd, &wset);
1274  FD_SET(listenfd, &eset);
1275  maxfd = listenfd;
1276 
1277  sts = select(maxfd + 1, &rset, &wset, &eset, &read_timeout);
1278  switch (sts) {
1279  case -1:
1280  switch (errno) {
1281  case EBADF:
1282  return STC__INVSOCK;
1283  case EINVAL:
1284  return STC__INVTIME;
1285  default:
1286  return STC__FAILURE;
1287  } /* switch( errno ) */
1288 
1289  case 0:
1290  return STC__TIMEOUT;
1291 
1292  } /* end switch( sts ) */
1293 
1294  if (FD_ISSET(listenfd, &eset)) {
1295  return STC__SUCCESS;
1296  }
1297 
1298  if (FD_ISSET(listenfd, &rset)) {
1299  return STC__SUCCESS;
1300  }
1301 
1302  if (FD_ISSET(listenfd, &wset)) {
1303  return STC__SUCCESS;
1304  }
1305 
1306  return STC__FAILURE;
1307 }
1308 
1309 /* %%+HEAD: */
1310 /*****************+***********+****************************************/
1311 /* */
1312 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
1313 /* Postfach 11 05 41 */
1314 /* D-6100 Darmstadt 11 */
1315 /* */
1316 /*1+ PLI Main ****************+****************************************/
1317 /* */
1318 /*+ Module : f_stc_disperror */
1319 /* */
1320 /*--------------------------------------------------------------------*/
1321 /*+ CALLING : f_stc_disperror( INTS4 i_error , CHARS c_string[256], */
1322 /* INTS4 i_out ) */
1323 /*--------------------------------------------------------------------*/
1324 /* */
1325 /*+ PURPOSE : f_stc_disperror displays the error message for the */
1326 /* error id ( i_error ) */
1327 /* if i_out = 1 the error message is */
1328 /* copied into c_string, else */
1329 /* f_stc_disperror() print the message */
1330 /* on the terminal. */
1331 /* */
1332 /*+ ARGUMENTS : */
1333 /* */
1334 /*+ I_ERROR : The error id. */
1335 /* */
1336 /*+ C_STRING : The string into f_stc_disperror() copies the */
1337 /* message. */
1338 /* */
1339 /*+ I_OUT : specifies the output device for the error message. */
1340 /* */
1341 /*- I_OUT = 1 : the error message is copied into */
1342 /* the string. */
1343 /*- I_OUT = 0 : the error message is printed on */
1344 /* the terminal. */
1345 /* */
1346 /*+ Return type : integer. */
1347 /* */
1348 /*2+DESCRIPTION***+***********+****************************************/
1349 /* */
1350 /*+ CALLING : f_stc_disperror( INTS4 i_error , CHARS c_string[256], */
1351 /* INTS4 i_out ) */
1352 /* */
1353 /*+ ARGUMENTS : */
1354 /* */
1355 /*+ I_ERROR : The error id. */
1356 /* */
1357 /*+ C_STRING : The string into f_stc_disperror() copies the */
1358 /* message. */
1359 /* */
1360 /*+ I_OUT : specifies the output device for the error message. */
1361 /* */
1362 /*- I_OUT = 1 : the error message is copied into the */
1363 /* string. */
1364 /*- I_OUT = 0 : the error message is printed on the */
1365 /* terminal. */
1366 /* */
1367 /*+ FUNCTION : f_stc_disperror displays the error message for the */
1368 /* error id ( i_error ) */
1369 /* if i_out = 1 the error message is */
1370 /* copied into c_string, else */
1371 /* f_stc_disperror() print the message */
1372 /* on the terminal. */
1373 /* */
1374 /*+ REMARKS : - */
1375 /* */
1376 /*2+IMPLEMENTATION************+****************************************/
1377 /* */
1378 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
1379 /*+ Return type : INTEGER */
1380 /*+ Status codes: */
1381 /*- STC__SUCCESS : success. */
1382 /*- STC__FAIlURE : failure. */
1383 /*+ File name : */
1384 /*+ Version : 1.01 */
1385 /*+ Author : R.Fritzsche */
1386 /*+ Last Update : 28-Jan-1994 */
1387 /* */
1388 /*2+UPDATES*******+***********+****************************************/
1389 /* */
1390 /*+ Updates : Date Purpose */
1391 /* */
1392 /*2+INTERNALS*****+***********+****************************************/
1393 /* */
1394 /*+ Utility : EXAMPLES */
1395 /*+ Compile lib.: GOOCINC.TLB */
1396 /*+ Home direct.: GOO$EXAMPLES */
1397 /*+ Created : 28-Jan-1994 */
1398 /* */
1399 /*1- PLI Main ****************+****************************************/
1400 /* %%-HEAD: */
1401 
1402 INTS4 f_stc_disperror(i_error, c_dest, i_out) INTS4 i_error;
1403 CHARS* c_dest;
1404 INTS4 i_out;
1405 {
1406  CHARS c_line[80];
1407 
1408  switch (i_error) {
1409  case STC__FAILURE:
1410  sprintf(c_line, "-I- f_stc failure");
1411  break;
1412  case STC__SUCCESS:
1413  sprintf(c_line, "-I- f_stc failure");
1414  break;
1415  case STC__INVSOCK:
1416  sprintf(c_line, "-I- f_stc invalid socket number");
1417  break;
1418  case STC__INVBUF:
1419  sprintf(c_line, "-I- f_stc buffer points outside allocated address space");
1420  break;
1421  case STC__NGBUFSIZE:
1422  sprintf(c_line, "-I- f_stc buffer length is negative");
1423  break;
1424  case STC__INVTIME:
1425  sprintf(c_line, "-I- f_stc time limit is negativ or to long");
1426  break;
1427  case STC__TIMEOUT:
1428  sprintf(c_line, "-I- f_stc timeout read data from socket");
1429  break;
1430  case STC__NOTSOCK:
1431  sprintf(c_line, "-I- f_stc socket number points to a file not a socket");
1432  break;
1433  case STC__INVADDR:
1434  sprintf(c_line, "-I- f_stc invalid address specified in parameter");
1435  break;
1436  case STC__INVADDRF:
1437  sprintf(c_line, "-I- f_stc the specified address family is not supported");
1438  break;
1439  case STC__SOCKNSUP:
1440  sprintf(c_line, "-I- f_stc The specified socket type is not supported.");
1441  break;
1442  case STC__INVPROTO:
1443  sprintf(c_line, "-I- f_stc The specified protocol is not supported.");
1444  break;
1445  case STC__SOCKTABF:
1446  sprintf(c_line, "-I- f_stc The per-process descriptor table is full.");
1447  break;
1448  case STC__SOCKSPAF:
1449  sprintf(c_line, "-I- f_stc No buffer space is available. The socket can't be created");
1450  break;
1451  case STC__SOCKISC:
1452  sprintf(c_line, "-I- f_stc socket is already connected.");
1453  break;
1454  case STC__CONNTOUT:
1455  sprintf(c_line, "-I- f_stc connection timed out without establishing a connection.");
1456  break;
1457  case STC__NETUNREA:
1458  sprintf(c_line, "-I- f_stc The network is not reachable from this host.");
1459  break;
1460  case STC__PORTINUS:
1461  sprintf(c_line, "-I- f_stc The specified Internet Address and port is already in use.");
1462  break;
1463  case STC__SOCKISP:
1464  sprintf(c_line, "-I- f_stc socket address is protected.");
1465  break;
1466  case STC__ECONNREF: /* added 17.7.95, H.G. */
1467  sprintf(c_line, "-I- f_stc connection refused.");
1468  break;
1469  case TPS__ECPORTS:
1470  sprintf(c_line, "-I- f_stc error connect portserver");
1471  break;
1472  case TPS__EREGSERV:
1473  sprintf(c_line, "-I- f_stc error register service at portserver");
1474  break;
1475  case TPS__EWTOPORTS:
1476  sprintf(c_line, "-I- f_stc error write buffer to portserver");
1477  break;
1478  case TPS__ERMFRPORTS:
1479  sprintf(c_line, "-I- f_stc error read status message from portserver");
1480  break;
1481  case TPS__EGSERVICE:
1482  sprintf(c_line, "-I- f_stc error get spec. info from portserver");
1483  break;
1484  default:
1485  sprintf(c_line, "-I- f_stc unknown message id %d", i_error);
1486  if (i_out == 0) {
1487  printf("%s\n", c_line);
1488  }
1489  if (i_out == 1) {
1490  strcpy(c_dest, c_line);
1491  }
1492  return STC__FAILURE;
1493  } /* end switch( i_error ) */
1494 
1495  if (i_out == 0) {
1496  printf("%s\n", c_line);
1497  }
1498  if (i_out == 1) {
1499  strcpy(c_dest, c_line);
1500  }
1501 
1502  return STC__SUCCESS;
1503 } /* f_stc_disperror() */
#define STC__ECONNRES
Definition: f_stccomm.h:395
char INTS1
Definition: typedefs.h:17
#define STC__NETUNREA
Definition: f_stccomm.h:383
INTS4 namelength
Definition: f_stccomm.h:308
INTS4 socket
Definition: f_stccomm.h:308
INTS4 f_stc_close(struct s_tcpcomm *ps_tcp)
Definition: f_stccomm.c:1095
#define STC__NOTSOCK
Definition: f_stccomm.h:374
struct hostent hostentstruct
Definition: f_stccomm.h:311
INTS4 f_stc_listenserver(struct s_tcpcomm *ps_server)
Definition: f_stccomm.c:1257
CHARS c_msg[80]
Definition: f_stccomm.c:10
#define STC__CONNTOUT
Definition: f_stccomm.h:382
#define STC__EINTR
Definition: f_stccomm.h:394
INTS4 f_stc_disperror(INTS4 i_error, CHARS *c_dest, INTS4 i_out)
Definition: f_stccomm.c:1402
#define TPS__ERMFRPORTS
Definition: f_stccomm.h:389
INTS4 f_stc_acceptclient(struct s_tcpcomm *ps_server, INTS4 *pi_channel)
Definition: f_stccomm.c:685
#define STC__SOCKSPAF
Definition: f_stccomm.h:380
INTS4 sock_rw
Definition: f_stccomm.h:308
#define TPS__EWTOPORTS
Definition: f_stccomm.h:388
#define STC__TIMEOUT
Definition: f_stccomm.h:373
INTS4 f_stc_discclient(INTS4 i_channel)
Definition: f_stccomm.c:1175
#define STC__PORTINUS
Definition: f_stccomm.h:384
INTS4 f_stc_connectserver(CHARS *c_node, INTS4 l_port, INTS4 *pi_channel, struct s_tcpcomm *ps_client)
Definition: f_stccomm.c:486
#define STC__SUCCESS
Definition: f_stccomm.h:368
#define TPS__EREGSERV
Definition: f_stccomm.h:387
struct hostent * hostentptr
Definition: f_stccomm.h:312
int INTS4
Definition: typedefs.h:21
#define STC__INVTIME
Definition: f_stccomm.h:372
#define STC__SOCKNSUP
Definition: f_stccomm.h:377
#define STC__INVSOCK
Definition: f_stccomm.h:369
#define STC__INVADDR
Definition: f_stccomm.h:375
#define TPS__EGSERVICE
Definition: f_stccomm.h:390
INTS1 hostname[256]
Definition: f_stccomm.h:313
#define STC__ECONNREF
Definition: f_stccomm.h:393
#define STC__NODATA
Definition: f_stccomm.h:392
#define STC__SOCKISP
Definition: f_stccomm.h:385
#define TPS__ECPORTS
Definition: f_stccomm.h:386
INTS4 f_stc_write(INTS1 *p_buffer, INTS4 i_buflen, INTS4 i_channel)
Definition: f_stccomm.c:324
#define STC__FAILURE
Definition: f_stccomm.h:367
struct sockaddr_in sock sock_name
Definition: f_stccomm.h:310
#define STC__INVBUF
Definition: f_stccomm.h:370
#define STC__NGBUFSIZE
Definition: f_stccomm.h:371
#define STC__INVPROTO
Definition: f_stccomm.h:378
#define STC__SOCKISC
Definition: f_stccomm.h:381
INTS4 f_stc_createserver(INTS4 *pl_port, struct s_tcpcomm *ps_server)
Definition: f_stccomm.c:846
#define STC__SOCKTABF
Definition: f_stccomm.h:379
#define STC__INVADDRF
Definition: f_stccomm.h:376
INTS4 f_stc_read(INTS1 *p_buffer, INTS4 i_buflen, INTS4 i_channel, INTS4 i_timeout)
Definition: f_stccomm.c:123
char CHARS
Definition: typedefs.h:15