BSD 4_3_Reno release
[unix-history] / usr / src / usr.sbin / lpr / common_source / common.c
index 620992b..a11510c 100644 (file)
@@ -1,12 +1,25 @@
 /*
  * Copyright (c) 1983 Regents of the University of California.
 /*
  * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted provided
+ * that: (1) source distributions retain this entire copyright notice and
+ * comment, and (2) distributions including binaries display the following
+ * acknowledgement:  ``This product includes software developed by the
+ * University of California, Berkeley and its contributors'' in the
+ * documentation or other materials provided with the distribution and in
+ * all advertising materials mentioning features or use of this software.
+ * Neither the name of the University nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)common.c   5.2 (Berkeley) %G%";
-#endif not lint
+static char sccsid[] = "@(#)common.c   5.6 (Berkeley) 6/1/90";
+#endif /* not lint */
 
 /*
  * Routines and data common to all the line printer functions.
 
 /*
  * Routines and data common to all the line printer functions.
@@ -61,6 +74,7 @@ char  *name;          /* program name */
 char   *printer;       /* printer name */
 char   host[32];       /* host machine name */
 char   *from = host;   /* client's machine name */
 char   *printer;       /* printer name */
 char   host[32];       /* host machine name */
 char   *from = host;   /* client's machine name */
+int    sendtorem;      /* are we sending to a remote? */
 
 /*
  * Create a connection to the remote printer server.
 
 /*
  * Create a connection to the remote printer server.
@@ -98,7 +112,7 @@ retry:
        s = rresvport(&lport);
        if (s < 0)
                return(-1);
        s = rresvport(&lport);
        if (s < 0)
                return(-1);
-       if (connect(s, (caddr_t)&sin, sizeof(sin), 0) < 0) {
+       if (connect(s, (caddr_t)&sin, sizeof(sin)) < 0) {
                err = errno;
                (void) close(s);
                errno = err;
                err = errno;
                (void) close(s);
                errno = err;
@@ -222,6 +236,49 @@ compar(p1, p2)
        return(0);
 }
 
        return(0);
 }
 
+/*
+ * Figure out whether the local machine is the same
+ * as the remote machine (RM) entry (if it exists).
+ */
+char *
+checkremote()
+{
+       char name[MAXHOSTNAMELEN];
+       register struct hostent *hp;
+       static char errbuf[128];
+
+       sendtorem = 0;  /* assume printer is local */
+       if (RM != (char *)NULL) {
+               /* get the official name of the local host */
+               gethostname(name, sizeof(name));
+               name[sizeof(name)-1] = '\0';
+               hp = gethostbyname(name);
+               if (hp == (struct hostent *) NULL) {
+                   (void) sprintf(errbuf,
+                       "unable to get official name for local machine %s",
+                       name);
+                   return errbuf;
+               } else (void) strcpy(name, hp->h_name);
+
+               /* get the official name of RM */
+               hp = gethostbyname(RM);
+               if (hp == (struct hostent *) NULL) {
+                   (void) sprintf(errbuf,
+                       "unable to get official name for remote machine %s",
+                       RM);
+                   return errbuf;
+               }
+
+               /*
+                * if the two hosts are not the same,
+                * then the printer must be remote.
+                */
+               if (strcmp(name, hp->h_name) != 0)
+                       sendtorem = 1;
+       }
+       return (char *)0;
+}
+
 /*VARARGS1*/
 fatal(msg, a1, a2, a3)
        char *msg;
 /*VARARGS1*/
 fatal(msg, a1, a2, a3)
        char *msg;