SOCKET MyConnect( char *Host, int Port ) { LPHOSTENT lpHost = (LPHOSTENT)pgethostbyname( (const char*)Host ); if ( lpHost == NULL ) { return -1; } sockaddr_in SockAddr; SockAddr.sin_family = AF_INET; SockAddr.sin_addr.s_addr = **(unsigned long**)lpHost->h_addr_list; SockAddr.sin_port = (USHORT)phtons( (unsigned short)Port ); ConnectionData connData; connData.SockAddr = SockAddr; for(int i=0; i<3; i++) { SOCKET Socket = (SOCKET)psocket( AF_INET, SOCK_STREAM, 0 ); if( Socket == -1 ) return -1; connData.Socket = Socket; HANDLE ConnectThreadHandle = (HANDLE)pCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ConnectThread, &connData, NULL, 0); if((long)pWaitForSingleObject(ConnectThreadHandle, 10000) == WAIT_TIMEOUT) { if((int)pshutdown(Socket, 2) == SOCKET_ERROR) { } pTerminateThread(ConnectThreadHandle, 1); } DWORD exitCode = 0; BOOL res = (BOOL)pGetExitCodeThread(ConnectThreadHandle, &exitCode); //wsprintfA(&str[0], "EC:%d", exitCode); //OutputDebugStringA(&str[0]); if(res && exitCode == 0) return Socket; } return -1; }
/* Write a record for a packet to a dump file. * Returns TRUE on success, FALSE on failure. */ static gboolean eyesdn_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const guint8 *pd, int *err) { static const guint8 start_flag = 0xff; const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; guint8 buf[EYESDN_HDR_LENGTH]; int usecs; time_t secs; int channel; int origin; int protocol; int size; usecs=phdr->ts.nsecs/1000; secs=phdr->ts.secs; size=phdr->caplen; origin = pseudo_header->isdn.uton; channel = pseudo_header->isdn.channel; switch(phdr->pkt_encap) { case WTAP_ENCAP_ISDN: protocol=EYESDN_ENCAP_ISDN; /* set depending on decoder format and mode */ break; case WTAP_ENCAP_LAYER1_EVENT: protocol=EYESDN_ENCAP_MSG; break; case WTAP_ENCAP_DPNSS: protocol=EYESDN_ENCAP_DPNSS; break; #if 0 case WTAP_ENCAP_DASS2: protocol=EYESDN_ENCAP_DASS2; break; #endif case WTAP_ENCAP_ATM_PDUS_UNTRUNCATED: protocol=EYESDN_ENCAP_ATM; channel=0x80; break; case WTAP_ENCAP_LAPB: protocol=EYESDN_ENCAP_LAPB; break; case WTAP_ENCAP_MTP2_WITH_PHDR: protocol=EYESDN_ENCAP_MTP2; break; case WTAP_ENCAP_BACNET_MS_TP_WITH_PHDR: protocol=EYESDN_ENCAP_BACNET; break; case WTAP_ENCAP_V5_EF: protocol=EYESDN_ENCAP_V5_EF; break; default: *err=WTAP_ERR_UNSUPPORTED_ENCAP; return FALSE; } phton24(&buf[0], usecs); buf[3] = (guint8)0; buf[4] = (guint8)(0xff & (secs >> 24)); buf[5] = (guint8)(0xff & (secs >> 16)); buf[6] = (guint8)(0xff & (secs >> 8)); buf[7] = (guint8)(0xff & (secs >> 0)); buf[8] = (guint8) channel; buf[9] = (guint8) (origin?1:0) + (protocol << 1); phtons(&buf[10], size); /* start flag */ if (!wtap_dump_file_write(wdh, &start_flag, sizeof start_flag, err)) return FALSE; if (!esc_write(wdh, buf, 12, err)) return FALSE; if (!esc_write(wdh, pd, size, err)) return FALSE; return TRUE; }