test/test.c

00001 /* 
00002  * $Id$
00003  *
00004  *
00005  * Copyright (C) 2001-2003 FhG Fokus
00006  *
00007  * This file is part of ser, a free SIP server.
00008  *
00009  * ser is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version
00013  *
00014  * For a license to use the ser software under conditions
00015  * other than those described here, or to purchase support for this
00016  * software, please contact iptel.org by e-mail at the following addresses:
00017  *    info@iptel.org
00018  *
00019  * ser is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU General Public License 
00025  * along with this program; if not, write to the Free Software 
00026  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027  */
00028 
00029 
00030 
00031 #include <stdlib.h>
00032 #include <stdio.h>
00033 #include <string.h>
00034 #include <sys/types.h>
00035 #include <sys/socket.h>
00036 #include <netinet/in.h>
00037 #include <errno.h>
00038 #include <arpa/inet.h>
00039 
00040 
00041 #define LOOP_COUNT 100
00042 #define PORT 5060
00043 #define SEND_PORT 5090
00044 #define SEND_ADDR 0x0a000022 /*10.0.0.34*/   /*   0x7f000001 127.0.0.1*/
00045 #define BUF_SIZE 65535
00046 static char buf[BUF_SIZE];
00047 
00048 int main(char** argv, int argn)
00049 {
00050         int sock;
00051         struct sockaddr_in addr;
00052         struct sockaddr_in to;
00053         int r, len;
00054 
00055         printf("starting\n");
00056         
00057         addr.sin_family=AF_INET;
00058         addr.sin_port=htons(PORT);
00059         addr.sin_addr.s_addr=INADDR_ANY;
00060         to.sin_family=AF_INET;
00061         to.sin_port=htons(SEND_PORT);
00062         to.sin_addr.s_addr=htonl(SEND_ADDR);
00063                 
00064 
00065         sock=socket(PF_INET, SOCK_DGRAM,0);
00066         if (bind(sock, (struct sockaddr*) &addr, sizeof(struct sockaddr_in))==-1){
00067                 fprintf(stderr, "ERROR: udp_init: bind: %s\n", strerror(errno));
00068                 exit(1);
00069         }
00070 
00071         //if (fork())
00072                 if (fork()){
00073                         close(sock);
00074                         for(;;) sleep(100);
00075                         exit(1);
00076                 }
00077         /*children*/
00078         printf("child\n");
00079         for(;;){
00080                 len=read(sock, buf, BUF_SIZE);
00081                 /*for (r=0;r < LOOP_COUNT; r++);*/
00082                 /* send it back*/
00083                 sendto(sock, buf, len, 0, (struct sockaddr*) &to,
00084                                 sizeof(struct sockaddr_in));
00085         }
00086 }