test.c 2.2 KB

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