diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..92eaa83 --- /dev/null +++ b/Makefile @@ -0,0 +1,45 @@ +# $Id$ +# Application Makefile (C) 2002-2004 The UbixOS Project + +#Compiler +CC = gcc +CXX = g++ + +#Linker +LD = ld + +#Binary File Name +BINARY = rtmp + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = socket.o amf.o rtmp.o + +LIBRARIES = + +# Link The Binary +$(BINARY) : $(OBJS) + $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) + strip $(BINARY) + +# Compile the source files +.cc.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) diff --git a/amf.c b/amf.c new file mode 100644 index 0000000..49d382f --- /dev/null +++ b/amf.c @@ -0,0 +1,16 @@ +#include +#include + +#include "rtmp.h" + +int doAccept(int fd) { + char raw1[] = {0x02,0x00,0x00,0x00,0x00,0x00,0x04,0x05,0x00,0x00,0x00,0x00,0x07,0xeb,0x58,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x96,0x14,0x00,0x00,0x00,0x00,0x02,0x00,0x07,0x5f,0x72,0x65,0x73,0x75,0x6c,0x74,0x00,0x3f,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x03,0x00,0x04,0x63,0x6f,0x64,0x65,0x02,0x00,0x1d,0x4e,0x65,0x74,0x43,0x6f,0x6e,0x6e,0x65,0x63,0x74,0x69,0x6f,0x6e,0x2e,0x43,0x6f,0x6e,0x6e,0x65,0x63,0x74,0x2e,0x53,0x75,0x63,0x63,0x65,0x73,0x73,0x00,0x05,0x6c,0x65,0x76,0x65,0x6c,0x02,0x00,0x06,0x73,0x74,0x61,0x74,0x75,0x73,0x00,0x07,0x64,0x65,0x74,0x61,0x69,0x6c,0x73,0x05,0x00,0x0b,0x64,0x65,0x73,0x63,0x72,0x69,0x70,0x74,0x69,0x6f,0x6e,0x02,0x00,0x15,0x43,0x6f,0x6e,0x6e,0x65,0x63,0x74,0x69,0x6f,0x6e,0x20,0x73,0x75,0x63,0x63,0x65,0x65,0x64,0x65,0x64,0x2e,0x00,0x0e,0x6f,0x62,0x6a,0x65,0x02,0x00,0x00,0x00,0x00,0x00,0x05,0x06,0x00,0x00,0x00,0x00,0x00,0x03,0xd0,0x90,0x02,0xc3,0x63,0x74,0x45,0x6e,0x63,0x6f,0x64,0x69,0x6e,0x67,0x00,0x40,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09}; + int recLen = 0x0; + + recLen = send(fd,&raw1,sizeof(raw1),0); + if (recLen != sizeof(raw1)) + return(-1); + + return(0x0); + } + diff --git a/rtmp.c b/rtmp.c index 19e2074..b693fe6 100644 --- a/rtmp.c +++ b/rtmp.c @@ -2,20 +2,18 @@ RTMP Server */ +#include + +/* #include #include -#include #include #include -#include #include -#include -#include -#include -#include #include #include #include +*/ #include "rtmp.h" amfHeader_real *AMFS = 0x0; @@ -25,48 +23,11 @@ int sockFD = 0x0; //Listener Socket int newFD = 0x0; //New Socket; - struct sockaddr_in my_addr; // my address information - struct sockaddr_in their_addr; // connector's address information - socklen_t sin_size; - struct sigaction sa; int yes=1; + AMFS = (amfHeader_real *)malloc(sizeof(amfHeader_real) * 128); - if ((sockFD = socket(PF_INET, SOCK_STREAM, 0)) == -1) { - perror("socket"); - exit(1); - } - - if (setsockopt(sockFD, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) { - perror("setsockopt"); - exit(1); - } - - my_addr.sin_family = AF_INET; // host byte order - my_addr.sin_port = htons(MYPORT); // short, network byte order - my_addr.sin_addr.s_addr = INADDR_ANY; // automatically fill with my IP - memset(my_addr.sin_zero, '\0', sizeof my_addr.sin_zero); - - if (bind(sockFD, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) { - perror("bind"); - exit(1); - } - - if (listen(sockFD, BACKLOG) == -1) { - perror("listen"); - exit(1); - } -/* - sa.sa_handler = sigchld_handler; // reap all dead processes - sigemptyset(&sa.sa_mask); - sa.sa_flags = SA_RESTART; - if (sigaction(SIGCHLD, &sa, NULL) == -1) { - perror("sigaction"); - exit(1); - } -*/ - while(1) { // main accept() loop sin_size = sizeof(struct sockaddr_in); if ((newFD = accept(sockFD, (struct sockaddr *)&their_addr, &sin_size)) == -1) { @@ -357,16 +318,3 @@ return(0x0); } -int doAccept(int fd) { - char data[1024]; - char raw1[] = {0x02,0x00,0x00,0x00,0x00,0x00,0x04,0x05,0x00,0x00,0x00,0x00,0x07,0xeb,0x58,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x96,0x14,0x00,0x00,0x00,0x00,0x02,0x00,0x07,0x5f,0x72,0x65,0x73,0x75,0x6c,0x74,0x00,0x3f,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x03,0x00,0x04,0x63,0x6f,0x64,0x65,0x02,0x00,0x1d,0x4e,0x65,0x74,0x43,0x6f,0x6e,0x6e,0x65,0x63,0x74,0x69,0x6f,0x6e,0x2e,0x43,0x6f,0x6e,0x6e,0x65,0x63,0x74,0x2e,0x53,0x75,0x63,0x63,0x65,0x73,0x73,0x00,0x05,0x6c,0x65,0x76,0x65,0x6c,0x02,0x00,0x06,0x73,0x74,0x61,0x74,0x75,0x73,0x00,0x07,0x64,0x65,0x74,0x61,0x69,0x6c,0x73,0x05,0x00,0x0b,0x64,0x65,0x73,0x63,0x72,0x69,0x70,0x74,0x69,0x6f,0x6e,0x02,0x00,0x15,0x43,0x6f,0x6e,0x6e,0x65,0x63,0x74,0x69,0x6f,0x6e,0x20,0x73,0x75,0x63,0x63,0x65,0x65,0x64,0x65,0x64,0x2e,0x00,0x0e,0x6f,0x62,0x6a,0x65,0x02,0x00,0x00,0x00,0x00,0x00,0x05,0x06,0x00,0x00,0x00,0x00,0x00,0x03,0xd0,0x90,0x02,0xc3,0x63,0x74,0x45,0x6e,0x63,0x6f,0x64,0x69,0x6e,0x67,0x00,0x40,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09}; - int recLen = 0x0; - - // recLen = recv(fd,&data,1024,0); - // printf("reLen: [%i]\n",recLen); - recLen = send(fd,&raw1,sizeof(raw1),0); - printf("raw1: [%i:%i]\n",sizeof(raw1),recLen); - - return(0x0); - } - diff --git a/rtmp.h b/rtmp.h index 857f1c4..ae194df 100644 --- a/rtmp.h +++ b/rtmp.h @@ -19,3 +19,5 @@ char *body; } amfHeader_real; + +int doAccet(int); diff --git a/socket.c b/socket.c new file mode 100644 index 0000000..93673c1 --- /dev/null +++ b/socket.c @@ -0,0 +1,55 @@ +/* + RTMP - Socket Server + + $ID: $ + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "rtmp.h" + + +int sStartListener() { + int listenerFD = 0x0; + int optVal = 0x1; + + struct sockaddr_in myAddr; // my address information + struct sockaddr_in remoteAddr; // connector's address information + socklen_t sin_size; + + if ((listenerFD = socket(PF_INET, SOCK_STREAM, 0)) == -1) { + perror("socket"); + exit(1); + } + + if (setsockopt(listenerFD, SOL_SOCKET, SO_REUSEADDR, &optVal, sizeof(int)) == -1) { + perror("setsockopt"); + exit(1); + } + + + myAddr.sin_family = PF_INET; // host byte order + myAddr.sin_port = htons(MYPORT); // short, network byte order + myAddr.sin_addr.s_addr = INADDR_ANY; // automatically fill with my IP + memset(myAddr.sin_zero, '\0', sizeof myAddr.sin_zero); + + if (bind(listenerFD, (struct sockaddr *)&myAddr, sizeof(struct sockaddr)) == -1) { + perror("bind"); + exit(1); + } + + if (listen(listenerFD, BACKLOG) == -1) { + perror("listen"); + exit(1); + } + + + + return(0x0); + }