Changeset 500

Show
Ignore:
Timestamp:
04/08/06 20:57:15 (3 years ago)
Author:
common
Message:

Nepenthes
- SocketManager? remove RAWSocket support, drop the select() loop,
- RAWSocket remove the rawsocket itself
- x-7 remove the rawsocket example module

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nepenthes/trunk/configure.ac

    r498 r500  
    890890                 modules/x-5/Makefile                  
    891891                 modules/x-6/Makefile 
    892                  modules/x-7/Makefile 
    893892                 modules/x-8/Makefile 
    894893                 modules/geolocation-hostip/Makefile 
  • nepenthes/trunk/modules/Makefile.am

    r420 r500  
    1515          geolocation-hostip geolocation-geoip geolocation-ip2location \ 
    1616          dnsresolve-adns \ 
    17           x-1 x-2 x-3 x-4 x-5 x-6 x-7 x-8 \ 
     17          x-1 x-2 x-3 x-4 x-5 x-6 x-8 \ 
    1818          log-surfnet vuln-ftpd \ 
    1919          log-prelude shellcode-signatures 
  • nepenthes/trunk/modules/download-http/HTTPDialogue.cpp

    r339 r500  
    181181        { 
    182182                end += 2; 
     183                int headersize = end-start; 
    183184                logSpam("FOUND HEADER (size %i)\n",end-start); 
    184185                logSpam("%.*s",end-start,start); 
    185186// FIXME PARSE HEADER 
    186 //              HTTPHeader *header = new HTTPHeader(start,(uint32_t)(end-start)); 
    187 //              m_HTTPHeader = header; 
     187                string httpheader(start,headersize); 
     188 
     189                int contentoffsetstart=0; 
     190                int contentoffsetstopp=0; 
     191                if ( (contentoffsetstart = httpheader.find("Content-Length:",0)) != -1) 
     192                { 
     193                        logInfo("FOund Content-Length on offset %i\n",contentoffsetstart); 
     194                        if ((contentoffsetstopp = httpheader.find("\r\n",contentoffsetstart)) != -1) 
     195                        { 
     196                                logInfo("FOund Content-Length End on offset %i\n",contentoffsetstopp); 
     197                                string contentline = httpheader.substr(contentoffsetstart + strlen("Content-Length:") 
     198                                                                                                           ,contentoffsetstopp -  
     199                                                                                                           contentoffsetstart -  
     200                                                                                                           strlen("Content-Length:")); 
     201                                printf("Content-Size = \"%s\" '%i'\n",contentline.c_str(),atoi(contentline.c_str())); 
     202 
     203                                if (m_Download->getDownloadBuffer()->getSize() - ((end-start)+2) == 
     204                                        (uint32_t)atoi(contentline.c_str()) 
     205                                        ) 
     206                                { 
     207                                        logInfo("perfect day size %i matches\n",atoi(contentline.c_str())); 
     208                                }else 
     209                                { 
     210                                        printf("download size %i\n",m_Download->getDownloadBuffer()->getSize()); 
     211                                        printf("header size %i\n",((end-start)+2)); 
     212                                        printf("body size %i\n",atoi(contentline.c_str())); 
     213                                } 
     214                        } 
     215                } 
     216                 
    188217        } 
    189218        m_Download->getDownloadBuffer()->cutFront((uint32_t)(end-start)+2); 
  • nepenthes/trunk/modules/log-irc/log-irc.cpp

    r378 r500  
    279279 
    280280        logSpam("LogIrc DNS %s has no ip, resolve error\n", result->getDNS().c_str()); 
    281 /*      char *reply; 
    282         asprintf(&reply,"DNS '%s' could not resolve\n", result->getDNS().c_str()); 
    283         m_Socket->doRespond(reply,strlen(reply)); 
    284         free(reply); 
    285 */       
     281 
    286282        return true; 
    287283} 
  • nepenthes/trunk/modules/shellcode-generic/shellcode-generic.cpp

    r459 r500  
    8383 
    8484//      m_ShellcodeHandlers.push_back(new GenericXOR(m_Nepenthes->getShellcodeMgr())); 
    85       m_ShellcodeHandlers.push_back(new GenericCreateProcess(m_Nepenthes->getShellcodeMgr())); 
     85//    m_ShellcodeHandlers.push_back(new GenericCreateProcess(m_Nepenthes->getShellcodeMgr())); 
    8686//      m_ShellcodeHandlers.push_back(new GenericUrl(m_Nepenthes->getShellcodeMgr())); 
    8787//      m_ShellcodeHandlers.push_back(new LinkXOR(m_Nepenthes->getShellcodeMgr())); 
  • nepenthes/trunk/nepenthes-core/include/Makefile.am

    r332 r500  
    1818EXTRA_DIST += ModuleManager.hpp Module.hpp   
    1919EXTRA_DIST += Manager.hpp Nepenthes.hpp 
    20 EXTRA_DIST += SocketManager.hpp Socket.hpp TCPSocket.hpp UDPSocket.hpp POLLSocket.hpp RAWSocket.hpp Responder.hpp  UDSSocket.hpp FILESocket.hpp 
     20EXTRA_DIST += SocketManager.hpp Socket.hpp TCPSocket.hpp UDPSocket.hpp POLLSocket.hpp Responder.hpp  UDSSocket.hpp FILESocket.hpp 
    2121EXTRA_DIST += ShellcodeManager.hpp ShellcodeHandler.hpp  
    2222EXTRA_DIST += Packet.hpp 
  • nepenthes/trunk/nepenthes-core/include/SocketManager.hpp

    r341 r500  
    6767                virtual Socket *connectTCPHost(uint32_t localHost, uint32_t remotehost, uint16_t localport, uint16_t remoteport,time_t connecttimeout); 
    6868 
    69                 virtual Socket *createRAWSocketUDP(uint16_t localport, uint16_t remoteport,time_t bindtimeout,time_t accepttimeout, DialogueFactory *diaf); 
    70                 virtual Socket *createRAWSocketTCP(uint16_t localport, uint16_t remoteport,time_t bindtimeout,time_t accepttimeout, DialogueFactory *diaf); 
    71  
    7269                virtual Socket *addPOLLSocket(POLLSocket *sock); 
    7370 
  • nepenthes/trunk/nepenthes-core/src/Makefile.am

    r341 r500  
    2323nepenthes_SOURCES += Nepenthes.cpp Manager.cpp 
    2424nepenthes_SOURCES += Packet.cpp 
    25 nepenthes_SOURCES += SocketManager.cpp Socket.cpp TCPSocket.cpp UDPSocket.cpp POLLSocket.cpp RAWSocket.cpp FILESocket.cpp 
     25nepenthes_SOURCES += SocketManager.cpp Socket.cpp TCPSocket.cpp UDPSocket.cpp POLLSocket.cpp FILESocket.cpp 
    2626nepenthes_SOURCES += Responder.cpp 
    2727nepenthes_SOURCES += ShellcodeManager.cpp ShellcodeHandler.cpp  
  • nepenthes/trunk/nepenthes-core/src/SocketManager.cpp

    r360 r500  
    5252#include "FILESocket.hpp" 
    5353#include "UDPSocket.hpp" 
    54 #include "RAWSocket.hpp" 
    5554#include "POLLSocket.hpp" 
    5655 
     
    114113bool  SocketManager::Init() 
    115114{ 
    116     try { 
    117         m_UseRawSockets = m_Nepenthes->getConfig()->getValInt("nepenthes.socketmanager.use_rawsockets"); 
    118         if (m_UseRawSockets) 
    119         { 
    120             logInfo("%s","Using Rawsockets\n"); 
    121         } 
    122     } catch ( ... ) { 
    123         logCrit("%s","Could not find nepenthes.socketmanager.use_rawsockets in config file, assuming no\n"); 
    124     } 
    125  
    126  
    127115        try { 
    128116                string bindAddressString = m_Nepenthes->getConfig()->getValString("nepenthes.socketmanager.bind_address"); 
     
    164152        } 
    165153 
    166  
    167 #ifdef WIN32 
    168         WORD wVersionRequested; 
    169         WSADATA wsaData; 
    170         int32_t err; 
    171   
    172         wVersionRequested = MAKEWORD( 2, 2 ); 
    173   
    174         err = WSAStartup( wVersionRequested, &wsaData ); 
    175         if ( err != 0 ) { 
    176                 /* Tell the user that we could not find a usable */ 
    177                 /* WinSock DLL.                                  */ 
    178                 logCrit("%s\n","Could not find good Windows Socket dll"); 
    179                 return false; 
    180         }else 
    181         { 
    182                 logDebug("%s\n","WSAStartup worked"); 
    183         } 
    184 #endif 
    185  
    186  
    187  
    188     if (m_UseRawSockets == true) 
    189     { 
    190 #ifdef WIN32 
    191         // win32 raw socket interface lookup & adding here 
    192         SOCKET sd = WSASocket(AF_INET, SOCK_DGRAM, 0, 0, 0, 0); 
    193         if (sd == SOCKET_ERROR) 
    194         { 
    195             logCrit("Failed to get a socket. Error %i\n", WSAGetLastError()); 
    196             return false; 
    197         } 
    198  
    199         INTERFACE_INFO InterfaceList[20]; 
    200         uint32_t nBytesReturned; 
    201         if (WSAIoctl(sd, SIO_GET_INTERFACE_LIST, 0, 0, &InterfaceList, 
    202                      sizeof(InterfaceList), &nBytesReturned, 0, 0) == SOCKET_ERROR) 
    203         { 
    204             logCrit("Failed calling WSAIoctl: error %i\n",WSAGetLastError()); 
    205             return false; 
    206         } 
    207  
    208         int32_t nNumInterfaces = nBytesReturned / sizeof(INTERFACE_INFO); 
    209         logDebug("There are %i interfaces \n",nNumInterfaces); 
    210         int32_t i; 
    211         for (i = 0; i < nNumInterfaces; ++i) 
    212         { 
    213             logDebug("Interface %i \n", i); 
    214  
    215             u_long nFlags = InterfaceList[i].iiFlags; 
    216             if (nFlags & IFF_UP)  
    217                 logDebug("Iface is %s\n","up"); 
    218             else                  
    219                 logDebug("Iface is %s\n","down"); 
    220  
    221  
    222  
    223             sockaddr_in *pAddress; 
    224             pAddress = (sockaddr_in *) & (InterfaceList[i].iiAddress); 
    225             logDebug("\tip %s\n",inet_ntoa(pAddress->sin_addr)); 
    226  
    227             pAddress = (sockaddr_in *) & (InterfaceList[i].iiBroadcastAddress); 
    228             logDebug("\tbcast %s\n",inet_ntoa(pAddress->sin_addr)); 
    229  
    230             pAddress = (sockaddr_in *) & (InterfaceList[i].iiNetmask); 
    231             logDebug("\tnetmask %s\n",inet_ntoa(pAddress->sin_addr)); 
    232  
    233             if (nFlags & IFF_POINTTOPOINT)  
    234                 logDebug("%s\n","\tis point-to-point"); 
    235             if (nFlags & IFF_LOOPBACK)      
    236                 logDebug("%s\n","\tis a loopback iface"); 
    237              
    238  
    239             string features = ""; 
    240              
    241             if (nFlags & IFF_BROADCAST)  
    242                 features += "bcast "; 
    243             if (nFlags & IFF_MULTICAST) 
    244                 features +=  "multicast "; 
    245             logDebug("\tFeatures: %s \n", features.c_str()); 
    246         } 
    247  
    248  
    249         for (i = 0; i < nNumInterfaces; ++i) 
    250         { 
    251  
    252             sockaddr_in *pAddress; 
    253             pAddress = (sockaddr_in *) & (InterfaceList[i].iiAddress); 
    254  
    255             RAWSocketListener *sock = new RAWSocketListener(m_Nepenthes,*(uint32_t *)&(pAddress->sin_addr)); 
    256             if ( sock->Init() == true ) 
    257             { 
    258                 m_Sockets.push_back(sock); 
    259             } else 
    260             { 
    261                 return false; 
    262             } 
    263  
    264         } 
    265 #else 
    266                 FILE *f = fopen(PROC_NET_DEV,"r"); 
    267                 if (f== NULL) 
    268                 { 
    269                         logCrit("Could not open %s \n",PROC_NET_DEV); 
    270                         return false; 
    271                 } 
    272                 char line[512]; 
    273                 memset(line,0,512); 
    274                 bool ifaceline=false; 
    275  
    276                 list <string> interfaces; 
    277  
    278                 while (fgets(line,512,f) != NULL) 
    279                 { 
    280                         if (ifaceline) 
    281                         { 
    282 //                              printf("proc line is '%s' \n",line); 
    283                                 char *ifacestopp=line; 
    284                                 char *ifacestart=line; 
    285                                 while(*ifacestopp != ':') 
    286                                         ifacestopp++; 
    287  
    288                                 while (*ifacestart == ' ') 
    289                                         ifacestart++; 
    290  
    291                                 logSpam("iface %.*s \n",ifacestopp-ifacestart,ifacestart); 
    292  
    293                 interfaces.push_back(string(ifacestart,ifacestopp-ifacestart)); 
    294  
    295                         }else 
    296                         if (strstr(line,"bytes") != NULL) 
    297                         { 
    298                                 ifaceline = true; 
    299                         } 
    300  
    301                          
    302  
    303                         memset(line,0,512); 
    304                 } 
    305         fclose(f); 
    306  
    307                 list<string>::iterator it; 
    308  
    309                 for (it=interfaces.begin();it!= interfaces.end();it++) 
    310                 { 
    311                         logDebug("Interface %s is availible for sniffing\n",it->c_str()); 
    312                 } 
    313  
    314                 for ( it=interfaces.begin();it!= interfaces.end();it++ ) 
    315                 { 
    316                         if (strstr(it->c_str(),"eth") == NULL) 
    317                         { 
    318                                 logDebug("No sniffing on %s\n",it->c_str()); 
    319                                 continue; 
    320                         } 
    321  
    322  
    323                         struct ifreq ifr; 
    324                         memset(&ifr,0,sizeof(struct ifreq)); 
    325 //                      struct ifconf ifc; 
    326  
    327                         uint32_t localip=0; 
    328                         int32_t fd = socket(AF_INET, SOCK_DGRAM, 0); 
    329                         if ( fd >= 0 ) 
    330                         { 
    331                                 strcpy(ifr.ifr_name, it->c_str()); 
    332                                 ifr.ifr_addr.sa_family = AF_INET; 
    333                                 if ( ioctl(fd, SIOCGIFADDR, &ifr) == 0 ) 
    334                                 { 
    335                                         struct sockaddr_in *ssin; 
    336                                         ssin = (struct sockaddr_in *) &ifr.ifr_addr; 
    337                                         logSpam("Interface %s has ip %s \n",it->c_str(),inet_ntoa(*(in_addr *)&ssin->sin_addr.s_addr)); 
    338  
    339                                         localip = ssin->sin_addr.s_addr; 
    340  
    341 /*                    logSpam("Interface %s has ip %s \n",it->c_str(),inet_ntoa(*(in_addr *)&ifr.ifr_addr)); 
    342                                         strcpy(ifr.ifr_name, it->c_str()); 
    343                                         if ( ioctl(fd, SIOCGIFDSTADDR, &ifr) >= 0 ) 
    344                                                 logSpam("Interface %s has ... %s \n",it->c_str(),inet_ntoa(*(in_addr *)&ifr.ifr_dstaddr)); 
    345  
    346                                         strcpy(ifr.ifr_name, it->c_str()); 
    347                                         if ( ioctl(fd, SIOCGIFBRDADDR, &ifr) >= 0 ) 
    348                                                 logSpam("Interface %s has ... %s \n",it->c_str(),inet_ntoa(*(in_addr *)&ifr.ifr_broadaddr)); 
    349  
    350                                         strcpy(ifr.ifr_name, it->c_str()); 
    351                                         if ( ioctl(fd, SIOCGIFNETMASK, &ifr) >= 0 ) 
    352                                                 logSpam("Interface %s has ... %s \n",it->c_str(),inet_ntoa(*(in_addr *)&ifr.ifr_netmask)); 
    353 */                                       
    354                                 }  
    355 //                              else 
    356 //                                      memset(&ife->addr, 0, sizeof(struct sockaddr)); 
    357                         } 
    358  
    359  
    360                         RAWSocketListener *sock; 
    361                         sock = new RAWSocketListener(m_Nepenthes,(char *)it->c_str(), localip, IPPROTO_TCP); 
    362                         if ( sock->Init() == true ) 
    363                         { 
    364                                 m_Sockets.push_back(sock); 
    365                         } else 
    366                         { 
    367                                 return false; 
    368                         } 
    369                          
    370 /*                      sock = new RAWSocketListener(m_Nepenthes,(char *)it->c_str(), IPPROTO_UDP); 
    371                         if ( sock->Init() == true ) 
    372                         { 
    373                                 m_Sockets.push_back(sock); 
    374                         } else 
    375                         { 
    376                                 return false; 
    377                         } 
    378 */                       
    379                 } 
    380                 interfaces.clear(); 
    381 #endif 
    382                  
    383         } 
    384154        return true; 
    385155} 
     
    406176 
    407177/** 
    408  * checks all sockets, and polls, handles the send and receive, socket timeouts, accepting new sockets, deleting dead sockets 
     178 * poll the sockets 
    409179 *  
    410180 * @param polltimeout 
    411  *               the polltimeout we want to use in milliseconds 
    412  *  
    413  * @return returns true if something was polled 
    414  *         else false 
     181 *               the polltimeout 
     182 *  
     183 * @return returns true 
    415184 */ 
    416 #ifdef WIN32 
    417         #error "i changed some stuff and found no reason to port it" 
    418         #error "to be precise, the setStatus thing for connected sockets" 
    419          
    420185bool SocketManager::doLoop(uint32_t polltimeout) 
    421 {// FIXME .. 
     186{ 
    422187        list <Socket *>::iterator itSocket; 
    423188 
     
    450215        } 
    451216 
    452         fd_set rfds; 
    453         fd_set wfds; 
    454  
    455         FD_ZERO(&rfds); 
    456         FD_ZERO(&wfds); 
    457  
    458  
     217        pollfd *polls = (pollfd *) malloc( (m_Sockets.size())* sizeof(pollfd)); 
     218        memset(polls,0,(m_Sockets.size())* sizeof(pollfd)); 
    459219        int32_t i=0; 
    460220        for (itSocket = m_Sockets.begin();itSocket != m_Sockets.end(); itSocket++) 
     
    477237                        { 
    478238                        case 0: // der socket is soweit okay 
    479 //                              logSpam("Socket %s is OK\n",(*itSocket)->getDescription().c_str()); 
    480                                 (*itSocket)->setPolled(); 
     239                        case EISCONN: 
     240                                if ((*itSocket)->getStatus() == SS_CONNECTING) 
     241                                { 
     242                                        (*itSocket)->setStatus(SS_CONNECTED); 
     243                                } 
     244                                (*itSocket)->setPolled();       // der socket ist am start 
    481245                                break; 
    482246 
    483                         case WSAEINPROGRESS: // der socket versuchts 
     247                        case EINPROGRESS: // der socket versuchts 
    484248                                (*itSocket)->unsetPolled(); 
    485249                                break; 
    486250 
    487                         case WSAEISCONN: 
    488                                 (*itSocket)->setPolled();       // der socket ist am start 
    489                                 break; 
    490  
    491251 
    492252                        default: 
     
    497257 
    498258        i=0; 
    499         int32_t maxsock=-1; 
    500259        for (itSocket = m_Sockets.begin();itSocket != m_Sockets.end(); itSocket++) 
    501         {        
     260        { 
     261                polls[i].events = 0; 
    502262                if ((*itSocket)->isPolled() == true ) 
    503263                { 
    504                         if ((*itSocket)->getSocket() > maxsock) 
    505                         { 
    506                                 maxsock = (*itSocket)->getSocket(); 
    507                         } 
    508  
    509                         FD_SET((*itSocket)->getSocket(),&rfds); 
     264                        polls[i].fd = (*itSocket)->getSocket(); 
     265                        polls[i].events = POLLIN; 
    510266 
    511267                        if ((*itSocket)->wantSend() == true) 
    512268                        { 
    513                                 FD_SET((*itSocket)->getSocket(),&wfds); 
    514                         }/*else 
    515                                 logSpam("polling %s readonly\n",(*itSocket)->getDescription().c_str());*/ 
     269                                polls[i].events |= POLLOUT; 
     270                        } 
    516271                        i++; 
    517272                } 
    518273        } 
    519274 
    520         struct timeval tv; 
    521         tv.tv_sec = 2; 
    522         tv.tv_usec = 500000; 
    523  
    524         int32_t iPollRet = select(maxsock,&rfds,&wfds,NULL,&tv); 
     275        int32_t iPollRet = poll(polls,i,50); 
    525276 
    526277        if (iPollRet != 0) 
     
    537288                                   ) 
    538289                                { 
    539                                         if ( FD_ISSET((*itSocket)->getSocket(),&rfds) ) 
     290                                        if ( iPollRet == 0 ) 
     291                                                continue; 
     292 
     293                                        if ( polls[i].revents & POLLIN && polls[i].events & POLLIN ) 
    540294                                        { 
    541295                                                (*itSocket)->doRecv(); 
     296                                                iPollRet--; 
    542297                                        } 
    543298                                } 
     
    552307                        if ( (*itSocket)->isPolled() == true ) 
    553308                        { 
    554 //                              logSpam(" COuld write #%i\n",1); 
    555                                 // doRecv() can close sockets 
    556                                 // we need a valid way to verify we dont try to send on a closed socket,  
    557                                 // i think wantSend() is a good option here 
    558                                 // getStatus i just a cheap fix 
    559 //                              logInfo("SSS %s \n",(*itSocket)->getDescription().c_str()); 
    560309                                if ( 
    561310                    ( (*itSocket)->getStatus() == SS_CONNECTED || (*itSocket)->getStatus() == SS_CLEANQUIT ) &&   
     
    569318                                   ) 
    570319                                { 
    571 //                                      if ( iPollRet == 0 ) 
    572 //                                              continue; 
    573 //                                      logSpam(" COuld write #%i\n",2); 
    574                                         if (FD_ISSET((*itSocket)->getSocket(),&wfds)) 
    575                                         { 
    576 //                                              logSpam(" COuld write #%i\n",3); 
    577                                                 (*itSocket)->doSend(); 
    578  
    579                                         } 
    580                                 } 
    581                                 i++; 
    582                         } 
    583                 } 
    584  
    585  
    586                 // accept new, non udp clients as udp does not accept() 
    587                 i=0; 
    588                 for (itSocket = m_Sockets.begin();itSocket != m_Sockets.end(); itSocket++) 
    589                 { 
    590                                  
    591  
    592                         if ( (*itSocket)->isPolled() == true ) 
    593                         { 
    594                                 if ( (*itSocket)->isBind() ) 
    595                                 { 
    596                                         if ( !((*itSocket)->getType() & ST_UDP) ) // bound udp sockets dont accept, they recvfrom 
    597                                         { 
    598                                                 if (FD_ISSET((*itSocket)->getSocket(),&rfds)) 
    599                                                 { 
    600                                                         logDebug("%s could Accept a Connection\n",(*itSocket)->getDescription().c_str()); 
    601                                                         Socket * socket = (*itSocket)->acceptConnection(); 
    602                                                         if ( socket == NULL ) 
    603                                                         { 
    604                                                                 logCrit("%s","Accept returned NULL ptr \n"); 
    605                                                         } else 
    606                                                         { 
    607                                                                 m_Sockets.push_back(socket); 
    608                                                                 logDebug("Accepted Connection %s \n%i Sockets in list\n",socket->getDescription().c_str(), m_Sockets.size()); 
    609                                                         } 
    610                                                 } 
    611                                         } 
    612                                 } 
    613                                 i++; 
    614                         } 
    615                 } 
    616         } 
    617 //      free(polls); 
    618 //      sleep(1); 
    619         return true; 
    620 } 
    621 #else 
    622  
    623 /** 
    624  * poll the sockets 
    625  *  
    626  * @param polltimeout 
    627  *               the polltimeout 
    628  *  
    629  * @return returns true 
    630  */ 
    631 bool SocketManager::doLoop(uint32_t polltimeout) 
    632 {// FIXME .. 
    633  
    634  
    635  
    636  
    637         list <Socket *>::iterator itSocket; 
    638  
    639 //      check socket timeouts and remove dead sockets 
    640         for (itSocket = m_Sockets.begin();itSocket != m_Sockets.end(); itSocket++) 
    641         { 
    642                 (*itSocket)->checkTimeout(); 
    643                 if ((*itSocket)->getStatus() == SS_TIMEOUT ) 
    644                 { 
    645                         logDebug("Deleting Socket %s due to timeout \n",(*itSocket)->getDescription().c_str()); 
    646                         Socket *delsocket = *itSocket; 
    647                         m_Sockets.erase(itSocket); 
    648                         delete delsocket; 
    649  
    650                         itSocket = m_Sockets.begin(); // FIXME ? 
    651                         if(m_Sockets.size() == 0) 
    652                 return false; 
    653                          
    654  
    655                 } 
    656  
    657                 if ( (*itSocket)->getStatus() == SS_CLOSED ) 
    658                 { 
    659                         logDebug("Deleting %s due to closed connection \n",(*itSocket)->getDescription().c_str()); 
    660                         Socket *delsocket = *itSocket; 
    661                         m_Sockets.erase(itSocket); 
    662                         delete delsocket; 
    663                         itSocket = m_Sockets.begin(); // FIXME ? 
    664                 } 
    665         } 
    666  
    667         pollfd *polls = (pollfd *) malloc( (m_Sockets.size())* sizeof(pollfd)); 
    668         memset(polls,0,(m_Sockets.size())* sizeof(pollfd)); 
    669         int32_t i=0; 
    670         for (itSocket = m_Sockets.begin();itSocket != m_Sockets.end(); itSocket++) 
    671         { 
    672                 int32_t iError = 0; 
    673                 int32_t iSize = sizeof(iError); 
    674                 if((*itSocket)->getType() & ST_FILE) 
    675                 { 
    676                         (*itSocket)->setPolled(); 
    677                 }else 
    678                 if ((*itSocket)->getsockOpt(SOL_SOCKET, SO_ERROR, &iError,(socklen_t *) &iSize) != 0 ) 
    679                 { 
    680                         // socket is dead 
    681                         logSpam("Socket %s is Dead\n",(*itSocket)->getDescription().c_str()); 
    682                         (*itSocket)->unsetPolled(); 
    683  
    684                 } else 
    685                 { 
    686                         switch (iError) 
    687                         { 
    688                         case 0: // der socket is soweit okay 
    689                         case EISCONN: 
    690 //                              logSpam("EISCONN State %i \n",(*itSocket)->getStatus()); 
    691                                 if ((*itSocket)->getStatus() == SS_CONNECTING) 
    692                                 { 
    693                                         (*itSocket)->setStatus(SS_CONNECTED); 
    694                                 } 
    695                                 (*itSocket)->setPolled();       // der socket ist am start 
    696                                 break; 
    697  
    698                         case EINPROGRESS: // der socket versuchts 
    699                                 (*itSocket)->unsetPolled(); 
    700                                 break; 
    701  
    702  
    703                         default: 
    704                                 (*itSocket)->unsetPolled();             // der is defekt 
    705                         } 
    706                 } 
    707         } 
    708  
    709         i=0; 
    710         for (itSocket = m_Sockets.begin();itSocket != m_Sockets.end(); itSocket++) 
    711         { 
    712                 polls[i].events = 0; 
    713                 if ((*itSocket)->isPolled() == true ) 
    714                 { 
    715                         polls[i].fd = (*itSocket)->getSocket(); 
    716  
    717                         polls[i].events = POLLIN; 
    718  
    719                          
    720  
    721                         if ((*itSocket)->wantSend() == true) 
    722                         { 
    723 //                              logSpam("polling %s read|write\n",(*itSocket)->getDescription().c_str()); 
    724                                          
    725                                 polls[i].events |= POLLOUT; 
    726                         }/*else 
    727                                 logSpam("polling %s readonly\n",(*itSocket)->getDescription().c_str());*/ 
    728                         i++; 
    729                 } 
    730         } 
    731  
    732         int32_t iPollRet = poll(polls,i,50); 
    733  
    734         if (iPollRet != 0) 
    735         { 
    736                 // read sockets 
    737                 i=0; 
    738                 for (itSocket = m_Sockets.begin();itSocket != m_Sockets.end(); itSocket++) 
    739                 { 
    740                         if ( (*itSocket)->isPolled() == true ) 
    741                         { 
    742                                 if (  
    743                                    ( (*itSocket)->isAccept()  || (*itSocket)->isConnect() ) || 
    744                                    (  (*itSocket)->isBind() && (*itSocket)->getType() & ST_UDP)   // bound udp sockets dont accept, they recvfrom 
    745                                    ) 
    746                                 { 
    747                                         if ( iPollRet == 0 ) 
    748                                                 continue; 
    749  
    750                                         if ( polls[i].revents & POLLIN && polls[i].events & POLLIN ) 
    751                                         { 
    752                                                 (*itSocket)->doRecv(); 
    753                                                 iPollRet--; 
    754                                         } 
    755                                 } 
    756                                 i++; 
    757                         } 
    758                 } 
    759  
    760                 // write sockets 
    761                 i=0; 
    762                 for (itSocket = m_Sockets.begin();itSocket != m_Sockets.end(); itSocket++) 
    763                 { 
    764                         if ( (*itSocket)->isPolled() == true ) 
    765                         { 
    766 //                              logSpam(" COuld write #%i\n",1); 
    767                                 // doRecv() can close sockets 
    768                                 // we need a valid way to verify we dont try to send on a closed socket,  
    769                                 // i think wantSend() is a good option here 
    770                                 // getStatus i just a cheap fix 
    771 //                              logDebug("SSS %s \n",(*itSocket)->getDescription().c_str()); 
    772                                 if ( 
    773                     ( (*itSocket)->getStatus() == SS_CONNECTED || (*itSocket)->getStatus() == SS_CLEANQUIT ) &&   
    774                                     ( 
    775                                      (*itSocket)->isAccept() || 
    776                                      (*itSocket)->isConnect() ||  
    777                                      ( 
    778                                       (*itSocket)->isBind() && (*itSocket)->getType() & ST_UDP 
    779                                      ) 
    780                                     )   
    781                                    ) 
    782                                 { 
    783 //                                      if ( iPollRet == 0 ) 
    784 //                                              continue; 
    785 //                                      logSpam(" COuld write #%i\n",2); 
    786320                                        if ( polls[i].revents & POLLOUT && polls[i].events & POLLOUT ) 
    787321                                        { 
    788 //                                              logSpam(" COuld write #%i\n",3); 
    789322                                                (*itSocket)->doSend(); 
    790323                                                iPollRet--; 
     
    832365        } 
    833366        free(polls); 
    834 //      sleep(1); 
    835367        return true; 
    836368} 
    837 #endif 
     369 
    838370 
    839371/** 
     
    1065597} 
    1066598 
    1067 Socket *SocketManager::createRAWSocketUDP(uint16_t localport, uint16_t remoteport, time_t bindtimeout,time_t accepttimeout, DialogueFactory *dialoguefactory) 
    1068 
    1069         logSpam("createRAWPSocketUDP %i %i %i %i \n",localport,remoteport,bindtimeout,accepttimeout); 
    1070         //RAWSocketListener *sock = NULL; 
    1071  
    1072         list <Socket *>::iterator socket; 
    1073         for(socket = m_Sockets.begin();socket != m_Sockets.end(); socket++) 
    1074         { 
    1075                 if((*socket)->getType() & ST_RAW ) 
    1076                 { 
    1077                         ((RAWSocketListener *)(*socket))->addListenFactory(localport,remoteport,IPPROTO_UDP,dialoguefactory); 
    1078 //                      return (*socket); 
    1079                 } 
    1080         } 
    1081         return NULL; 
    1082 
    1083  
    1084 /** 
    1085  *  
    1086  * @param localport 
    1087  * @param remoteport 
    1088  * @param bindtimeout 
    1089  * @param accepttimeout 
    1090  * @param dialoguefactory 
    1091  *  
    1092  * @return  
    1093  */ 
    1094 Socket *SocketManager::createRAWSocketTCP(uint16_t localport,uint16_t remoteport,time_t bindtimeout,time_t accepttimeout, DialogueFactory *dialoguefactory) 
    1095 
    1096         logSpam("createRAWPSocketTCP %i %i %i %i \n",localport,remoteport,bindtimeout,accepttimeout); 
    1097         //RAWSocketListener *sock = NULL; 
    1098  
    1099         list <Socket *>::iterator socket; 
    1100         for(socket = m_Sockets.begin();socket != m_Sockets.end(); socket++) 
    1101         { 
    1102                 if((*socket)->getType() & ST_RAW ) 
    1103                 { 
    1104         &nb