01-unpwd-set.c 565 B

1234567891011121314151617181920212223242526272829303132
  1. #include <stdbool.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <mosquitto.h>
  6. static int run = -1;
  7. int main(int argc, char *argv[])
  8. {
  9. int rc;
  10. struct mosquitto *mosq;
  11. int port = atoi(argv[1]);
  12. mosquitto_lib_init();
  13. mosq = mosquitto_new("01-unpwd-set", true, NULL);
  14. if(mosq == NULL){
  15. return 1;
  16. }
  17. mosquitto_username_pw_set(mosq, "uname", ";'[08gn=#");
  18. rc = mosquitto_connect(mosq, "localhost", port, 60);
  19. while(run == -1){
  20. mosquitto_loop(mosq, -1, 1);
  21. }
  22. mosquitto_destroy(mosq);
  23. mosquitto_lib_cleanup();
  24. return run;
  25. }