char * UDP_Socket::addToProgram() { char *tcp = " 2 "; char my_InetAddr[MAX_INET_ADDR]; char myPortNum[8]; char me[30]; unsigned int thePort = this->getPortNumber(); int start = 0; inttoa(thePort,myPortNum,&start); gethostname(me,MAX_INET_ADDR); GetHostAddr(me,my_InetAddr); char *newStuff =(char *)malloc(100*sizeof(char)); for (int i=0; i<100; i++) newStuff[i] = ' '; strcpy(newStuff,tcp); strcat(newStuff," "); strcat(newStuff,my_InetAddr); strcat(newStuff," "); strcat(newStuff,myPortNum); strcat(newStuff," "); return newStuff; }
void __cdecl SocketPosixC__ThisEnd(int fd, EndPoint* ep) { if (memcmp(ep, &NullAddress, sizeof(NullAddress)) == 0) { GetHostAddr(&ep->address); } if (ep->port == NullPort) { SockAddrIn name; socklen_t len = sizeof(name); ZERO_MEMORY(name); if (getsockname(fd, (struct sockaddr *)&name, &len) != 0) { IOError(Unexpected); return; } ep->port = ntohs(name.sin_port); } }
BOOL KDnsRecorder::RecordRecv( PROTO_TYPE pt, DWORD uLocalIp, USHORT uLocalPort, DWORD uRemoteIP, USHORT uRemotePort, PVOID pData, DWORD uDataLen ) { DNS_HEADER* pDns = NULL; string strHostName; list<DWORD> uAddrList; BOOL bResult = FALSE; DWORD nAnsPos = 0; DWORD nAnsCount = 0; do { if( uDataLen <= sizeof(DNS_HEADER) ) break; if( uRemotePort != 53 ) break; pDns = (DNS_HEADER*)pData; if( !IsValidResponse(pDns) ) break; if( m_sendDnsTansID.find( pDns->id ) == m_sendDnsTansID.end() ) break; m_sendDnsTansID.erase( pDns->id ); nAnsPos = GetHost( pData, uDataLen, strHostName ); if( nAnsPos == 0 || nAnsPos >= uDataLen ) break; nAnsCount = ntohs(pDns->ans_count); if( !GetHostAddr( pData, uDataLen, nAnsPos, nAnsCount, uAddrList ) ) break; m_hostIpList[strHostName] = uAddrList; //remove { struct sockaddr_in a; cout << strHostName <<endl; list<DWORD> &ipList = uAddrList; cout << "-------------------------------"<<endl; for( list<DWORD>::iterator ipItem = ipList.begin(); ipItem != ipList.end(); ipItem++ ) { a.sin_addr.s_addr=(*ipItem); //working without ntohl cout << "\t"<< inet_ntoa(a.sin_addr) << endl; } } bResult = TRUE; } while (FALSE); return bResult; }