sock_disc.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 Fhg Fokus
  5. *
  6. * This file is part of ser, a free SIP server.
  7. *
  8. * ser is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * For a license to use the ser software under conditions
  14. * other than those described here, or to purchase support for this
  15. * software, please contact iptel.org by e-mail at the following addresses:
  16. * [email protected]
  17. *
  18. * ser is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. */
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include <sys/types.h>
  31. #include <sys/socket.h>
  32. #include <netinet/in.h>
  33. #include <errno.h>
  34. #include <arpa/inet.h>
  35. /* results:
  36. real 0m23.332s
  37. user 0m0.410s
  38. sys 0m15.710s
  39. */
  40. /* which socket to use? main socket or new one? */
  41. int udp_send()
  42. {
  43. register int i;
  44. int n;
  45. char buffer;
  46. int sock;
  47. struct sockaddr_in addr;
  48. if ((sock=socket(PF_INET, SOCK_DGRAM, 0))<0) {
  49. fprintf( stderr, "socket error\n");
  50. exit(1);
  51. }
  52. memset( &addr, 0, sizeof(struct sockaddr_in));
  53. addr.sin_family=AF_INET;
  54. addr.sin_port=htons(9);
  55. addr.sin_addr.s_addr= inet_addr("127.0.0.1");
  56. for (i=0; i<1024*1024*16; i++)
  57. sendto(sock, &buffer, 1, 0, (struct sockaddr *) &addr, sizeof(addr));
  58. }
  59. main() {
  60. udp_send();
  61. }