jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.5KB

  1. /*
  2. Copyright (C) 2016-2019 Christoph Kuhr
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #include "mrp_client_control_socket.h"
  16. static int control_socket = -1;
  17. int mrp_client_get_Control_socket()
  18. {
  19. return control_socket;
  20. }
  21. int mrp_client_init_Control_socket( FILE* filepointer )
  22. {
  23. // in POSIX fd 0,1,2 are reserved
  24. // if (2 > (*avb_ctx)->mrp_ctx.control_socket) {
  25. // if (-1 > (*avb_ctx)->mrp_ctx.control_socket)
  26. // close((*avb_ctx)->mrp_ctx.control_socket);
  27. // return RETURN_VALUE_FAILURE;
  28. // }
  29. struct sockaddr_in addr;
  30. int sockopt=0;
  31. fprintf(filepointer, "Create MRP control socket.\n");fflush(filepointer);
  32. memset((char*)&addr, 0, sizeof(struct sockaddr_in));
  33. addr.sin_family = AF_INET;
  34. // Listener... why 0?
  35. addr.sin_port = htons(0);
  36. // addr.sin_port = htons(MRPD_PORT_DEFAULT);
  37. inet_aton("127.0.0.1", &addr.sin_addr);
  38. if( (control_socket = socket(addr.sin_family, SOCK_DGRAM, IPPROTO_UDP)) < 0 ){
  39. fprintf(filepointer, "Failed to create socket. %d %s\n", errno, strerror(errno));fflush(filepointer);
  40. fclose(filepointer);
  41. return RETURN_VALUE_FAILURE;
  42. }
  43. // Allow the socket to be reused - incase connection is closed prematurely
  44. if (setsockopt(control_socket, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof( sockopt)) == -1) {
  45. fprintf(filepointer, "setsockopt failed %d %s\n", errno, strerror(errno));fflush(filepointer);
  46. close(control_socket);
  47. fclose(filepointer);
  48. return RETURN_VALUE_FAILURE;
  49. }
  50. if( bind(control_socket, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
  51. fprintf(filepointer, "Could not bind socket. %d %s\n", errno, strerror(errno));fflush(filepointer);
  52. close(control_socket);
  53. fclose(filepointer);
  54. return RETURN_VALUE_FAILURE;
  55. } else {
  56. return RETURN_VALUE_SUCCESS;
  57. }
  58. }