sock_conn.c 1.7 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. /* results:
  29. real 0m23.332s
  30. user 0m0.410s
  31. sys 0m15.710s
  32. */
  33. /* which socket to use? main socket or new one? */
  34. int udp_send()
  35. {
  36. register int i;
  37. int n;
  38. char buffer;
  39. int sock;
  40. struct sockaddr_in addr;
  41. if ((sock=socket(PF_INET, SOCK_DGRAM, 0))<0) {
  42. fprintf( stderr, "socket error\n");
  43. exit(1);
  44. }
  45. memset( &addr, 0, sizeof(struct sockaddr_in));
  46. addr.sin_family=AF_INET;
  47. addr.sin_port=htons(9);
  48. addr.sin_addr.s_addr= inet_addr("127.0.0.1");
  49. if (connect(sock, (struct sockaddr *) &addr, sizeof(addr))==-1) {
  50. fprintf( stderr, "connect failed\n");
  51. exit(1);
  52. }
  53. for (i=0; i<1024*1024*16; i++)
  54. write( sock, &buffer, 1 );
  55. /* sendto(sock, &buffer, 1, 0, (struct sockaddr *) &addr, sizeof(addr)); */
  56. }
  57. main() {
  58. udp_send();
  59. }