struct sockaddr_in sin, from, local_laddr;
krb5_creds *get_cred, *ret_cred = 0;
char c;
- int lport = START_PORT;
+ int lport;
struct hostent *hp;
int rc;
char *host_save;
#endif /* POSIX_SIGNALS */
for (;;) {
- s = getport(&lport);
+ s = getport(0);
if (s < 0) {
if (errno == EAGAIN)
- fprintf(stderr, "socket: All ports in use\n");
+ fprintf(stderr, "socket: All ports in use\n");
else
- perror("kcmd: socket");
+ perror("kcmd: socket");
#ifdef POSIX_SIGNALS
sigprocmask(SIG_SETMASK, &oldmask, (sigset_t*)0);
#else
memcpy((caddr_t)&sin.sin_addr,hp->h_addr, sizeof(sin.sin_addr));
sin.sin_port = rport;
if (connect(s, (struct sockaddr *)&sin, sizeof (sin)) >= 0)
- break;
+ break;
(void) close(s);
- if (errno == EADDRINUSE) {
- lport--;
+ if (errno == EADDRINUSE)
continue;
- }
#if !(defined(tek) || defined(ultrix) || defined(sun) || defined(SYSV))
if (hp->h_addr_list[1] != NULL) {
krb5_free_creds(bsd_context, get_cred);
return (-1);
}
- lport--;
if (fd2p == 0) {
write(s, "", 1);
lport = 0;
{
struct sockaddr_in sin;
int s;
+ int len = sizeof(sin);
+ s = socket(AF_INET, SOCK_STREAM, 0);
+ if (s < 0)
+ return (-1);
+
memset((char *) &sin, 0,sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
- s = socket(AF_INET, SOCK_STREAM, 0);
- if (s < 0)
- return (-1);
- for (;;) {
- sin.sin_port = htons((u_short)*alport);
- if (bind(s, (struct sockaddr *)&sin, sizeof (sin)) >= 0)
- return (s);
- if (errno != EADDRINUSE) {
- (void) close(s);
- return (-1);
- }
- (*alport)--;
- if (*alport == IPPORT_RESERVED) {
- (void) close(s);
- errno = EAGAIN; /* close */
- return (-1);
+
+ if (bind(s, (struct sockaddr *)&sin, sizeof (sin)) >= 0) {
+ if (alport) {
+ if (getsockname(s, (struct sockaddr *)&sin, &len) < 0) {
+ (void) close(s);
+ return -1;
+ } else {
+ *alport = ntohs(sin.sin_port);
+ }
}
+ return s;
}
+
+ (void) close(s);
+ return -1;
}
argv++; argc--;
goto another;
}
-
if (argc > 0 && !strcmp(*argv, "-d")) {
argv++, argc--;
options |= SO_DEBUG;
sprintf (term + strlen (term), "%d", ospeed);
else {
(void) strcat(term, speeds[ospeed]);
-#if 0
- /* XXX - Not used, since the above code was
- * not ifdef'd and it relied on cfget... */
-
- /* some "posix" systems don't have cfget...
- * so used CBAUD if it's there */
- (void) strcat(term, speeds[ttyb.c_cflag & CBAUD]);
-#endif
}
}
#else
*/
writer()
{
- char c;
+ unsigned char c;
register n;
register bol = 1; /* beginning of line */
register local = 0;
#endif
mark = 0;
- recv(rem, &mark, 1, MSG_OOB);
+ recv(rem, &mark, 1, MSG_OOB);
if (mark & TIOCPKT_WINDOW) {
/*
* Let server know about window size changes
#endif
ppid = getppid();
-FD_ZERO(&readset);
+ FD_ZERO(&readset);
FD_ZERO(&excset);
FD_ZERO(&writeset);
#ifdef POSIX_SIGNALS
bufp = rcvbuf;
rcvcnt = 0;
- rcvstate = READING;
-FD_SET(rem,&readset);
+ rcvstate = READING;
+ FD_SET(rem,&readset);
FD_CLR(1,&writeset);
}
FD_SET(rem,&excset);
if (select(rem+1, &readset, &writeset, &excset, 0) > 0 ) {
if (FD_ISSET(rem, &excset))
- oob();
+ oob();
if (FD_ISSET(1,&writeset)) {
- n = write(1, bufp, remaining);
- if (n < 0) {
- if (errno != EINTR)
- return (-1);
- continue;
+ n = write(1, bufp, remaining);
+ if (n < 0) {
+ if (errno != EINTR)
+ return (-1);
+ continue;
+ }
+ bufp += n;
}
- bufp += n;
-}
-if (FD_ISSET(rem, &readset)) {
+ if (FD_ISSET(rem, &readset)) {
rcvcnt = des_read(rem, rcvbuf, sizeof (rcvbuf));
- if (rcvcnt == 0)
- return (0);
- if (rcvcnt < 0)
- goto error;
-}
+ if (rcvcnt == 0)
+ return (0);
+ if (rcvcnt < 0)
+ goto error;
+ }
} else
- error: {
+error:
+ {
if (errno == EINTR)
continue;
perror("read");
mode(f)
{
#ifdef POSIX_TERMIOS
- struct termios newtty;
+ struct termios newtty;
- switch(f) {
- case 0:
+ switch(f) {
+ case 0:
#ifdef TIOCGLTC
-#ifndef solaris20
- (void) ioctl(0, TIOCSLTC, (char *)&defltc);
+#if !defined(sun)
+ (void) ioctl(0, TIOCSLTC, (char *)&defltc);
#endif
#endif
- (void) tcsetattr(0, TCSADRAIN, &deftty);
- break;
- case 1:
- (void) tcgetattr(0, &newtty);
-/* was __svr4__ */
+ (void) tcsetattr(0, TCSADRAIN, &deftty);
+ break;
+ case 1:
+ (void) tcgetattr(0, &newtty);
+ /* was __svr4__ */
#ifdef VLNEXT
/* there's a POSIX way of doing this, but do we need it general? */
- newtty.c_cc[VLNEXT] = 0;
+ newtty.c_cc[VLNEXT] = 0;
#endif
- newtty.c_lflag &= ~(ICANON|ISIG|ECHO);
- if (!flow)
- {
- newtty.c_lflag &= ~(ICANON|ISIG|ECHO);
- newtty.c_iflag &= ~(BRKINT|INLCR|ICRNL|ISTRIP);
- /* newtty.c_iflag |= (IXON|IXANY); */
- newtty.c_iflag &= ~(IXON|IXANY);
- newtty.c_oflag &= ~(OPOST);
- } else {
- newtty.c_lflag &= ~(ICANON|ISIG|ECHO);
- newtty.c_iflag &= ~(INLCR|ICRNL);
- /* newtty.c_iflag |= (BRKINT|ISTRIP|IXON|IXANY); */
- newtty.c_iflag &= ~(IXON|IXANY);
- newtty.c_iflag |= (BRKINT|ISTRIP);
- newtty.c_oflag &= ~(ONLCR|ONOCR);
- newtty.c_oflag |= (OPOST);
- }
+ newtty.c_lflag &= ~(ICANON|ISIG|ECHO);
+ newtty.c_iflag &= ~(ISTRIP|INLCR|ICRNL);
+
+ if (!flow) {
+ newtty.c_iflag &= ~(BRKINT|IXON|IXANY);
+ newtty.c_oflag &= ~(OPOST);
+ } else {
+ /* XXX - should we set ixon ? */
+ newtty.c_iflag &= ~(IXON|IXANY);
+ newtty.c_iflag |= (BRKINT);
+ newtty.c_oflag &= ~(ONLCR|ONOCR);
+ newtty.c_oflag |= (OPOST);
+ }
#ifdef TABDLY
- /* preserve tab delays, but turn off XTABS */
- if ((newtty.c_oflag & TABDLY) == TAB3)
- newtty.c_oflag &= ~TABDLY;
+ /* preserve tab delays, but turn off XTABS */
+ if ((newtty.c_oflag & TABDLY) == TAB3)
+ newtty.c_oflag &= ~TABDLY;
#endif
+ if (!eight)
+ newtty.c_iflag |= ISTRIP;
+ if (litout)
+ newtty.c_oflag &= ~OPOST;
- if (litout)
- newtty.c_oflag &= ~OPOST;
-
- newtty.c_cc[VMIN] = 1;
- newtty.c_cc[VTIME] = 0;
- (void) tcsetattr(0, TCSADRAIN, &newtty);
+ newtty.c_cc[VMIN] = 1;
+ newtty.c_cc[VTIME] = 0;
+ (void) tcsetattr(0, TCSADRAIN, &newtty);
#ifdef TIOCGLTC
- /* Do this after the tcsetattr() in case this version
- * of termio supports the VSUSP or VDSUSP characters */
-#ifndef solaris20
- /* this forces ICRNL under Solaris... */
- (void) ioctl(0, TIOCSLTC, (char *)&noltc);
+ /* Do this after the tcsetattr() in case this version
+ * of termio supports the VSUSP or VDSUSP characters */
+#if !defined(sun)
+ /* this forces ICRNL under Solaris... */
+ (void) ioctl(0, TIOCSLTC, (char *)&noltc);
#endif
#endif
- break;
- default:
- return;
- /* NOTREACHED */
- }
+ break;
+ default:
+ return;
+ /* NOTREACHED */
+ }
#else
struct ltchars *ltc;
#ifdef USE_TERMIO
(void) ioctl(0, TIOCGETP, (char *)&sb);
switch (f) {
- case 0:
+ case 0:
#ifdef USE_TERMIO
/*
- ** remember whether IXON was set, so it can be restored
- ** when mode(1) is next done
- */
+ ** remember whether IXON was set, so it can be restored
+ ** when mode(1) is next done
+ */
(void) ioctl(fileno(stdin), TIOCGETP, &ixon_state);
/*
- ** copy the initial modes we saved into sb; this is
- ** for restoring to the initial state
- */
+ ** copy the initial modes we saved into sb; this is
+ ** for restoring to the initial state
+ */
(void)memcpy(&sb, &defmodes, sizeof(defmodes));
#else
ltc = &defltc;
break;
- case 1:
+ case 1:
#ifdef USE_TERMIO
/*
- ** turn off output mappings
- */
+ ** turn off output mappings
+ */
sb.c_oflag &= ~(ONLCR|OCRNL);
/*
- ** turn off canonical processing and character echo;
- ** also turn off signal checking -- ICANON might be
- ** enough to do this, but we're being careful
- */
+ ** turn off canonical processing and character echo;
+ ** also turn off signal checking -- ICANON might be
+ ** enough to do this, but we're being careful
+ */
sb.c_lflag &= ~(ECHO|ICANON|ISIG);
sb.c_cc[VTIME] = 1;
sb.c_cc[VMIN] = 1;
if (eight)
- sb.c_iflag &= ~(ISTRIP);
+ sb.c_iflag &= ~(ISTRIP);
#ifdef TABDLY
/* preserve tab delays, but turn off tab-to-space expansion */
if ((sb.c_oflag & TABDLY) == TAB3)
- sb.c_oflag &= ~TAB3;
+ sb.c_oflag &= ~TAB3;
#endif
/*
- ** restore current flow control state
- */
+ ** restore current flow control state
+ */
if ((ixon_state.c_iflag & IXON) && flow ) {
sb.c_iflag |= IXON;
} else {
sb.sg_flags |= (!flow ? RAW : CBREAK);
/* preserve tab delays, but turn off XTABS */
if ((sb.sg_flags & TBDELAY) == XTABS)
- sb.sg_flags &= ~TBDELAY;
+ sb.sg_flags &= ~TBDELAY;
sb.sg_kill = sb.sg_erase = -1;
#ifdef LLITOUT
if (litout)
- lflags |= LLITOUT;
+ lflags |= LLITOUT;
#endif
#ifdef LPASS8
if (eight)
- lflags |= LPASS8;
+ lflags |= LPASS8;
#endif /* LPASS8 */
tc = ¬c;
sb.sg_flags &= ~defflags;
ltc = &noltc;
break;
- default:
+ default:
return;
}
(void) ioctl(0, TIOCSLTC, (char *)ltc);