/* Include the CUPS header files. */ #include int /* O - Exit status */ main(void) { http_t *http; /* HTTP object */ ipp_t *request; /* IPP request object */ ipp_t *response; /* IPP response object */ ipp_attribute_t *attr; /* Current IPP attribute */ /* Connect to the HTTP server */ http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption()); if (http == NULL) { perror("Unable to connect to server"); return (1); } /* Assemble the IPP request */ request = ippNew(); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes-charset", NULL, "utf-8"); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, "en"); request->request.op.operation_id = CUPS_GET_PRINTERS; request->request.any.request_id = 1; /* Send the request and get a response. */ response = cupsDoRequest(http, request, "/"); if (response != NULL) { for (attr = ippFindAttribute(response, "printer-name", IPP_TAG_NAME); attr != NULL; attr = ippFindNextAttribute(response, "printer-name", IPP_TAG_NAME)) puts(attr->values[0].string.text); ippDelete(response); } else printf("Unable to get printer list: %s\n", ippErrorString(cupsLastError())); /* Close the connection to the server. */ httpClose(http); return (0); }