Now works between SUNs and VAXen
authorKevin Layer <layer@ucbvax.Berkeley.EDU>
Sat, 12 May 1984 05:20:17 +0000 (21:20 -0800)
committerKevin Layer <layer@ucbvax.Berkeley.EDU>
Sat, 12 May 1984 05:20:17 +0000 (21:20 -0800)
SCCS-vsn: usr.bin/talk/look_up.c 1.3
SCCS-vsn: libexec/talkd/talkd.c 1.3

usr/src/libexec/talkd/talkd.c
usr/src/usr.bin/talk/look_up.c

index b1a3d6a..90dcd06 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)talkd.c    1.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)talkd.c    1.3 (Berkeley) %G%";
 #endif
 
 /*
 #endif
 
 /*
@@ -21,6 +21,7 @@ CTL_RESPONSE  response;
 
 int    sockt;
 int    debug = 0;
 
 int    sockt;
 int    debug = 0;
+FILE   *debugout;
 int    timeout();
 long   lastmsgtime;
 
 int    timeout();
 long   lastmsgtime;
 
@@ -35,6 +36,9 @@ main(argc, argv)
 {
        struct sockaddr_in from;
        int fromlen, cc;
 {
        struct sockaddr_in from;
        int fromlen, cc;
+       
+       if (debug)
+               debugout = (FILE *)fopen ("/usr/tmp/talkd.msgs", "w");
 
        if (getuid()) {
                fprintf(stderr, "Talkd : not super user\n");
 
        if (getuid()) {
                fprintf(stderr, "Talkd : not super user\n");
@@ -56,6 +60,8 @@ main(argc, argv)
                        continue;
                }
                lastmsgtime = time(0);
                        continue;
                }
                lastmsgtime = time(0);
+               swapmsg(&request);
+               if (debug) print_request(&request, fp);
                process_request(&request, &response);
                /* can block here, is this what I want? */
                cc = sendto(sockt, (char *) &response,
                process_request(&request, &response);
                /* can block here, is this what I want? */
                cc = sendto(sockt, (char *) &response,
@@ -64,6 +70,7 @@ main(argc, argv)
                if (cc != sizeof(response))
                        perror("sendto");
        }
                if (cc != sizeof(response))
                        perror("sendto");
        }
+       if (debug) close (debugout);
 }
 
 timeout()
 }
 
 timeout()
@@ -73,3 +80,22 @@ timeout()
                exit(0);
        alarm(TIMEOUT);
 }
                exit(0);
        alarm(TIMEOUT);
 }
+
+#define swapshort(a) (((a << 8) | ((unsigned short) a >> 8)) & 0xffff)
+#define swaplong(a) ((swapshort(a) << 16) | (swapshort(((unsigned)a >> 16))))
+
+/*  
+ * heuristic to detect if need to swap bytes
+ */
+
+swapmsg(req)
+       CTL_MSG *req;
+{
+       if (req->ctl_addr.sin_family == swapshort(AF_INET)) {
+               req->id_num = swaplong(req->id_num);
+               req->pid = swaplong(req->pid);
+               req->addr.sin_family = swapshort(req->addr.sin_family);
+               req->ctl_addr.sin_family =
+                       swapshort(req->ctl_addr.sin_family);
+       }
+}
index 17e9f14..4c0b43f 100644 (file)
@@ -1,9 +1,10 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)look_up.c  1.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)look_up.c  1.3 (Berkeley) %G%";
 #endif
 
 #include "talk_ctl.h"
 
 #endif
 
 #include "talk_ctl.h"
 
+
 /*
  * See if the local daemon has a invitation for us
  */
 /*
  * See if the local daemon has a invitation for us
  */
@@ -13,7 +14,8 @@ check_local()
 
        /* the rest of msg was set up in get_names */
        msg.ctl_addr = ctl_addr;
 
        /* the rest of msg was set up in get_names */
        msg.ctl_addr = ctl_addr;
-       if (!look_for_invite(&response))        /* must be initiating a talk */
+       /* must be initiating a talk */
+       if (!look_for_invite(&response))
                return (0);
        /*
         * There was an invitation waiting for us, 
                return (0);
        /*
         * There was an invitation waiting for us, 
@@ -21,6 +23,7 @@ check_local()
         */
        current_state = "Waiting to connect with caller";
 again:
         */
        current_state = "Waiting to connect with caller";
 again:
+       swapresponse(&response);
        if (connect(sockt, &response.addr, sizeof(response.addr)) != -1)
                return (1);
        if (errno == EINTR)
        if (connect(sockt, &response.addr, sizeof(response.addr)) != -1)
                return (1);
        if (errno == EINTR)
@@ -63,3 +66,70 @@ look_for_invite(response)
                return (0);
        }
 }
                return (0);
        }
 }
+
+/*  
+ * heuristic to detect if need to reshuffle CTL_RESPONSE structure
+ */
+
+#define swapshort(a) (((a << 8) | ((unsigned short) a >> 8)) & 0xffff)
+#define swaplong(a) ((swapshort(a) << 16) | (swapshort(((unsigned)a >> 16))))
+
+#ifdef sun
+struct ctl_response_vax {
+       char type;
+       char answer;
+       short junk;
+       int id_num;
+       struct sockaddr_in addr;
+};
+
+swapresponse(rsp)
+       CTL_RESPONSE *rsp;
+{
+       struct ctl_response_vax swaprsp;
+       
+       if (rsp->addr.sin_family != AF_INET) {
+               bcopy(rsp, &swaprsp, sizeof(CTL_RESPONSE));
+               swaprsp.addr.sin_family = swapshort(swaprsp.addr.sin_family);
+               if (swaprsp.addr.sin_family == AF_INET) {
+                       rsp->addr = swaprsp.addr;
+                       rsp->type = swaprsp.type;
+                       rsp->answer = swaprsp.answer;
+                       rsp->id_num = swaplong(swaprsp.id_num);
+               }
+       }
+}
+#endif
+
+#ifdef vax
+struct ctl_response_sun {
+       char type;
+       char answer;
+       unsigned short id_num2;
+       unsigned short id_num1;
+       short sin_family;
+       short sin_port;
+       short sin_addr2;
+       short sin_addr1;
+};
+
+swapresponse(rsp)
+       CTL_RESPONSE *rsp;
+{
+       struct ctl_response_sun swaprsp;
+       
+       if (rsp->addr.sin_family != AF_INET) {
+               bcopy(rsp, &swaprsp, sizeof(struct ctl_response_sun));
+               if (swaprsp.sin_family == swapshort(AF_INET)) {
+                       rsp->type = swaprsp.type;
+                       rsp->answer = swaprsp.answer;
+                       rsp->id_num = swapshort(swaprsp.id_num1)
+                           | (swapshort(swaprsp.id_num2) << 16);
+                       rsp->addr.sin_family = swapshort(swaprsp.sin_family);
+                       rsp->addr.sin_port = swaprsp.sin_port;
+                       rsp->addr.sin_addr.s_addr =
+                           swaprsp.sin_addr2 | (swaprsp.sin_addr1 << 16);
+               }
+       }
+}
+#endif