Search code examples
c++httpprintingcups

How would I use CUPS to get the printers in my network in C++?


CUPS seems to now be requiring a http_t* http; variable in cupsGetDests(&dests); method and right now I don't know what to do since I haven't found any reference online yet.

I already did some search and got some code:

#include "assets/cups/cups.h"
#include <iostream>

void list_printers(){
    cups_dest_t* dests;
    int num_dests = cupsGetDests(&dests);
   
    for(int i=0; i<num_dests; i++){
        std::cout << dests[i].name << endl;
    }
}

But this code does not include the http variable in the cupsGetDests() method and I wasn't able to find any other code snippet featuring this. Thanks!


Solution

  • As explained in CUPS Programming Manual:

      int cupsGetDests2(http_t *http, cups_dest_t **dests);                        
                                                                                    
        Parameters                                                                  
                                                                                    
       http  Connection to server or CUPS_HTTP_DEFAULT                              
       dests Destinations                                                           
    

    You want to use the cupsGetDests2 function:

    auto n_dests=cupsGetDests2(CUPS_HTTP_DEFAULT, &dests);