Minor fixes in opentcp

This commit is contained in:
Michiel Broek 2002-12-21 22:23:14 +00:00
parent b3f78e2934
commit 16256e4a39
3 changed files with 161 additions and 154 deletions

View File

@ -32,6 +32,9 @@ v0.35.07 11-Dec-2002
The index command displays LFN names in the webpages again. The index command displays LFN names in the webpages again.
The real download still sends the 8.3 name. The real download still sends the 8.3 name.
mbcico:
Code cleanup in opentcp, better handling of given ports and
better logging.
v0.35.06 13-Nov-2002 - 11-Dec-2002 v0.35.06 13-Nov-2002 - 11-Dec-2002

3
TODO
View File

@ -102,6 +102,9 @@ mbcico:
N: Implement binkp resync when getting files. Transmit works. N: Implement binkp resync when getting files. Transmit works.
N: Add better check for stale outbound locks, check if the pid is from
a non-mbse program or add a age check.
mbfile: mbfile:
N: Add a check to see if the magic filenames are (still) valid. N: Add a check to see if the magic filenames are (still) valid.

View File

@ -82,28 +82,35 @@ int opentcp(char *name)
{ {
struct servent *se; struct servent *se;
struct hostent *he; struct hostent *he;
int a1,a2,a3,a4; int a1, a2, a3, a4, Fd, GotPort = FALSE;
char *errmsg; char *errmsg, *portname;
char *portname;
int Fd;
short portnum; short portnum;
struct sockaddr_in server; struct sockaddr_in server;
Syslog('d', "Try open tcp connection to %s",MBSE_SS(name)); Syslog('+', "Open TCP connection to \"%s\"", MBSE_SS(name));
tcp_is_open = FALSE; tcp_is_open = FALSE;
memset(&telnet_options, 0, sizeof(telnet_options)); memset(&telnet_options, 0, sizeof(telnet_options));
server.sin_family = AF_INET; server.sin_family = AF_INET;
/*
* Get port number from name argument if there is a : part
*/
if ((portname = strchr(name,':'))) { if ((portname = strchr(name,':'))) {
*portname++='\0'; *portname++='\0';
if ((portnum = atoi(portname))) if ((portnum = atoi(portname))) {
server.sin_port=htons(portnum); server.sin_port=htons(portnum);
else if ((se = getservbyname(portname, "tcp"))) GotPort = TRUE;
} else if ((se = getservbyname(portname, "tcp"))) {
server.sin_port = se->s_port; server.sin_port = se->s_port;
else GotPort = TRUE;
server.sin_port = htons(FIDOPORT); }
} else { }
/*
* If not a forced port number, get the defaults.
*/
if (! GotPort) {
switch (tcp_mode) { switch (tcp_mode) {
case TCPMODE_IFC: if ((se = getservbyname("fido", "tcp"))) case TCPMODE_IFC: if ((se = getservbyname("fido", "tcp")))
server.sin_port = se->s_port; server.sin_port = se->s_port;
@ -124,6 +131,9 @@ int opentcp(char *name)
} }
} }
/*
* Get IP address for the hostname
*/
if (sscanf(name,"%d.%d.%d.%d",&a1,&a2,&a3,&a4) == 4) if (sscanf(name,"%d.%d.%d.%d",&a1,&a2,&a3,&a4) == 4)
server.sin_addr.s_addr = inet_addr(name); server.sin_addr.s_addr = inet_addr(name);
else if ((he = gethostbyname(name))) else if ((he = gethostbyname(name)))
@ -139,9 +149,6 @@ int opentcp(char *name)
return -1; return -1;
} }
Syslog('d', "Trying %s at port %d",
inet_ntoa(server.sin_addr),(int)ntohs(server.sin_port));
signal(SIGPIPE,linedrop); signal(SIGPIPE,linedrop);
fflush(stdin); fflush(stdin);
fflush(stdout); fflush(stdout);
@ -169,16 +176,12 @@ int opentcp(char *name)
f_flags=0; f_flags=0;
switch (tcp_mode) { if (tcp_mode == TCPMODE_ITN)
case TCPMODE_ITN: tel_enter_binary(3); tel_enter_binary(3);
Syslog('+', "Established ITN/TCP connection with %s", inet_ntoa(server.sin_addr));
break; Syslog('+', "Established %s/TCP connection with %s, port %d",
case TCPMODE_IFC: Syslog('+', "Established IFC/TCP connection with %s", inet_ntoa(server.sin_addr)); (tcp_mode == TCPMODE_ITN) ? "ITN":(tcp_mode == TCPMODE_IFC) ? "IFC":(tcp_mode == TCPMODE_IBN) ? "IBN":"Unknown",
break; inet_ntoa(server.sin_addr), (int)ntohs(server.sin_port));
case TCPMODE_IBN: Syslog('+', "Established IBN/TCP connection with %s", inet_ntoa(server.sin_addr));
break;
default: WriteError("Established TCP connection with unknow protocol");
}
c_start = time(NULL); c_start = time(NULL);
carrier = TRUE; carrier = TRUE;
tcp_is_open = TRUE; tcp_is_open = TRUE;
@ -195,8 +198,6 @@ void closetcp(void)
if (!tcp_is_open) if (!tcp_is_open)
return; return;
Syslog('d', "Closing TCP connection");
if (tcp_mode == TCPMODE_ITN) if (tcp_mode == TCPMODE_ITN)
tel_leave_binary(3); tel_leave_binary(3);
@ -206,14 +207,14 @@ void closetcp(void)
if (carrier) { if (carrier) {
c_end = time(NULL); c_end = time(NULL);
online += (c_end - c_start); online += (c_end - c_start);
Syslog('+', "Connection time %s", t_elapsed(c_start, c_end)); Syslog('+', "Closing TCP connection, connected %s", t_elapsed(c_start, c_end));
carrier = FALSE; carrier = FALSE;
history.offline = c_end; history.offline = c_end;
history.online = c_start; history.online = c_start;
history.sent_bytes = sentbytes; history.sent_bytes = sentbytes;
history.rcvd_bytes = rcvdbytes; history.rcvd_bytes = rcvdbytes;
history.inbound = ~master; history.inbound = ~master;
tmp = calloc(128, sizeof(char)); tmp = calloc(PATH_MAX, sizeof(char));
sprintf(tmp, "%s/var/mailer.hist", getenv("MBSE_ROOT")); sprintf(tmp, "%s/var/mailer.hist", getenv("MBSE_ROOT"));
if ((fph = fopen(tmp, "a")) == NULL) if ((fph = fopen(tmp, "a")) == NULL)
WriteError("$Can't open %s", tmp); WriteError("$Can't open %s", tmp);