On 04/23/2012 09:12 PM, Timothy Pearson wrote:
The part I don't get is that this worked at all in
KDE 3.5.10.
Specifically this portion of the code:
else {
struct servent *pse;
if( (pse = getservbyname("ssh", "tcp") ) == NULL )
mPort = 22;
else
mPort = ntohs(pse->s_port);
}
looks like it should be completely removed! This duplicates the default
port logic in ssh (bad), and also overrides any ports set via the ssh
option file (even worse).
I'd try removing that section of code to see if it resolves the problem.
Tim
I think you are correct. I didn't know what the hell it did, so I wrote a code
snippet to look at it and the pse structure created. What I don't get is how the
heck this would ever get the correct port since you are never providing
getservbyname with any remote host information. I run this and I get port
numbers -- but 1+1!=2 yet...:
#include <limits.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <netdb.h>
#include <arpa/inet.h>
int getval (char *str, int base);
int main(int argc, char *argv[])
{
int mPort;
long port;
if (argc < 2) {
fprintf(stderr, "Usage: %s port_str [base]\n", argv[0]);
exit(EXIT_FAILURE);
}
port = getval(argv[1], (argc > 2) ? atoi(argv[2]) : 10);
printf("port: %d\n", port);
struct servent *pse;
pse = getservbyname("ssh", "tcp");
if( port > 0 )
mPort = port;
else {
if( (pse) == NULL )
mPort = 22;
else
mPort = ntohs(pse->s_port);
}
printf("mPort: %d\n", mPort);
printf("(servant *pse)\n\
pse->s_name: %s\n\
pse->s_aliases: %s\n\
pse->s_port %d\n\
pse->s_proto %s\n", pse->s_name, pse->s_aliases, pse->s_port,
pse->s_proto);
printf ("The host byte order -> Network byte order: %d\n\n",
ntohs(pse->s_port));
return 0;
}
int getval (char *str, int base) {
char *endptr;
long val;
errno = 0; /* To distinguish success/failure after call */
val = strtol(str, &endptr, base);
/* Check for various possible errors */
if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
|| (errno != 0 && val == 0)) {
perror("strtol");
return(EXIT_FAILURE);
}
if (endptr == str) {
fprintf(stderr, "No digits were found\n");
return(EXIT_FAILURE);
}
/* If we got here, strtol() successfully parsed a number */
printf("strtol() returned %ld\n", val);
if (*endptr != '\0') /* Not necessarily an error... */
printf("Further characters after number: %s\n", endptr);
return (val);
}
--
David C. Rankin, J.D.,P.E.