From 2c399a70be7632fcda97cdb1e91ad277c5190318 Mon Sep 17 00:00:00 2001
From: Erik Zandvliet <s.p.the.ghost@gmail.com>
Date: Fri, 3 Sep 2010 15:44:57 +0200
Subject: [PATCH] Client_Ip address fixage

---
 Connector_RTSP/main.cpp | 48 +++++++++++++++++++++++++++++++++++------
 1 file changed, 42 insertions(+), 6 deletions(-)

diff --git a/Connector_RTSP/main.cpp b/Connector_RTSP/main.cpp
index f81d8d1a..1cc618c7 100644
--- a/Connector_RTSP/main.cpp
+++ b/Connector_RTSP/main.cpp
@@ -33,6 +33,24 @@ timeval lastrec;
 #include "rtsp.cpp"
 #include "rtp.h"
 
+void parse_ip(char* ip_addr, uint8_t * uitvoer) {
+  int i = 0;
+  int j = 0;
+  int tempint = 0;
+  while( ip_addr[i] != '\0' ) {
+    if( ip_addr[i] != '.' ) {
+      tempint = tempint * 10;
+      tempint += ip_addr[i] - '0';
+    } else {
+      uitvoer[j] = tempint;
+      tempint = 0;
+      j++;
+    }
+    i++;
+  }
+  uitvoer[j] = tempint;
+}
+
 int main(){
   unsigned int ts;
   unsigned int fts = 0;
@@ -48,7 +66,7 @@ int main(){
   timeout.tv_sec = 1; timeout.tv_usec = 0;
   FD_ZERO(&pollset);//clear the polling set
   FD_SET(0, &pollset);//add stdin to polling set
-  
+
 
   DEBUG("Starting processing...\n");
   while (!feof(stdin) && !stopparsing){
@@ -70,9 +88,23 @@ int main(){
         transparams.SetPortbase(serverport);
         rtp_connection.Create(sessionparams,&transparams);
 
+  struct sockaddr_in i;
+  int len;
+  char * addr1;
+  len = sizeof(i);
+  if (getpeername( fileno(stdin), (sockaddr*)&i, (socklen_t*)&len ) == 0) {
+    addr1 = (char *) inet_ntoa(i.sin_addr);
+    DEBUG("%s\n", addr1 );
+  } else {
+    DEBUG("Blaah\n");
+  }
+
+  uint8_t clientip[4];
+  parse_ip(addr1,clientip);
+
         //TODO: clientip ophalen uit stdin-socket: zie http://www.mail-archive.com/plug@lists.q-linux.com/msg16482.html
-        uint8_t clientip[]={127,0,0,1};
         RTPIPv4Address addr(clientip,clientport);
+        DEBUG("RTP Connected\n");
 
         inited = true;
       }
@@ -100,18 +132,22 @@ int main(){
 
         if( FLVbuffer[0] != 0x12 ) {//Metadata direct filteren.
           if( FLVbuffer[0] == 0x08 ) { //Audio Packet
+            DEBUG("Audio Packet\n");
             rtp_connection.SetTimestampUnit(1.0/11025);//11025 samples/second
             // RTPSession::SendPacket( void * data   , length      , payload_type , marker , timestampincrement );
             //Audiodata heeft na de flv-tag nog 2 UI8 aan beschrijvingen die NIET bij de AAC-data horen
             //NOTE:Same als hieronder, wat moeten we doen met init-data van aac? die info wordt nu omitted.
-            rtp_connection.SendPacket( &FLVbuffer[13], FLV_len - 17, 99           , false  , 1                  );
+            rtp_connection.SendPacket( &FLVbuffer[13], FLV_len - 17, 99, false, 1);
           } else if ( FLVbuffer[0] == 0x09 ) { //Video Packet
+            DEBUG("Video Packet\n");
             rtp_connection.SetTimestampUnit(1.0/90000);//90000 samples/second
             //Videodata heeft na de flv-tag nog 2 UI8 en een SI24 aan beschrijvingen die niet bij de NALU horen
             //NOTE:Moeten we eigenlijk wat adobe genereert als sequence headers/endings ook gwoon doorsturen? gebeurt nu wel
-            rtp_connection.SendPacket( &FLVbuffer[16], FLV_len - 19, 98           , false  , 1                  );
-          }	  
-        }//Datatype 0x12 = metadata, zouden we voor nu weggooien
+            rtp_connection.SendPacket( &FLVbuffer[16], FLV_len - 19, 98, false, 1);
+          }
+        } else {//Datatype 0x12 = metadata, zouden we voor nu weggooien
+          DEBUG("Metadata, throwing away\n");
+        }
         FLV_Dump();//dump packet and get ready for next
       }
       if ((SWBerr != SWBaseSocket::ok) && (SWBerr != SWBaseSocket::notReady)){