*
* File: main.c
* Author: root
*
* Created on May 17, 2011, 1:51 PM
*/
#include
#include
#include
#include
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "Include/lzo1z.h"
#define MAX_LEN 1024;
int main(int argc, char **argv)
{
int sock;
int flag_on = 1;
struct sockaddr_in mc_addr;
unsigned char recv_str[1024];
int recv_len;
struct ip_mreq mc_req;
char* mc_addr_str;
unsigned short mc_port;
struct sockaddr_in from_addr;
unsigned int from_len;
mc_addr_str = "233.1.1.11";
mc_port = 34330;
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
{
perror("socket() failed");
exit(1);
}
if ((setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &flag_on, sizeof(flag_on))) < 0)
{
perror("setsockopt() failed");
exit(1);
}
memset(&mc_addr,0,sizeof(mc_addr));
mc_addr.sin_family = AF_INET;
mc_addr.sin_addr.s_addr = htonl(INADDR_ANY);
mc_addr.sin_port = htons(mc_port);
if((bind(sock,(struct sockaddr *) &mc_addr,sizeof(mc_addr))) < 0)
{
perror("bind() failed");
exit(1);
}
mc_req.imr_multiaddr.s_addr = inet_addr(mc_addr_str);
mc_req.imr_interface.s_addr = htonl(INADDR_ANY);
if((setsockopt(sock,IPPROTO_IP,IP_ADD_MEMBERSHIP,(void*) &mc_req,sizeof(mc_req))) < 0)
{
perror("setsockopt() failed");
exit(1);
}
for(;;)
{
memset(recv_str,0,sizeof(recv_str));
from_len = sizeof(from_addr);
memset(&from_addr,0,from_len);
if((recv_len = recvfrom(sock, recv_str,1024,0,(struct sockaddr*)&mc_addr, &from_len))<0)
{
perror("recvfrom() failed");
exit(1);
}
short compLen=0;
short NOP=0;
memcpy(&compLen,recv_str+4,2);
compLen = ntohs(compLen);
if(compLen > 0)
{
memcpy(&NOP,recv_str+2,2);
NOP=ntohs(NOP);
int i=0;
for(i=0;i<nop;i++)>
{
unsigned char src[compLen];
memcpy(&src,recv_str+6,compLen);
short src_len = compLen;
unsigned int dst_len = 1024;
unsigned char dst[1024];
int rCode;
unsigned int eCode=0;
rCode = lzo1z_decompress((lzo_bytep) src,(lzo_uint)src_len,(lzo_bytep) dst,(lzo_uintp)&dst_len,0);
}
}
}
if((setsockopt(sock, IPPROTO_IP, IP_DROP_MEMBERSHIP,(void*)&mc_req, sizeof(mc_req))) < 0)
{
perror("setsocketopt() failed");
exit(1);
}
close(sock);
return 0;
}</unistd.h></string.h></stdlib.h></stdio.h>