from carl again; third arg to connect was missing
[unix-history] / usr / src / lib / libcompat / 4.3 / rexec.c
index e402964..ae492b9 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)rexec.c    4.5 82/12/17";
+static char sccsid[] = "@(#)rexec.c    4.8 83/08/18";
 #endif
 
 #include <sys/types.h>
 #endif
 
 #include <sys/types.h>
@@ -36,7 +36,7 @@ rexec(ahost, rport, name, pass, cmd, fd2p)
        *ahost = hp->h_name;
        ruserpass(hp->h_name, &name, &pass);
 retry:
        *ahost = hp->h_name;
        ruserpass(hp->h_name, &name, &pass);
 retry:
-       s = socket(0, SOCK_STREAM, 0, 0);
+       s = socket(AF_INET, SOCK_STREAM, 0);
        if (s < 0) {
                perror("rexec: socket");
                return (-1);
        if (s < 0) {
                perror("rexec: socket");
                return (-1);
@@ -44,7 +44,7 @@ retry:
        sin.sin_family = hp->h_addrtype;
        sin.sin_port = rport;
        bcopy(hp->h_addr, (caddr_t)&sin.sin_addr, hp->h_length);
        sin.sin_family = hp->h_addrtype;
        sin.sin_port = rport;
        bcopy(hp->h_addr, (caddr_t)&sin.sin_addr, hp->h_length);
-       if (connect(s, &sin) < 0) {
+       if (connect(s, &sin, sizeof(sin)) < 0) {
                if (errno == ECONNREFUSED && timo <= 16) {
                        (void) close(s);
                        sleep(timo);
                if (errno == ECONNREFUSED && timo <= 16) {
                        (void) close(s);
                        sleep(timo);
@@ -59,15 +59,21 @@ retry:
                port = 0;
        } else {
                char num[8];
                port = 0;
        } else {
                char num[8];
-               int s2;
+               int s2, sin2len;
                
                
-               s2 = socket(0, SOCK_STREAM, 0, 0);
+               s2 = socket(AF_INET, SOCK_STREAM, 0);
                if (s2 < 0) {
                        (void) close(s);
                        return (-1);
                }
                listen(s2, 1);
                if (s2 < 0) {
                        (void) close(s);
                        return (-1);
                }
                listen(s2, 1);
-               socketaddr(s2, &sin2);
+               sin2len = sizeof (sin2);
+               if (getsockname(s2, (char *)&sin2, &sin2len) < 0 ||
+                 sin2len != sizeof (sin2)) {
+                       perror("getsockname");
+                       (void) close(s2);
+                       goto bad;
+               }
                port = ntohs((u_short)sin2.sin_port);
                (void) sprintf(num, "%d", port);
                (void) write(s, num, strlen(num)+1);
                port = ntohs((u_short)sin2.sin_port);
                (void) sprintf(num, "%d", port);
                (void) write(s, num, strlen(num)+1);