This is Unofficial EPICS BASE Doxygen Site
caRepeater.cpp
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE is distributed subject to a Software License Agreement found
7 * in file LICENSE that is included with this distribution.
8 \*************************************************************************/
9 /*
10  *
11  * CA UDP repeater standalone executable
12  *
13  * Author: Jeff Hill
14  * Date: 3-27-90
15  *
16  * PURPOSE:
17  * Broadcasts fan out over the LAN, but old IP kernels do not allow
18  * two processes on the same machine to get the same broadcast
19  * (and modern IP kernels do not allow two processes on the same machine
20  * to receive the same unicast).
21  *
22  * This code fans out UDP messages sent to the CA repeater port
23  * to all CA client processes that have subscribed.
24  *
25  * NOTES:
26  *
27  * see repeater.c
28  *
29  */
30 
31 #define epicsAssertAuthor "Jeff Hill johill@lanl.gov"
32 
33 #include <stdio.h>
34 
35 #if !defined(_WIN32) && !defined(__rtems__) && !defined(vxWorks)
36 # include <sys/types.h>
37 # include <sys/stat.h>
38 # include <fcntl.h>
39 #define CAN_DETACH_STDINOUT
40 #endif
41 
42 #include "epicsAssert.h"
43 #include "osiUnistd.h"
44 #include "epicsGetopt.h"
45 #include "udpiiu.h"
46 
47 static void usage(char* argv[])
48 {
49  fprintf(stderr, "Usage: %s -hv\n"
50  "\n"
51  " -h - Print this message\n"
52  " -v - Do not replace stdin/out/err with /dev/null\n",
53  argv[0]);
54 }
55 
56 int main(int argc, char* argv[])
57 {
58  bool detachinout = true;
59 
60  int opt;
61  while ((opt = getopt(argc, argv, "hv")) != -1) {
62  switch (opt) {
63  default:
64  usage(argv);
65  fprintf(stderr, "\nUnknown argument '%c'\n", opt);
66  return 1;
67  case 'h':
68  usage(argv);
69  return 0;
70  case 'v':
71  detachinout = false;
72  break;
73  }
74  }
75 
76 #ifdef CAN_DETACH_STDINOUT
77  if(detachinout) {
78  int readfd = open("/dev/null", O_RDONLY);
79  int writefd = open("/dev/null", O_WRONLY);
80 
81  dup2(readfd, 0);
82  dup2(writefd, 1);
83  dup2(writefd, 2);
84 
85  close(readfd);
86  close(writefd);
87  }
88 #else
89  (void)detachinout;
90 #endif
91 
92  chdir ( "/" );
93  ca_repeater ();
94  return ( 0 );
95 }
96 
int getopt(int nargc, char *const *nargv, const char *ostr)
Definition: epicsGetopt.c:65
int main(int argc, char *argv[])
Definition: caRepeater.cpp:56
An EPICS-specific replacement for ANSI C&#39;s assert.
void ca_repeater()
Definition: repeater.cpp:482
#define stderr
Definition: epicsStdio.h:32