(setpeer): handle both service names and port numbers for the second
optional argument. also make parsing more robust git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@9679 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -81,7 +81,7 @@ void
|
|||||||
setpeer(int argc, char **argv)
|
setpeer(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *host;
|
char *host;
|
||||||
short port;
|
u_short port;
|
||||||
struct servent *sp;
|
struct servent *sp;
|
||||||
|
|
||||||
if (connected) {
|
if (connected) {
|
||||||
@@ -102,14 +102,23 @@ setpeer(int argc, char **argv)
|
|||||||
errx(1, "You bastard. You removed ftp/tcp from services");
|
errx(1, "You bastard. You removed ftp/tcp from services");
|
||||||
port = sp->s_port;
|
port = sp->s_port;
|
||||||
if (argc > 2) {
|
if (argc > 2) {
|
||||||
port = atoi(argv[2]);
|
sp = getservbyname(argv[2], "tcp");
|
||||||
if (port <= 0) {
|
if (sp != NULL) {
|
||||||
printf("%s: bad port number-- %s\n", argv[1], argv[2]);
|
port = sp->s_port;
|
||||||
printf ("usage: %s host-name [port]\n", argv[0]);
|
} else {
|
||||||
code = -1;
|
char *ep;
|
||||||
return;
|
|
||||||
|
port = strtol(argv[2], &ep, 0);
|
||||||
|
if (argv[2] == ep) {
|
||||||
|
printf("%s: bad port number-- %s\n",
|
||||||
|
argv[1], argv[2]);
|
||||||
|
printf ("usage: %s host-name [port]\n",
|
||||||
|
argv[0]);
|
||||||
|
code = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
port = htons(port);
|
||||||
}
|
}
|
||||||
port = htons(port);
|
|
||||||
}
|
}
|
||||||
host = hookup(argv[1], port);
|
host = hookup(argv[1], port);
|
||||||
if (host) {
|
if (host) {
|
||||||
|
Reference in New Issue
Block a user