* Copyright (c) 1988 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)utilities.c 1.14 (Berkeley) %G%";
FILE *NetTrace
= 0; /* Not in bss, since needs to stay */
* Upcase (in place) the argument.
while ((c
= *argument
) != 0) {
* Compensate for differences in 4.2 and 4.3 systems.
SetSockOpt(fd
, level
, option
, yesno
)
return setsockopt(fd
, level
, option
,
(char *)&yesno
, sizeof yesno
);
if (yesno
== 0) { /* Can't do that in 4.2! */
fprintf(stderr
, "Error: attempt to turn off an option 0x%x.\n",
return setsockopt(fd
, level
, option
, 0, 0);
* The following are routines used to print out debugging information.
char NetTraceFile
[256] = "(standard output)";
if (NetTrace
&& NetTrace
!= stdout
)
if (file
&& (strcmp(file
, "-") != 0)) {
NetTrace
= fopen(file
, "w");
strcpy(NetTraceFile
, file
);
fprintf(stderr
, "Cannot open %s.\n", file
);
strcpy(NetTraceFile
, "(standard output)");
Dump(direction
, buffer
, length
)
# define BYTES_PER_LINE 32
# define min(x,y) ((x<y)? x:y)
fprintf(NetTrace
, "%c 0x%x\t", direction
, offset
);
buffer
= buffer
+ min(length
, BYTES_PER_LINE
);
fprintf(NetTrace
, "%c%.2x",
(((*pThis
)&0xff) == 0xff) ? '*' : ' ',
buffer
= buffer
+ min(length
, BYTES_PER_LINE
/2);
fprintf(NetTrace
, "%.2x", (*pThis
)&0xff);
if (NetTrace
== stdout
) {
fprintf(NetTrace
, "\r\n");
length
-= BYTES_PER_LINE
;
offset
+= BYTES_PER_LINE
;
/* find next unique line */
printoption(direction
, fmt
, option
)
fprintf(NetTrace
, "%s ", direction
);
fprintf(NetTrace
, "%s %s", fmt
, TELOPT(option
));
else if (TELCMD_OK(option
))
fprintf(NetTrace
, "%s %s", fmt
, TELCMD(option
));
fprintf(NetTrace
, "%s %d", fmt
, option
);
fprintf(NetTrace
, "\r\n");
extern char will_wont_resp
[], do_dont_resp
[];
for (i
= 0; i
< 256; i
++) {
printf("resp DO_DONT %s: %d\n", TELOPT(i
), do_dont_resp
[i
]);
printf("resp DO_DONT %s: %d\n", TELCMD(i
), do_dont_resp
[i
]);
printf("resp DO_DONT %d: %d\n", i
,
if (my_want_state_is_do(i
)) {
printf("want DO %s\n", TELOPT(i
));
printf("want DO %s\n", TELCMD(i
));
printf("want DO %d\n", i
);
printf("want DONT %s\n", TELOPT(i
));
printf("want DONT %s\n", TELCMD(i
));
printf("want DONT %d\n", i
);
printf(" DO %s\n", TELOPT(i
));
printf(" DO %s\n", TELCMD(i
));
printf("resp WILL_WONT %s: %d\n", TELOPT(i
), will_wont_resp
[i
]);
printf("resp WILL_WONT %s: %d\n", TELCMD(i
), will_wont_resp
[i
]);
printf("resp WILL_WONT %d: %d\n",
if (my_want_state_is_will(i
)) {
printf("want WILL %s\n", TELOPT(i
));
printf("want WILL %s\n", TELCMD(i
));
printf("want WILL %d\n", i
);
printf("want WONT %s\n", TELOPT(i
));
printf("want WONT %s\n", TELCMD(i
));
printf("want WONT %d\n", i
);
if (my_state_is_will(i
)) {
printf(" WILL %s\n", TELOPT(i
));
printf(" WILL %s\n", TELCMD(i
));
char *slcnames
[] = { SLC_NAMES
};
printsub(direction
, pointer
, length
)
char direction
; /* '<' or '>' */
unsigned char *pointer
; /* where suboption data sits */
int length
; /* length of suboption data */
fprintf(NetTrace
, "%s suboption ",
(direction
== '<')? "Received":"Sent");
if (i
!= IAC
|| j
!= SE
) {
fprintf(NetTrace
, "(terminated by ");
fprintf(NetTrace
, "%s ", TELOPT(i
));
fprintf(NetTrace
, "%s ", TELCMD(i
));
fprintf(NetTrace
, "%d ", i
);
fprintf(NetTrace
, "%s", TELOPT(j
));
fprintf(NetTrace
, "%s", TELCMD(j
));
fprintf(NetTrace
, "%d", j
);
fprintf(NetTrace
, ", not IAC SE!) ");
fprintf(NetTrace
, "(Empty suboption???)");
fprintf(NetTrace
, "TERMINAL-TYPE ");
fprintf(NetTrace
, "IS \"%.*s\"", length
-2, pointer
+2);
fprintf(NetTrace
, "SEND");
"- unknown qualifier %d (0x%x).",
fprintf(NetTrace
, "TERMINAL-SPEED");
fprintf(NetTrace
, " (empty suboption???)");
fprintf(NetTrace
, " IS ");
fprintf(NetTrace
, "%.*s", length
-2, pointer
+2);
fprintf(NetTrace
, " SEND");
fprintf(NetTrace
, " %d (unknown)");
for (i
= 2; i
< length
; i
++)
fprintf(NetTrace
, " ?%d?", pointer
[i
]);
fprintf(NetTrace
, "TOGGLE-FLOW-CONTROL");
fprintf(NetTrace
, " (empty suboption???)");
fprintf(NetTrace
, " OFF"); break;
fprintf(NetTrace
, " ON"); break;
fprintf(NetTrace
, " %d (unknown)");
for (i
= 2; i
< length
; i
++)
fprintf(NetTrace
, " ?%d?", pointer
[i
]);
fprintf(NetTrace
, "NAWS");
fprintf(NetTrace
, " (empty suboption???)");
fprintf(NetTrace
, " ?%d?", pointer
[1]);
fprintf(NetTrace
, " %d %d (%d)",
(((unsigned int)pointer
[1])<<8)|((unsigned int)pointer
[2]));
fprintf(NetTrace
, " ?%d?", pointer
[3]);
fprintf(NetTrace
, " %d %d (%d)",
(((unsigned int)pointer
[3])<<8)|((unsigned int)pointer
[4]));
for (i
= 5; i
< length
; i
++)
fprintf(NetTrace
, " ?%d?", pointer
[i
]);
fprintf(NetTrace
, "LINEMODE ");
fprintf(NetTrace
, " (empty suboption???)");
fprintf(NetTrace
, "WILL ");
fprintf(NetTrace
, "WONT ");
fprintf(NetTrace
, "DO ");
fprintf(NetTrace
, "DONT ");
fprintf(NetTrace
, "(no option???)");
fprintf(NetTrace
, "Forward Mask");
for (i
= 3; i
< length
; i
++)
fprintf(NetTrace
, " %x", pointer
[i
]);
fprintf(NetTrace
, "%d (unknown)", pointer
[2]);
for (i
= 3; i
< length
; i
++)
fprintf(NetTrace
, " %d", pointer
[i
]);
fprintf(NetTrace
, "SLC");
for (i
= 2; i
< length
- 2; i
+= 3) {
if (pointer
[i
+SLC_FUNC
] <= NSLC
)
fprintf(NetTrace
, " %s", slcnames
[pointer
[i
+SLC_FUNC
]]);
fprintf(NetTrace
, " %d", pointer
[i
+SLC_FUNC
]);
switch (pointer
[i
+SLC_FLAGS
]&SLC_LEVELBITS
) {
fprintf(NetTrace
, " NOSUPPORT"); break;
fprintf(NetTrace
, " CANTCHANGE"); break;
fprintf(NetTrace
, " VARIABLE"); break;
fprintf(NetTrace
, " DEFAULT"); break;
fprintf(NetTrace
, "%s%s%s",
pointer
[i
+SLC_FLAGS
]&SLC_ACK
? "|ACK" : "",
pointer
[i
+SLC_FLAGS
]&SLC_FLUSHIN
? "|FLUSHIN" : "",
pointer
[i
+SLC_FLAGS
]&SLC_FLUSHOUT
? "|FLUSHOUT" : "");
if (pointer
[i
+SLC_FLAGS
]& ~(SLC_ACK
|SLC_FLUSHIN
|
SLC_FLUSHOUT
| SLC_LEVELBITS
))
fprintf(NetTrace
, "(0x%x)", pointer
[i
+SLC_FLAGS
]);
fprintf(NetTrace
, " %d;", pointer
[i
+SLC_VALUE
]);
fprintf(NetTrace
, " ?%d?", pointer
[i
]);
fprintf(NetTrace
, "MODE ");
fprintf(NetTrace
, "(no mode???)");
pointer
[2]&MODE_EDIT
? "|EDIT" : "",
pointer
[2]&MODE_TRAPSIG
? "|TRAPSIG" : "",
pointer
[2]&MODE_ACK
? "|ACK" : "");
fprintf(NetTrace
, "%s", tbuf
[1] ? &tbuf
[1] : "0");
if (pointer
[2]&~(MODE_EDIT
|MODE_TRAPSIG
|MODE_ACK
))
fprintf(NetTrace
, " (0x%x)", pointer
[2]);
for (i
= 3; i
< length
; i
++)
fprintf(NetTrace
, " ?0x%x?", pointer
[i
]);
fprintf(NetTrace
, "%d (unknown)", pointer
[1]);
for (i
= 2; i
< length
; i
++)
fprintf(NetTrace
, " %d", pointer
[i
]);
fprintf(NetTrace
, "Unknown option ");
for (i
= 0; i
< length
; i
++)
fprintf(NetTrace
, " %d", pointer
[i
]);
fprintf(NetTrace
, "\r\n");
/* EmptyTerminal - called to make sure that the terminal buffer is empty.
* Note that we consider the buffer to run all the
* way to the kernel (thus the select).
#endif /* defined(unix) */
(void) select(tout
+1, (fd_set
*) 0, &o
, (fd_set
*) 0,
(struct timeval
*) 0); /* wait for TTLOWAT */
#endif /* defined(unix) */
(void) select(tout
+1, (fd_set
*) 0, &o
, (fd_set
*) 0,
(struct timeval
*) 0); /* wait for TTLOWAT */
#endif /* defined(unix) */
#else /* defined(TN3270) */
telrcv(); /* Process any incoming data */
} while (ring_full_count(&netiring
)); /* While there is any */
#endif /* defined(TN3270) */
#endif /* defined(TN3270) */
EmptyTerminal(); /* Flush the path to the tty */
ExitString(string
, returnCode
)
fwrite(string
, 1, strlen(string
), stderr
);
ExitPerror(string
, returnCode
)
#endif /* defined(MSDOS) */