test.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (C) 2001-2003 FhG Fokus
  3. *
  4. * This file is part of Kamailio, a free SIP server.
  5. *
  6. * Kamailio is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version
  10. *
  11. * Kamailio is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <sys/types.h>
  24. #include <sys/socket.h>
  25. #include <netinet/in.h>
  26. #include <errno.h>
  27. #include <arpa/inet.h>
  28. #define LOOP_COUNT 100
  29. #define PORT 5060
  30. #define SEND_PORT 5090
  31. #define SEND_ADDR 0x0a000022 /*10.0.0.34*/ /* 0x7f000001 127.0.0.1*/
  32. #define BUF_SIZE 65535
  33. static char buf[BUF_SIZE];
  34. int main(char** argv, int argn)
  35. {
  36. int sock;
  37. struct sockaddr_in addr;
  38. struct sockaddr_in to;
  39. int r, len;
  40. printf("starting\n");
  41. addr.sin_family=AF_INET;
  42. addr.sin_port=htons(PORT);
  43. addr.sin_addr.s_addr=INADDR_ANY;
  44. to.sin_family=AF_INET;
  45. to.sin_port=htons(SEND_PORT);
  46. to.sin_addr.s_addr=htonl(SEND_ADDR);
  47. sock=socket(PF_INET, SOCK_DGRAM,0);
  48. if (bind(sock, (struct sockaddr*) &addr, sizeof(struct sockaddr_in))==-1){
  49. fprintf(stderr, "ERROR: udp_init: bind: %s\n", strerror(errno));
  50. exit(1);
  51. }
  52. //if (fork())
  53. if (fork()){
  54. close(sock);
  55. for(;;) sleep(100);
  56. exit(1);
  57. }
  58. /*children*/
  59. printf("child\n");
  60. for(;;){
  61. len=read(sock, buf, BUF_SIZE);
  62. /*for (r=0;r < LOOP_COUNT; r++);*/
  63. /* send it back*/
  64. sendto(sock, buf, len, 0, (struct sockaddr*) &to,
  65. sizeof(struct sockaddr_in));
  66. }
  67. }