00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
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
00072 if (fork()){
00073 close(sock);
00074 for(;;) sleep(100);
00075 exit(1);
00076 }
00077
00078 printf("child\n");
00079 for(;;){
00080 len=read(sock, buf, BUF_SIZE);
00081
00082
00083 sendto(sock, buf, len, 0, (struct sockaddr*) &to,
00084 sizeof(struct sockaddr_in));
00085 }
00086 }