Debian Codegraph @

kiss/kissnetd.c

raw symbols SCIP
1 /*
2 * kissnetd.c : Simple kiss broadcast daemon between several
3 * pseudo-tty devices.
4 * Each kiss frame received on one pty is broadcasted
5 * to each other one.
6 *
7 * ATEPRA FPAC/Linux Project
8 *
9 * F1OAT 960804 - Frederic RIBLE
10 */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <sys/time.h>
15 #include <sys/types.h>
16 #include <string.h>
17 #include <unistd.h>
18 #include <assert.h>
19 #include <fcntl.h>
20 #include <errno.h>
21 #include <syslog.h>
22 #include <time.h>
23 #include <limits.h>
24
25 #include <config.h>cxx . . $ `<file>/config.h`/
26 #include <scm-version.h>cxx . . $ `<file>/scm-version.h`/
27
28 static int VerboseModecxx . . $ VerboseMode.;
29 static int MaxFrameSizecxx . . $ MaxFrameSize. = 512;
30
31 #define REOPEN_TIMEOUTcxx . . $ `kiss/kissnetd.c:31:9`! 30 /* try tio reopen every 10 s */
32
33 struct PortDescriptorcxx . . $ PortDescriptor# {
34 char Namecxx . . $ PortDescriptor#Name.[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!];
35 int Fdcxx . . $ PortDescriptor#Fd.;
36 unsigned char *FrameBuffercxx . . $ PortDescriptor#FrameBuffer.;
37 int BufferIndexcxx . . $ PortDescriptor#BufferIndex.;
38 time_tcxx . . $ time_t# TimeLastOpencxx . . $ PortDescriptor#TimeLastOpen.;
39 char nameptscxx . . $ PortDescriptor#namepts.[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; /* name of the unix98 pts slaves, which
40 * the client has to use */
41 int is_activecxx . . $ PortDescriptor#is_active.;
42 };
43
44 static struct PortDescriptorcxx . . $ PortDescriptor# *PortListcxx . . $ PortList.[FD_SETSIZEcxx . . $ `<external>/946878812840035423/select.h:73:9`!];
45
46 static int NbPortcxx . . $ NbPort.;
47
48 static void Usagecxx . . $ Usage(49f6e7a06ebc5aa8).(void)
49 {
50 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\nUsage : kissnetd [-v] [-f size] [-p num | /dev/pty?? [/dev/pty??]* ]\n");
51 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -v : Verbose mode, trace on stdout\n");
52 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -f size : Set max frame size to size bytes (default 512)\n");
53 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -p num : Number of /dev/ptmx-master-devices has to open\n");
54 exitcxx . . $ exit(3ca292c338df9bb3).(1);
55 }
56
57 static void Bannercxx . . $ Banner(d4f767463ce0a6b3).(int Small)
58 {
59 if (Small) {
60 printfcxx . . $ printf(581fddd72a8db8fc).("kissnetd V %s by Frederic RIBLE F1OAT - ATEPRA FPAC/Linux Project\n", FULL_VERcxx . . $ `scm-version.h:6:9`!);
61 }
62 else {
63 printfcxx . . $ printf(581fddd72a8db8fc).("****************************************\n");
64 printfcxx . . $ printf(581fddd72a8db8fc).("* Network broadcast between kiss ports *\n");
65 printfcxx . . $ printf(581fddd72a8db8fc).("* ATEPRA FPAC/Linux Project *\n");
66 printfcxx . . $ printf(581fddd72a8db8fc).("****************************************\n");
67 printfcxx . . $ printf(581fddd72a8db8fc).("* %*skissnetd Version %s%*s*\n",
68 (int) (10 - strlencxx . . $ strlen(751346f8406fd082).(FULL_VERcxx . . $ `scm-version.h:6:9`!) / 2), "",
69 FULL_VERcxx . . $ `scm-version.h:6:9`!,
70 (int) (10 - (strlencxx . . $ strlen(751346f8406fd082).(FULL_VERcxx . . $ `scm-version.h:6:9`!) + 1)) / 2, "");
71 printfcxx . . $ printf(581fddd72a8db8fc).("* by Frederic RIBLE F1OAT *\n");
72 printfcxx . . $ printf(581fddd72a8db8fc).("****************************************\n");
73 }
74 }
75
76 static void NewPortcxx . . $ NewPort(fda57c8427c60377).(char *Name)
77 {
78 struct PortDescriptorcxx . . $ PortDescriptor# *MyPort;
79
80 if (VerboseModecxx . . $ VerboseMode.) {
81 printfcxx . . $ printf(581fddd72a8db8fc).("Opening port %s\n", Name);
82 }
83
84 if (NbPortcxx . . $ NbPort. == FD_SETSIZEcxx . . $ `<external>/946878812840035423/select.h:73:9`!) {
85 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Cannot handle %s : too many ports\n", Name);
86 exitcxx . . $ exit(3ca292c338df9bb3).(1);
87 }
88
89 MyPort = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(struct PortDescriptorcxx . . $ PortDescriptor#));
90 if (MyPort) MyPort->FrameBuffercxx . . $ PortDescriptor#FrameBuffer. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(sizeof (unsigned char), MaxFrameSizecxx . . $ MaxFrameSize.);
91 if (!MyPort || !MyPort->FrameBuffercxx . . $ PortDescriptor#FrameBuffer.) {
92 perrorcxx . . $ perror(85c52e162fed56f9).("cannot allocate port descriptor");
93 exitcxx . . $ exit(3ca292c338df9bb3).(1);
94 }
95
96 strncpycxx . . $ strncpy(255158a415b673b0).(MyPort->Namecxx . . $ PortDescriptor#Name., Name, PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!-1);
97 MyPort->Namecxx . . $ PortDescriptor#Name.[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!-1] = '\0';
98 MyPort->Fdcxx . . $ PortDescriptor#Fd. = -1;
99 MyPort->FrameBuffercxx . . $ PortDescriptor#FrameBuffer.[0] = 0xC0;
100 MyPort->BufferIndexcxx . . $ PortDescriptor#BufferIndex. = 1;
101 MyPort->nameptscxx . . $ PortDescriptor#namepts. [0] = '\0';
102 MyPort->is_activecxx . . $ PortDescriptor#is_active. = 0;
103 PortListcxx . . $ PortList.[NbPortcxx . . $ NbPort.++] = MyPort;
104 }
105
106 static void ReopenPortcxx . . $ ReopenPort(d4f767463ce0a6b3).(int PortNumber)
107 {
108 char MyString[28 + PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!];
109
110 PortListcxx . . $ PortList.[PortNumber]->TimeLastOpencxx . . $ PortDescriptor#TimeLastOpen. = timecxx . . $ time(7f38134db6521d23).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
111
112 if (VerboseModecxx . . $ VerboseMode.) {
113 printfcxx . . $ printf(581fddd72a8db8fc).("Reopening port %d\n", PortNumber);
114 }
115
116 if (PortListcxx . . $ PortList.[PortNumber]->nameptscxx . . $ PortDescriptor#namepts.[0] == '\0') {
117
118 syslogcxx . . $ syslog(afcfcee7634adf7d).(LOG_WARNINGcxx . . $ `<external>/6168640806541382331/syslog.h:55:9`!, "kissnetd : Opening port %s\n", PortListcxx . . $ PortList.[PortNumber]->Namecxx . . $ PortDescriptor#Name.);
119 PortListcxx . . $ PortList.[PortNumber]->Fdcxx . . $ PortDescriptor#Fd. = opencxx . . $ open(e156e3aa1e5c4ad1).(PortListcxx . . $ PortList.[PortNumber]->Namecxx . . $ PortDescriptor#Name., O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`! | O_NONBLOCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:62:10`!);
120 if (PortListcxx . . $ PortList.[PortNumber]->Fdcxx . . $ PortDescriptor#Fd. < 0) {
121 syslogcxx . . $ syslog(afcfcee7634adf7d).(LOG_WARNINGcxx . . $ `<external>/6168640806541382331/syslog.h:55:9`!, "kissnetd : Error opening port %s : %s\n",
122 PortListcxx . . $ PortList.[PortNumber]->Namecxx . . $ PortDescriptor#Name., strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
123 if (VerboseModecxx . . $ VerboseMode.) {
124 sprintfcxx . . $ sprintf(26c8642d26409d6d).(MyString, "cannot reopen %s", PortListcxx . . $ PortList.[PortNumber]->Namecxx . . $ PortDescriptor#Name.);
125 perrorcxx . . $ perror(85c52e162fed56f9).(MyString);
126 }
127 return;
128 }
129 PortListcxx . . $ PortList.[PortNumber]->is_activecxx . . $ PortDescriptor#is_active. = 1;
130 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(PortListcxx . . $ PortList.[PortNumber]->Namecxx . . $ PortDescriptor#Name., "/dev/ptmx")) {
131 char *npts;
132 /* get name of pts-device */
133 npts = ptsnamecxx . . $ ptsname(ff224f080444ee45).(PortListcxx . . $ PortList.[PortNumber]->Fdcxx . . $ PortDescriptor#Fd.);
134 if (npts == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
135 sprintfcxx . . $ sprintf(26c8642d26409d6d).(MyString, "Cannot get name of pts-device.\n");
136 syslogcxx . . $ syslog(afcfcee7634adf7d).(LOG_WARNINGcxx . . $ `<external>/6168640806541382331/syslog.h:55:9`!, "kissnetd : Cannot get name of pts-device\n");
137 exitcxx . . $ exit(3ca292c338df9bb3).(1);
138 }
139 strncpycxx . . $ strncpy(255158a415b673b0).(PortListcxx . . $ PortList.[PortNumber]->nameptscxx . . $ PortDescriptor#namepts., npts, PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!-1);
140 PortListcxx . . $ PortList.[PortNumber]->nameptscxx . . $ PortDescriptor#namepts.[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!-1] = '\0';
141
142 /* unlock pts-device */
143 if (unlockptcxx . . $ unlockpt(7864480464b09eea).(PortListcxx . . $ PortList.[PortNumber]->Fdcxx . . $ PortDescriptor#Fd.) == -1) {
144 sprintfcxx . . $ sprintf(26c8642d26409d6d).(MyString, "Cannot unlock pts-device %s\n", PortListcxx . . $ PortList.[PortNumber]->nameptscxx . . $ PortDescriptor#namepts.);
145 syslogcxx . . $ syslog(afcfcee7634adf7d).(LOG_WARNINGcxx . . $ `<external>/6168640806541382331/syslog.h:55:9`!, "kissnetd : Cannot unlock pts-device %s\n", PortListcxx . . $ PortList.[PortNumber]->nameptscxx . . $ PortDescriptor#namepts.);
146 exitcxx . . $ exit(3ca292c338df9bb3).(1);
147 }
148 syslogcxx . . $ syslog(afcfcee7634adf7d).(LOG_WARNINGcxx . . $ `<external>/6168640806541382331/syslog.h:55:9`!, "kissnetd : Using /dev/ptmx with slave pty %s\n", PortListcxx . . $ PortList.[PortNumber]->nameptscxx . . $ PortDescriptor#namepts.);
149 }
150 } else {
151 if (PortListcxx . . $ PortList.[PortNumber]->Fdcxx . . $ PortDescriptor#Fd. == -1) {
152 syslogcxx . . $ syslog(afcfcee7634adf7d).(LOG_WARNINGcxx . . $ `<external>/6168640806541382331/syslog.h:55:9`!, "kissnetd : Cannot reopen port ptmx (slave %s) : not supported by ptmx-device\n",
153 PortListcxx . . $ PortList.[PortNumber]->nameptscxx . . $ PortDescriptor#namepts.);
154 if (VerboseModecxx . . $ VerboseMode.) {
155 sprintfcxx . . $ sprintf(26c8642d26409d6d).(MyString, "cannot reopen ptmx (slave %s).", PortListcxx . . $ PortList.[PortNumber]->nameptscxx . . $ PortDescriptor#namepts.);
156 perrorcxx . . $ perror(85c52e162fed56f9).(MyString);
157 }
158 return;
159 }
160 syslogcxx . . $ syslog(afcfcee7634adf7d).(LOG_WARNINGcxx . . $ `<external>/6168640806541382331/syslog.h:55:9`!, "kissnetd : Trying to poll port ptmx (slave %s).\n",
161 PortListcxx . . $ PortList.[PortNumber]->nameptscxx . . $ PortDescriptor#namepts.);
162 PortListcxx . . $ PortList.[PortNumber]->is_activecxx . . $ PortDescriptor#is_active. = 1;
163 }
164 }
165
166 static void TickReopencxx . . $ TickReopen(49f6e7a06ebc5aa8).(void)
167 {
168 int i;
169 static int wrote_info;
170 time_tcxx . . $ time_t# CurrentTime = timecxx . . $ time(7f38134db6521d23).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
171
172 for (i=0; i<NbPortcxx . . $ NbPort.; i++) {
173 if (PortListcxx . . $ PortList.[i]->Fdcxx . . $ PortDescriptor#Fd. >= 0 && PortListcxx . . $ PortList.[i]->is_activecxx . . $ PortDescriptor#is_active. == 1) continue;
174 if ( (CurrentTime - PortListcxx . . $ PortList.[i]->TimeLastOpencxx . . $ PortDescriptor#TimeLastOpen.) > REOPEN_TIMEOUTcxx . . $ `kiss/kissnetd.c:31:9`! ) ReopenPortcxx . . $ ReopenPort(d4f767463ce0a6b3).(i);
175 }
176
177 if (!wrote_info) {
178 for (i=0; i<NbPortcxx . . $ NbPort.; i++) {
179 if (PortListcxx . . $ PortList.[i]->nameptscxx . . $ PortDescriptor#namepts.[0] != '\0') {
180 if (wrote_info == 0)
181 printfcxx . . $ printf(581fddd72a8db8fc).("\nAwaiting client connects on:\n");
182 else
183 printfcxx . . $ printf(581fddd72a8db8fc).(" ");
184 printfcxx . . $ printf(581fddd72a8db8fc).("%s", PortListcxx . . $ PortList.[i]->nameptscxx . . $ PortDescriptor#namepts.);
185 wrote_info = 1;
186 }
187 }
188 if (wrote_info > 0) {
189 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
190 if (!VerboseModecxx . . $ VerboseMode.) {
191 fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
192 fflushcxx . . $ fflush(89bc1efcdac0ca22).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
193 closecxx . . $ close(7864480464b09eea).(0);
194 closecxx . . $ close(7864480464b09eea).(1);
195 closecxx . . $ close(7864480464b09eea).(2);
196 }
197 }
198 }
199 }
200
201 static void Broadcastcxx . . $ Broadcast(d4f767463ce0a6b3).(int InputPort)
202 {
203 int i;
204 int rc;
205
206 /* Broadcast only info frames */
207
208 if (PortListcxx . . $ PortList.[InputPort]->FrameBuffercxx . . $ PortDescriptor#FrameBuffer.[1] != 0x00 && \
209 PortListcxx . . $ PortList.[InputPort]->FrameBuffercxx . . $ PortDescriptor#FrameBuffer.[1] != 0x20 && \
210 PortListcxx . . $ PortList.[InputPort]->FrameBuffercxx . . $ PortDescriptor#FrameBuffer.[1] != 0x80)
211 return;
212
213 for (i=0; i<NbPortcxx . . $ NbPort.; i++) {
214 int offset = 0;
215 if (i == InputPort) continue;
216 if (PortListcxx . . $ PortList.[i]->Fdcxx . . $ PortDescriptor#Fd. < 0 || PortListcxx . . $ PortList.[i]->is_activecxx . . $ PortDescriptor#is_active. == 0) continue;
217 again:
218 rc = writecxx . . $ write(41184a59d38b4f65).(PortListcxx . . $ PortList.[i]->Fdcxx . . $ PortDescriptor#Fd.,
219 PortListcxx . . $ PortList.[InputPort]->FrameBuffercxx . . $ PortDescriptor#FrameBuffer.+offset,
220 PortListcxx . . $ PortList.[InputPort]->BufferIndexcxx . . $ PortDescriptor#BufferIndex.-offset);
221 if (rc < 0) {
222 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EAGAINcxx . . $ `<external>/8987895939074593727/errno-base.h:15:9`!) {
223 if (PortListcxx . . $ PortList.[i]->nameptscxx . . $ PortDescriptor#namepts.[0] == '\0')
224 syslogcxx . . $ syslog(afcfcee7634adf7d).(LOG_WARNINGcxx . . $ `<external>/6168640806541382331/syslog.h:55:9`!, "kissnetd : write buffer full on port %s. dropping frame. %s",
225 PortListcxx . . $ PortList.[i]->Namecxx . . $ PortDescriptor#Name., strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
226 else
227 syslogcxx . . $ syslog(afcfcee7634adf7d).(LOG_WARNINGcxx . . $ `<external>/6168640806541382331/syslog.h:55:9`!, "kissnetd : write buffer full on ptmx port %s. dropping frame. %s",
228 PortListcxx . . $ PortList.[i]->nameptscxx . . $ PortDescriptor#namepts., strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
229 continue;
230 }
231 if (PortListcxx . . $ PortList.[i]->nameptscxx . . $ PortDescriptor#namepts.[0] == '\0')
232 syslogcxx . . $ syslog(afcfcee7634adf7d).(LOG_WARNINGcxx . . $ `<external>/6168640806541382331/syslog.h:55:9`!, "kissnetd : Error writing to port %s : %s\n",
233 PortListcxx . . $ PortList.[i]->Namecxx . . $ PortDescriptor#Name., strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
234 else
235 syslogcxx . . $ syslog(afcfcee7634adf7d).(LOG_WARNINGcxx . . $ `<external>/6168640806541382331/syslog.h:55:9`!, "kissnetd : Error writing to port ptmx (slave %s) : %s\n",
236 PortListcxx . . $ PortList.[i]->nameptscxx . . $ PortDescriptor#namepts., strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
237 if (VerboseModecxx . . $ VerboseMode.) perrorcxx . . $ perror(85c52e162fed56f9).("write");
238 PortListcxx . . $ PortList.[i]->is_activecxx . . $ PortDescriptor#is_active. = 0;
239 if (PortListcxx . . $ PortList.[i]->nameptscxx . . $ PortDescriptor#namepts.[0] == '\0') {
240 closecxx . . $ close(7864480464b09eea).(PortListcxx . . $ PortList.[i]->Fdcxx . . $ PortDescriptor#Fd.);
241 PortListcxx . . $ PortList.[i]->Fdcxx . . $ PortDescriptor#Fd. = -1;
242 }
243 continue;
244 }
245 if (VerboseModecxx . . $ VerboseMode.) {
246 printfcxx . . $ printf(581fddd72a8db8fc).("Sending %d bytes on port %d : rc=%d\n",
247 PortListcxx . . $ PortList.[InputPort]->BufferIndexcxx . . $ PortDescriptor#BufferIndex.,
248 i, rc);
249 }
250 if (rc < PortListcxx . . $ PortList.[InputPort]->BufferIndexcxx . . $ PortDescriptor#BufferIndex.-offset) {
251 offset += rc;
252 goto again;
253 }
254 }
255 }
256
257 static void ProcessInputcxx . . $ ProcessInput(d4f767463ce0a6b3).(int PortNumber)
258 {
259 static unsigned char MyBuffer[2048];
260 int Length;
261 int i;
262 struct PortDescriptorcxx . . $ PortDescriptor# *MyPort = PortListcxx . . $ PortList.[PortNumber];
263
264 Length = readcxx . . $ read(7e34d0a36f355389).(MyPort->Fdcxx . . $ PortDescriptor#Fd., MyBuffer, sizeof(MyBuffer));
265 if (VerboseModecxx . . $ VerboseMode.) {
266 printfcxx . . $ printf(581fddd72a8db8fc).("Read port %d : rc=%d\n", PortNumber, Length);
267 }
268 if (!Length) return;
269 if (Length < 0) {
270 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EAGAINcxx . . $ `<external>/8987895939074593727/errno-base.h:15:9`!)
271 return;
272 if (MyPort->nameptscxx . . $ PortDescriptor#namepts.[0] == '\0')
273 syslogcxx . . $ syslog(afcfcee7634adf7d).(LOG_WARNINGcxx . . $ `<external>/6168640806541382331/syslog.h:55:9`!, "kissnetd : Error reading from port %s : %s\n",
274 PortListcxx . . $ PortList.[PortNumber]->Namecxx . . $ PortDescriptor#Name., strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
275 else
276 syslogcxx . . $ syslog(afcfcee7634adf7d).(LOG_WARNINGcxx . . $ `<external>/6168640806541382331/syslog.h:55:9`!, "kissnetd : Error reading from port ptmx (slave %s) : %s\n",
277 PortListcxx . . $ PortList.[PortNumber]->nameptscxx . . $ PortDescriptor#namepts., strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
278 if (VerboseModecxx . . $ VerboseMode.) perrorcxx . . $ perror(85c52e162fed56f9).("read");
279 MyPort->is_activecxx . . $ PortDescriptor#is_active. = 0;
280 if (MyPort->nameptscxx . . $ PortDescriptor#namepts.[0] == '\0') {
281 closecxx . . $ close(7864480464b09eea).(MyPort->Fdcxx . . $ PortDescriptor#Fd.);
282 MyPort->Fdcxx . . $ PortDescriptor#Fd. = -1;
283 }
284 return;
285 }
286 for (i=0; i<Length; i++) {
287 if (MyPort->BufferIndexcxx . . $ PortDescriptor#BufferIndex. == MaxFrameSizecxx . . $ MaxFrameSize.) {
288 if (MyBuffer[i] == 0xC0) {
289 if (VerboseModecxx . . $ VerboseMode.) printfcxx . . $ printf(581fddd72a8db8fc).("Drop frame too long\n");
290 MyPort->BufferIndexcxx . . $ PortDescriptor#BufferIndex. = 1;
291 }
292 }
293 else {
294 MyPort->FrameBuffercxx . . $ PortDescriptor#FrameBuffer.[MyPort->BufferIndexcxx . . $ PortDescriptor#BufferIndex.++] = MyBuffer[i];
295 if (MyBuffer[i] == 0xC0) {
296 Broadcastcxx . . $ Broadcast(d4f767463ce0a6b3).(PortNumber);
297 MyPort->BufferIndexcxx . . $ PortDescriptor#BufferIndex. = 1;
298 }
299 }
300 }
301 }
302
303 static void ProcessPortListcxx . . $ ProcessPortList(49f6e7a06ebc5aa8).(void)
304 {
305 static fd_setcxx . . $ fd_set# MyFdSet;
306 int i, rc;
307 struct timevalcxx . . $ timeval# Timeout;
308
309 Timeout.tv_seccxx . . $ timeval#tv_sec. = 1;
310 Timeout.tv_useccxx . . $ timeval#tv_usec. = 0;
311
312 FD_ZEROcxx . . $ `<external>/946878812840035423/select.h:88:9`!(&MyFdSet);
313 for (i=0; i<NbPortcxx . . $ NbPort.; i++) {
314 if (PortListcxx . . $ PortList.[i]->Fdcxx . . $ PortDescriptor#Fd. >= 0 && PortListcxx . . $ PortList.[i]->is_activecxx . . $ PortDescriptor#is_active.) FD_SETcxx . . $ `<external>/946878812840035423/select.h:85:9`!(PortList[i]->Fd, &MyFdSet);
315 }
316 rc = selectcxx . . $ select(6d24c7514c8a5b88).(FD_SETSIZEcxx . . $ `<external>/946878812840035423/select.h:73:9`!, &MyFdSet, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &Timeout);
317
318 if (VerboseModecxx . . $ VerboseMode.) printfcxx . . $ printf(581fddd72a8db8fc).("select : rc=%d\n", rc);
319 if (!rc ) TickReopencxx . . $ TickReopen(49f6e7a06ebc5aa8).();
320
321 if (rc > 0) {
322 for (i=0; i<NbPortcxx . . $ NbPort. && rc; i++) {
323 if (PortListcxx . . $ PortList.[i]->Fdcxx . . $ PortDescriptor#Fd. < 0) continue;
324 if (FD_ISSETcxx . . $ `<external>/946878812840035423/select.h:87:9`!(PortList[i]->Fd, &MyFdSet)) {
325 ProcessInputcxx . . $ ProcessInput(d4f767463ce0a6b3).(i);
326 rc--;
327 }
328 }
329 }
330 }
331
332 static void ProcessArgvcxx . . $ ProcessArgv(c759356ac01a31e7).(int argc, char *argv[])
333 {
334 int opt;
335 int i=0;
336 int ptmxdevices = 0;
337
338 while ((opt = getoptcxx . . $ getopt(2483c31ff9bab884).(argc, argv, "vf:p:")) != -1) {
339 switch (opt) {
340 case 'v':
341 VerboseModecxx . . $ VerboseMode. = 1;
342 break;
343 case 'f':
344 MaxFrameSizecxx . . $ MaxFrameSize. = atoicxx . . $ atoi(5c4306d8553b3696).(argv[optindcxx . . $ optind.]);
345 break;
346 case 'p':
347 ptmxdevices = atoicxx . . $ atoi(5c4306d8553b3696).(optargcxx . . $ optarg.);
348 if (ptmxdevices < 1) {
349 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error: too many devices\n");
350 exitcxx . . $ exit(3ca292c338df9bb3).(1);
351 }
352 for (i=0; i < ptmxdevices; i++)
353 NewPortcxx . . $ NewPort(fda57c8427c60377).("/dev/ptmx");
354 break;
355 default:
356 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Invalid option %s\n", argv[optindcxx . . $ optind.]);
357 Usagecxx . . $ Usage(49f6e7a06ebc5aa8).();
358 exitcxx . . $ exit(3ca292c338df9bb3).(1);
359 }
360 }
361
362 while (optindcxx . . $ optind. < argc)
363 NewPortcxx . . $ NewPort(fda57c8427c60377).(argv[optindcxx . . $ optind.++]);
364
365 if (NbPortcxx . . $ NbPort. < 2) {
366 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "This multiplexer needs at least two pty's\n");
367 exitcxx . . $ exit(3ca292c338df9bb3).(1);
368 }
369 }
370
371
372 int maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[])
373 {
374 if (argc < 2) {
375 Bannercxx . . $ Banner(d4f767463ce0a6b3).(0);
376 Usagecxx . . $ Usage(49f6e7a06ebc5aa8).();
377 }
378 else {
379 Bannercxx . . $ Banner(d4f767463ce0a6b3).(1);
380 }
381
382 ProcessArgvcxx . . $ ProcessArgv(c759356ac01a31e7).(argc, argv);
383 while (1) ProcessPortListcxx . . $ ProcessPortList(49f6e7a06ebc5aa8).();
384 return 0;
385 }