vcc.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* vcc/vcc.c
  2. *
  3. * This file is part of vcc.
  4. *
  5. * vcc is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * vcc is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with vcc. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <unistd.h>
  21. #include <fcntl.h>
  22. #include <errno.h>
  23. #include <string.h>
  24. #include <sys/stat.h>
  25. #include <sys/types.h>
  26. #include <sys/socket.h>
  27. #include <netinet/in.h>
  28. #include <arpa/inet.h>
  29. #include <poll.h>
  30. #include <signal.h>
  31. #include <vcc/vcc.h>
  32. #include <vcc/version.h>
  33. extern int fd;
  34. int send_msg(const char *msg, const char *usrname) {
  35. struct vcc_request req;
  36. req.magic = htonl(VCC_MAGIC);
  37. req.reqtype = htonl(REQ_MSG_SEND);
  38. req.uid = 0;
  39. strcpy(req.usrname, usrname);
  40. strcpy(req.msg, msg);
  41. write(fd, &req, REQ_SIZE);
  42. return 0;
  43. }
  44. int read_msg(struct vcc_request *buf) {
  45. return read(fd, buf, REQ_SIZE);
  46. }
  47. int get_users(void) {
  48. struct vcc_request req;
  49. req.magic = htonl(VCC_MAGIC);
  50. req.reqtype = htonl(REQ_CTL_USRS);
  51. req.uid = 0;
  52. write(fd, &req, REQ_SIZE);
  53. /* read in another task */
  54. return 0;
  55. }