Minor fixes in opentcp
This commit is contained in:
parent
b3f78e2934
commit
16256e4a39
@ -32,6 +32,9 @@ v0.35.07 11-Dec-2002
|
||||
The index command displays LFN names in the webpages again.
|
||||
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
|
||||
|
3
TODO
3
TODO
@ -102,6 +102,9 @@ mbcico:
|
||||
|
||||
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:
|
||||
N: Add a check to see if the magic filenames are (still) valid.
|
||||
|
||||
|
@ -82,28 +82,35 @@ int opentcp(char *name)
|
||||
{
|
||||
struct servent *se;
|
||||
struct hostent *he;
|
||||
int a1,a2,a3,a4;
|
||||
char *errmsg;
|
||||
char *portname;
|
||||
int Fd;
|
||||
int a1, a2, a3, a4, Fd, GotPort = FALSE;
|
||||
char *errmsg, *portname;
|
||||
short portnum;
|
||||
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;
|
||||
memset(&telnet_options, 0, sizeof(telnet_options));
|
||||
server.sin_family = AF_INET;
|
||||
|
||||
/*
|
||||
* Get port number from name argument if there is a : part
|
||||
*/
|
||||
if ((portname = strchr(name,':'))) {
|
||||
*portname++='\0';
|
||||
if ((portnum = atoi(portname)))
|
||||
if ((portnum = atoi(portname))) {
|
||||
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;
|
||||
else
|
||||
server.sin_port = htons(FIDOPORT);
|
||||
} else {
|
||||
GotPort = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If not a forced port number, get the defaults.
|
||||
*/
|
||||
if (! GotPort) {
|
||||
switch (tcp_mode) {
|
||||
case TCPMODE_IFC: if ((se = getservbyname("fido", "tcp")))
|
||||
server.sin_port = se->s_port;
|
||||
@ -124,24 +131,24 @@ int opentcp(char *name)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Get IP address for the hostname
|
||||
*/
|
||||
if (sscanf(name,"%d.%d.%d.%d",&a1,&a2,&a3,&a4) == 4)
|
||||
server.sin_addr.s_addr = inet_addr(name);
|
||||
else if ((he = gethostbyname(name)))
|
||||
memcpy(&server.sin_addr,he->h_addr,he->h_length);
|
||||
else {
|
||||
switch (h_errno) {
|
||||
case HOST_NOT_FOUND: errmsg=(char *)"Authoritative: Host not found"; break;
|
||||
case TRY_AGAIN: errmsg=(char *)"Non-Authoritive: Host not found"; break;
|
||||
case NO_RECOVERY: errmsg=(char *)"Non recoverable errors"; break;
|
||||
default: errmsg=(char *)"Unknown error"; break;
|
||||
case HOST_NOT_FOUND: errmsg = (char *)"Authoritative: Host not found"; break;
|
||||
case TRY_AGAIN: errmsg = (char *)"Non-Authoritive: Host not found"; break;
|
||||
case NO_RECOVERY: errmsg = (char *)"Non recoverable errors"; break;
|
||||
default: errmsg = (char *)"Unknown error"; break;
|
||||
}
|
||||
Syslog('+', "No IP address for %s: %s\n", name, errmsg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
Syslog('d', "Trying %s at port %d",
|
||||
inet_ntoa(server.sin_addr),(int)ntohs(server.sin_port));
|
||||
|
||||
signal(SIGPIPE,linedrop);
|
||||
fflush(stdin);
|
||||
fflush(stdout);
|
||||
@ -169,16 +176,12 @@ int opentcp(char *name)
|
||||
|
||||
f_flags=0;
|
||||
|
||||
switch (tcp_mode) {
|
||||
case TCPMODE_ITN: tel_enter_binary(3);
|
||||
Syslog('+', "Established ITN/TCP connection with %s", inet_ntoa(server.sin_addr));
|
||||
break;
|
||||
case TCPMODE_IFC: Syslog('+', "Established IFC/TCP connection with %s", inet_ntoa(server.sin_addr));
|
||||
break;
|
||||
case TCPMODE_IBN: Syslog('+', "Established IBN/TCP connection with %s", inet_ntoa(server.sin_addr));
|
||||
break;
|
||||
default: WriteError("Established TCP connection with unknow protocol");
|
||||
}
|
||||
if (tcp_mode == TCPMODE_ITN)
|
||||
tel_enter_binary(3);
|
||||
|
||||
Syslog('+', "Established %s/TCP connection with %s, port %d",
|
||||
(tcp_mode == TCPMODE_ITN) ? "ITN":(tcp_mode == TCPMODE_IFC) ? "IFC":(tcp_mode == TCPMODE_IBN) ? "IBN":"Unknown",
|
||||
inet_ntoa(server.sin_addr), (int)ntohs(server.sin_port));
|
||||
c_start = time(NULL);
|
||||
carrier = TRUE;
|
||||
tcp_is_open = TRUE;
|
||||
@ -195,25 +198,23 @@ void closetcp(void)
|
||||
if (!tcp_is_open)
|
||||
return;
|
||||
|
||||
Syslog('d', "Closing TCP connection");
|
||||
|
||||
if (tcp_mode == TCPMODE_ITN)
|
||||
tel_leave_binary(3);
|
||||
|
||||
shutdown(fd,2);
|
||||
shutdown(fd, 2);
|
||||
signal(SIGPIPE,SIG_DFL);
|
||||
|
||||
if (carrier) {
|
||||
c_end = time(NULL);
|
||||
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;
|
||||
history.offline = c_end;
|
||||
history.online = c_start;
|
||||
history.sent_bytes = sentbytes;
|
||||
history.rcvd_bytes = rcvdbytes;
|
||||
history.inbound = ~master;
|
||||
tmp = calloc(128, sizeof(char));
|
||||
tmp = calloc(PATH_MAX, sizeof(char));
|
||||
sprintf(tmp, "%s/var/mailer.hist", getenv("MBSE_ROOT"));
|
||||
if ((fph = fopen(tmp, "a")) == NULL)
|
||||
WriteError("$Can't open %s", tmp);
|
||||
|
Reference in New Issue
Block a user