changeset 9810:0bddf3c4f9fb

6821590 lpstat -lp output for remote printers is that of local printers
author Keerthi Kondaka <Keerthi.Kondaka@Sun.COM>
date Sun, 07 Jun 2009 23:28:14 -0700
parents decd140e1fad
children 32bf28cecf9f
files usr/src/cmd/print/bsd-sysv-commands/lpstat.c
diffstat 1 files changed, 44 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/print/bsd-sysv-commands/lpstat.c	Mon Jun 08 07:59:22 2009 +0800
+++ b/usr/src/cmd/print/bsd-sysv-commands/lpstat.c	Sun Jun 07 23:28:14 2009 -0700
@@ -330,6 +330,42 @@
 	return (0);
 }
 
+static int
+get_remote_hostname(papi_attribute_t **attrs, char **host)
+{
+	char *uri = NULL;
+	uri_t *u;
+	char *nodename;
+
+	*host = NULL;
+	(void) papiAttributeListGetString(attrs, NULL,
+	    "job-originating-host-name", host);
+	(void) papiAttributeListGetString(attrs, NULL,
+	    "printer-uri-supported", &uri);
+	if (*host == NULL) {
+		if (uri != NULL) {
+			if (uri_from_string(uri, &u) == 0) {
+				if (u->host == NULL) {
+					uri_free(u);
+					return (0);
+				}
+				*host = strdup(u->host);
+				uri_free(u);
+			} else {
+				return (0);
+			}
+		} else {
+			return (0);
+		}
+	}
+	nodename = localhostname();
+	if ((strcasecmp(*host, "localhost") == 0) ||
+	    (strcasecmp(*host, nodename) == 0)) {
+		return (0);
+	}
+	return (1);
+}
+
 static char *report_printer_keys[] = { "printer-name",
 			"printer-uri-supported", "printer-state",
 			"printer-up-time", "printer-state-time",
@@ -438,7 +474,15 @@
 	if (verbose == 1) {
 		void *iter;
 		char *str;
+		char *host = NULL;
 
+		if ((get_remote_hostname(attrs, &host)) != 0) {
+			(void) printf(
+			    gettext("\tRemote Name: %s\n\tRemote Server: "
+			    "%s\n"), name, host);
+			free(host);
+			return (0);
+		}
 		str = "";
 		(void) papiAttributeListGetString(attrs, NULL,
 		    "form-ready", &str);