int main() { int i, len, flag1, flag2, lena, lenb; getString(st); getString(a); getString(b); len = _strlen(st); lena = _strlen(a); lenb = _strlen(b); flag1 = calc(); for(i = 0; i < len / 2; i++) { int t = st[i]; st[i] = st[len - i - 1]; st[len - i - 1] = t; } flag2 = calc(); if(flag1 && flag2) { printf("both\n"); }else if(flag1) { printf("forward\n"); }else if(flag2) { printf("backward\n"); }else { printf("fantasy\n"); } }
bool str_equals(const char* x, const char* y) { uint32_t xlen = _strlen(x), ylen = _strlen(y); if (xlen != ylen) return false; for (; x[0] != '\0' && x[0] == y[0]; x++, y++); return x[0] == '\0'; }
uint8 *_strcat(const uint8 *src, const uint8 *s1) { uint32 len = _strlen(src) + _strlen(s1); uint8 *p; p = (uint8 *)malloc(len + 1); memcpy(p, src, _strlen(src)); _strcpy(p + _strlen(src), s1); return p; }
uint32_t ZipStream::r_addDirectory(const char* dir, const char* root) { uint32_t count = 0; DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp != NULL) { uint32_t dirsize = _strlen(dir); uint32_t rootsize = _strlen(root); uint32_t d_namlen; while (ep = readdir(dp)) { d_namlen = _strlen(ep->d_name); if ((d_namlen == 1 && ep->d_name[0] == '.') || (d_namlen == 2 && ep->d_name[0] == '.' && ep->d_name[1] == '.')) continue; if (dir[dirsize - 1] == '/') ((char*)dir)[--dirsize] = '\0'; uint32_t qualifiedSize = dirsize + d_namlen + 1 + 1; char* qualifiedName = new char[qualifiedSize]; memcpy(qualifiedName, dir, dirsize); qualifiedName[dirsize] = '/'; memcpy(qualifiedName + dirsize + 1, ep->d_name, d_namlen + 1); bool isdir, isreg; #ifndef _WIN32 struct stat stet; if (lstat(qualifiedName, &stet) == -1) continue; isdir = S_ISDIR(stet.st_mode); isreg = S_ISREG(stet.st_mode); #else isdir = ep->d_type == DT_DIR; isreg = ep->d_type == DT_REG; #endif if (isdir) count += r_addDirectory((const char*)qualifiedName, root); else if (isreg) { addFile(qualifiedName, qualifiedName + rootsize + 1); unflushed--; count++; } delete[] qualifiedName; } (void)closedir(dp); } return count; }
mountpoint_t *vfs_get_mountpoint(char *path) { mountpoint_t *tmp = mountlist; mountpoint_t *l = mountlist; while(l != NULL) { if( (_strncmp(l->path, path, _strlen(path)) == 0) && (_strlen(tmp->path) < _strlen(l->path))) tmp = l; l = l->next; } return tmp; }
/* * SfuQueryEnvironmentVariableOffset * * Purpose: * * Return offset to the given environment variable. * */ LPWSTR SfuQueryEnvironmentVariableOffset( PUNICODE_STRING Value ) { UNICODE_STRING str1; PWCHAR EnvironmentBlock, ptr; EnvironmentBlock = RtlGetCurrentPeb()->ProcessParameters->Environment; ptr = EnvironmentBlock; do { if (*ptr == 0) return 0; RtlSecureZeroMemory(&str1, sizeof(str1)); RtlInitUnicodeString(&str1, ptr); if (RtlPrefixUnicodeString(Value, &str1, TRUE)) break; ptr += _strlen(ptr) + 1; } while (1); return (ptr + Value->Length / sizeof(WCHAR)); }
UINT8 convert_time(UINT32 * ret, char * t) { if (!ret || !t) return RTX_ERROR; UINT8 len = _strlen(t); if (!len || len > TIME_FORMAT_SIZE) return RTX_ERROR; char str[3]; str[2] = '\0'; UINT8 count = 3; *ret = 0; SINT32 tmp_time = 0; do { str[0] = *t++; str[1] = *t++; if (!_atoi(&tmp_time, str)) return RTX_ERROR; switch(count--) { case 3: if (tmp_time>23 || tmp_time <0) return INVALID_HOUR; *ret += tmp_time*3600; break; case 2: if (tmp_time>59 || tmp_time <0) return INVALID_MINUTE; *ret += tmp_time*60; break; case 1: if (tmp_time>59 || tmp_time <0) return INVALID_SECOND; *ret += tmp_time; break; } }while (*t && *t++ == COLON); #ifdef _DEBUG_ dprintf("%s: *ret = %d \r\n", __func__, *ret); #endif return !count ? RTX_SUCCESS : RTX_ERROR; }
int main() { char s[100]; scanf("%s", s); printf("Laenge: %d\n", _strlen(s)); }
/* * supOpenDirectoryForObject * * Purpose: * * Open directory for given object, handle self case * */ HANDLE supOpenDirectoryForObject( _In_ LPWSTR lpObjectName, _In_ LPWSTR lpDirectory ) { HANDLE hDirectory; SIZE_T i, l, rdirLen, ldirSz; LPWSTR SingleDirName, LookupDirName; BOOL needFree = FALSE; if ( (lpObjectName == NULL) || (lpDirectory == NULL) ) { return NULL; } LookupDirName = lpDirectory; // // 1) Check if object is directory self // Extract directory name and compare (case insensitive) with object name // Else go to 3 // l = 0; rdirLen = _strlen(lpDirectory); for (i = 0; i < rdirLen; i++) { if (lpDirectory[i] == '\\') l = i + 1; } SingleDirName = &lpDirectory[l]; if (_strcmpi(SingleDirName, lpObjectName) == 0) { // // 2) If we are looking for directory, move search directory up // e.g. lpDirectory = \ObjectTypes, lpObjectName = ObjectTypes then lpDirectory = \ // ldirSz = rdirLen * sizeof(WCHAR) + sizeof(UNICODE_NULL); LookupDirName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ldirSz); if (LookupDirName == NULL) return NULL; needFree = TRUE; //special case for root if (l == 1) l++; supCopyMemory(LookupDirName, ldirSz, lpDirectory, (l - 1) * sizeof(WCHAR)); } // // 3) Open directory // hDirectory = supOpenDirectory(LookupDirName); if (needFree) { HeapFree(GetProcessHeap(), 0, LookupDirName); } return hDirectory; }
Tag::Tag (const _char *pName) : m_pName (pName), m_pTagAttrString (0), m_bEndTag (false), m_bSelfClosing (false) { m_pStrEnd = pName + _strlen (pName); }
/* * SdtSaveListToFile * * Purpose: * * Dump table to the selected file * */ VOID SdtSaveListToFile( _In_ HWND hwndDlg ) { WCHAR ch; INT BufferSize = 0; INT numitems; INT row, subitem; SIZE_T sz, k; LPWSTR pItem = NULL; HCURSOR hSaveCursor; HCURSOR hHourGlass; WCHAR szTempBuffer[MAX_PATH + 1]; RtlSecureZeroMemory(szTempBuffer, sizeof(szTempBuffer)); _strcpy(szTempBuffer, TEXT("list.txt")); if (supSaveDialogExecute(hwndDlg, (LPWSTR)&szTempBuffer, TEXT("Text files\0*.txt\0\0"))) { hHourGlass = LoadCursorW(NULL, IDC_WAIT); ch = (WCHAR)0xFEFF; supWriteBufferToFile(szTempBuffer, &ch, sizeof(WCHAR), FALSE, FALSE); SetCapture(hwndDlg); hSaveCursor = SetCursor(hHourGlass); numitems = ListView_GetItemCount(SdtDlgContext.ListView); for (row = 0; row < numitems; row++) { output[0] = 0; for (subitem = 0; subitem < SdtDlgContext.lvColumnCount; subitem++) { sz = 0; pItem = supGetItemText(SdtDlgContext.ListView, row, subitem, &sz); if (pItem) { _strcat(output, pItem); HeapFree(GetProcessHeap(), 0, pItem); } if (subitem == 1) { for (k = 54; k > sz / sizeof(WCHAR); k--) { _strcat(output, TEXT(" ")); } } else { _strcat(output, TEXT("\t")); } } _strcat(output, L"\r\n"); BufferSize = (INT)_strlen(output); supWriteBufferToFile(szTempBuffer, output, BufferSize * sizeof(WCHAR), FALSE, TRUE); } SetCursor(hSaveCursor); ReleaseCapture(); } }
int calc() { int len, lena, lenb, i, p, stamp, j; len = _strlen(st); next[0] = -1; lena = _strlen(a); lenb = _strlen(b); for(i = 1; i < lena; i++) { next[i] = next[i - 1]; while(next[i] != -1 && a[next[i] + 1] != a[i]) { next[i] = next[next[i]]; } next[i] += a[next[i] + 1] == a[i]; } p = 0; stamp = 0; for(i = 0; i < len; i++) { if(stamp == 0) { while(p != 0 && a[p] != st[i]) { p = next[p - 1] + 1; } p += a[p] == st[i]; if(p == lena) { next[0] = -1; for(j = 1; j < lenb; j++) { next[j] = next[j - 1]; while(next[j] != -1 && b[next[j] + 1] != b[j]) { next[j] = next[next[j]]; } next[j] += b[next[j] + 1] == b[j]; } p = 0; stamp = 1; } }else { while(p != 0 && b[p] != st[i]) { p = next[p - 1] + 1; } p += b[p] == st[i]; if(p == lenb) { return 1; } } } return 0; }
/* * supQueryTypeInfo * * Purpose: * * Query specific type info for output in listview. * */ BOOL supQueryTypeInfo( _In_ LPWSTR lpTypeName, _Inout_ LPWSTR Buffer, _In_ DWORD ccBuffer //size of buffer in chars ) { BOOL bResult = FALSE; ULONG i, nPool; POBJECT_TYPE_INFORMATION pObject; if ((g_pObjectTypesInfo == NULL) || (Buffer == NULL) ) { SetLastError(ERROR_INSUFFICIENT_BUFFER); return bResult; } if (ccBuffer < MAX_PATH) { SetLastError(ERROR_INSUFFICIENT_BUFFER); return bResult; } pObject = (POBJECT_TYPE_INFORMATION)&g_pObjectTypesInfo->TypeInformation; for (i = 0; i < g_pObjectTypesInfo->NumberOfTypes; i++) { /* Warning: Dxgk objects missing in this enum in Windows 10 TP WCHAR test[1000]; RtlSecureZeroMemory(&test, sizeof(test)); wsprintfW(test, L"\nLength=%lx, MaxLen=%lx \n", pObject->TypeName.Length, pObject->TypeName.MaximumLength); OutputDebugString(test); _strncpy(test, MAX_PATH, pObject->TypeName.Buffer, pObject->TypeName.MaximumLength); OutputDebugString(test);*/ if (_strncmpi(pObject->TypeName.Buffer, lpTypeName, pObject->TypeName.Length / sizeof(WCHAR)) == 0) { for (nPool = 0; nPool < MAX_KNOWN_POOL_TYPES; nPool++) { if ((POOL_TYPE)pObject->PoolType == (POOL_TYPE)a_PoolTypes[nPool].dwValue) { _strncpy( Buffer, ccBuffer, a_PoolTypes[nPool].lpDescription, _strlen(a_PoolTypes[nPool].lpDescription) ); break; } } bResult = TRUE; } if (bResult) { break; } //next entry located after the aligned type name buffer pObject = (POBJECT_TYPE_INFORMATION)((PCHAR)(pObject + 1) + ALIGN_UP(pObject->TypeName.MaximumLength, sizeof(ULONG_PTR))); } return bResult; }
Tag::Tag (_char *pTagString, bool bParseAttributes) : m_pName (0), m_pTagAttrString (0), m_bEndTag (false), m_bSelfClosing (false) { m_pStrEnd = pTagString + _strlen (pTagString); parseTag (pTagString, bParseAttributes); }
void initialize_modes(void){ char i; for (i=0;i<MAX_MODE_NUM;i++){ modes[i].label = (char *)MODE_LABELS[i]; modes[i].choice_label = (char *)CHOICE_LABELS[i]; modes[i].choice_pos = 0; } current_mode_pos = 0; alphabet_num = _strlen((char *)CHOICE_LABELS[0]) / 2; }
uint8 *_strdup(const uint8 *src) { uint32 len = _strlen(src); uint8 *p; p = (uint8 *)malloc(len + 1); _strcpy(p, src); return p; }
void ZipStream::addFile(char* localFileLocation, char* fileName) { LFH lfh; int32_t length = _strlen(localFileLocation); lfh.localFileLocation = new char[length + 1]; memcpy(lfh.localFileLocation, localFileLocation, length + 1); length = _strlen(fileName); lfh.fileName = new char[length + 1]; memcpy(lfh.fileName, fileName, length + 1); lfh.fileNameLength = length; FileNode *lastNode; for (lastNode = rootNode; lastNode->next != NULL; lastNode = lastNode->next); lastNode->next = new FileNode(lfh, NULL); fileCount++; unflushed++; }
/* * supFindModuleEntryByAddress * * Purpose: * * Find Module Name for given Address. * */ BOOL supFindModuleEntryByAddress( _In_ CONST PRTL_PROCESS_MODULES pModulesList, _In_ PVOID Address, _Inout_ LPWSTR Buffer, _In_ DWORD ccBuffer //size of buffer in chars ) { ULONG i, c; PRTL_PROCESS_MODULE_INFORMATION pModule; WCHAR szBuffer[MAX_PATH + 1]; if ( (Address == NULL) || (pModulesList == NULL) || (Buffer == NULL) || (ccBuffer == 0) ) { return FALSE; } c = pModulesList->NumberOfModules; if (c == 0) { return FALSE; } for (i = 0; i < c; i++) { if ( IN_REGION(Address, pModulesList->Modules[i].ImageBase, pModulesList->Modules[i].ImageSize) ) { pModule = &pModulesList->Modules[i]; RtlSecureZeroMemory(&szBuffer, sizeof(szBuffer)); if ( MultiByteToWideChar(CP_ACP, 0, (LPCSTR)&pModule->FullPathName[pModule->OffsetToFileName], sizeof(pModule->FullPathName), szBuffer, MAX_PATH) ) { _strncpy(Buffer, ccBuffer, szBuffer, _strlen(szBuffer)); return TRUE; } else { //MultiByteToWideChar error return FALSE; } } } return FALSE; }
struct vfs_node_p *vfs_open(char *path, char *flags) { mountpoint_t *mp = vfs_get_mountpoint(path); if(mp == NULL) return (struct vfs_node_p *) NULL; path += _strlen(mp->path); /* split the restant path, and get nodes */ char token[VFS_TOKEN_SIZE]; unsigned tok_len; struct vfs_node_p *tmp = mp->root; struct readdir_t rd; unsigned i; while(tmp != NULL) { /* get the token */ tok_len = 0; while((*path != '/') && (*path != 0)) { token[tok_len] = *path; path++; tok_len++; } token[tok_len] = 0; /* read the dir and find the correct token */ struct vfs_node_p *tmp2 = NULL; i = 0; while((tmp2 == NULL) && (tmp->readdir(tmp, &rd, i))) { if(_strcmp(tmp->name, token) == 0) { /* get the correct node */ tmp2 = tmp->get_node(tmp, i); if(tmp != mp->root) { mm_free(tmp); } tmp = tmp2; if(*(path-1) == 0) return tmp; } i++; } } return (struct vfs_node_p *) NULL; }
char *_strstr (const char *s1, const char *s2) { const char *p = s1; const int len = _strlen (s2); for (; (p = _strchr (p, *s2)) != 0; p++) { if (_strncmp (p, s2, len) == 0) return (char *)p; } return (0); }
int main(int argc, char* argv[]) { char str[] = "The quick brown fox jumps over the lazy dog"; char buf[256]; unsigned char out[20]; api_crypto.sha1((unsigned char *)str, _strlen(str), out); utl.snprintf_hex(buf, sizeof(buf), (const u8_t *)out, sizeof(out), 0x80|' '); LOG_INFO("sha1 result:\"%s\".\r\n", buf); return ADDON_LOADER_ABORT; //删除该addon (无需驻留) }
void doit(int index)//, CycList<zip*>* zipList) { char* qualifiedName = "C:/Users/Ahmad/Downloads/test"; m.lock(); CRC crclib; crclib.partialCompute((uint8_t *)qualifiedName, 0, _strlen(qualifiedName)); uint32_t crc = crclib.GetCRC32(); uint64_t zipCount = zipList.count; uint32_t i; for (i = 0; i < zipCount && zipList[i]->crc != crc; i++); zip* cur; if (i == zipCount) { cur = new zip(true); cur->crc = crc; if (zipList.count == ZIPLISTCAP) delete zipList[zipList.index + 1 % ZIPLISTCAP]; zipList.append(cur); cur->zs->addDirectory(qualifiedName); } else cur = zipList[i]; m.unlock(); std::ostringstream ss; ss << "c:/users/ahmad/desktop/custom/test" << index; std::ofstream outfile(ss.str(), std::ios::binary); cur->m.lock(); cur->zs->buildStream(); cur->m.unlock(); int64_t streamSize = cur->zs->getStreamSize(); uint64_t from = (streamSize / THREADCOUNT + 1) * index; uint64_t to = from + streamSize / THREADCOUNT; if (index == THREADCOUNT - 1) to = streamSize - 1; uint64_t targetLength; for (uint64_t i = from; i <= to; i += targetLength) { targetLength = MIN(10240, to - i + 1); cur->zs->printBytes(i, i + targetLength - 1, outfile.rdbuf()); } //cur->zs->printBytes(from, to, outfile.rdbuf()); outfile.close(); }
/* * PipeCreateFullName * * Purpose: * * Create complete pipe name. * Caller responsible for cleanup with HeapFree after use. * */ LPWSTR PipeCreateFullName( _In_ LPWSTR lpObjectName ) { LPWSTR lpFullName = NULL; SIZE_T sz; if (lpObjectName == NULL) { return NULL; } sz = (_strlen(T_DEVICE_NAMED_PIPE) + _strlen(lpObjectName)) * sizeof(WCHAR) + sizeof(UNICODE_NULL); lpFullName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz); if (lpFullName == NULL) { return NULL; } _strcpy(lpFullName, T_DEVICE_NAMED_PIPE); _strcat(lpFullName, lpObjectName); return lpFullName; }
StringGD::StringGD (char *str) { if (!str){ cerr << "Paramater invalid.\n"; exit(1); } cap = len = _strlen(str); int i = 0; this->str = new char[len]; while (str[i]){ this->str[i] = str[i]; i++; } }
/* * cuiPrintTextW * * Purpose: * * Output text to the console or file. * * UNICODE variant * */ VOID cuiPrintTextW( _In_ HANDLE hOutConsole, _In_ LPWSTR lpText, _In_ BOOL ConsoleOutputEnabled, _In_ BOOL UseReturn ) { SIZE_T consoleIO; DWORD bytesIO; LPWSTR Buffer; if (lpText == NULL) return; consoleIO = _strlen(lpText); if ((consoleIO == 0) || (consoleIO > MAX_PATH * 4)) return; consoleIO = (4 + sizeof(UNICODE_NULL) + consoleIO) * sizeof(WCHAR); Buffer = (LPWSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, consoleIO); if (Buffer) { _strcpy(Buffer, lpText); if (UseReturn) _strcat(Buffer, TEXT("\r\n")); consoleIO = _strlen(Buffer); if (ConsoleOutputEnabled != FALSE) { WriteConsole(hOutConsole, Buffer, (DWORD)consoleIO, &bytesIO, NULL); } else { WriteFile(hOutConsole, Buffer, (DWORD)(consoleIO * sizeof(WCHAR)), &bytesIO, NULL); } HeapFree(GetProcessHeap(), 0, Buffer); } }
void OSD(u8_t x, u8_t y, char *str) { int i; if (_strlen(str) > 14) { str[13] = 0; } u8_t args[17] = {_strlen(str), _strlen(str)-1, (y & 0xF) | ((x & 0x3) << 4)}; for(i=0; i<_strlen(str); i++) { char c = str[i]; if ((c >= '0') && (c <= '9')) { str[i] -= '0'; } else if ((c >= 'A') && (c <= 'Z')) { str[i] -= 'A'; str[i] += 10; } else if ((c >= 'a') && (c <= 'z')) { str[i] -= 'a'; str[i] += 36; } args[3+i] = str[i]; } runCommand(VC0706_OSD_ADD_CHAR, args, _strlen(str)+3, 5, TRUE); //printBuff(); }
/* * MainWindowOnRefresh * * Purpose: * * Main Window Refresh handler. * */ VOID MainWindowOnRefresh( _In_ HWND hwnd ) { LPWSTR CurrentObject; SIZE_T len; UNREFERENCED_PARAMETER(hwnd); supSetWaitCursor(TRUE); if (g_kdctx.hDevice != NULL) { ObListDestroy(&g_kdctx.ObjectList); if (g_kdctx.hThreadWorker) { WaitForSingleObject(g_kdctx.hThreadWorker, INFINITE); CloseHandle(g_kdctx.hThreadWorker); g_kdctx.hThreadWorker = NULL; } //query object list info g_kdctx.hThreadWorker = CreateThread(NULL, 0, kdQueryProc, &g_kdctx, 0, NULL); } supFreeSCMSnapshot(g_enumParams.scmSnapshot); sapiFreeSnapshot(g_enumParams.sapiDB); RtlSecureZeroMemory(&g_enumParams, sizeof(g_enumParams)); g_enumParams.scmSnapshot = supCreateSCMSnapshot(&g_enumParams.scmNumberOfEntries); g_enumParams.sapiDB = sapiCreateSetupDBSnapshot(); g_enumParams.lpSubDirName = CurrentObjectPath; len = _strlen(CurrentObjectPath); CurrentObject = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (len + 1)*sizeof(WCHAR)); if (CurrentObject) _strcpy(CurrentObject, CurrentObjectPath); TreeView_DeleteAllItems(ObjectTree); ListObjectDirectoryTree(L"\\", NULL, NULL); TreeView_SelectItem(ObjectTree, TreeView_GetRoot(ObjectTree)); if (CurrentObject) { ListToObject(CurrentObject); HeapFree(GetProcessHeap(), 0, CurrentObject); } supSetWaitCursor(FALSE); }
void StringGD::assign (char* str) { if (!str){ cerr << "Error in assign method. Null is not permited\n"; exit(1); } int len_str = _strlen(str); this->len = len_str; if (len_str > cap){ cap = (INCREMENT + 1) * len_str; delete [] this->str; this->str = new char[cap]; } for (int i = 0; i < len_str; i++) this->str[i] = str[i]; }
/* * MainWindowOnRefresh * * Purpose: * * Main Window Refresh handler. * */ VOID MainWindowOnRefresh( _In_ HWND hwnd ) { LPWSTR CurrentPath = NULL; SIZE_T len; UNREFERENCED_PARAMETER(hwnd); supSetWaitCursor(TRUE); if (g_kdctx.hDevice != NULL) { ObListDestroy(&g_kdctx.ObjectList); if (g_kdctx.hThreadWorker) { WaitForSingleObject(g_kdctx.hThreadWorker, INFINITE); CloseHandle(g_kdctx.hThreadWorker); g_kdctx.hThreadWorker = NULL; } //query object list info g_kdctx.hThreadWorker = CreateThread(NULL, 0, kdQueryProc, &g_kdctx, 0, NULL); } supFreeSCMSnapshot(); sapiFreeSnapshot(); supCreateSCMSnapshot(); sapiCreateSetupDBSnapshot(); len = _strlen(g_WinObj.CurrentObjectPath); CurrentPath = supHeapAlloc((len + 1) * sizeof(WCHAR)); if (CurrentPath) _strcpy(CurrentPath, g_WinObj.CurrentObjectPath); TreeView_DeleteAllItems(g_hwndObjectTree); ListObjectDirectoryTree(L"\\", NULL, NULL); TreeView_SelectItem(g_hwndObjectTree, TreeView_GetRoot(g_hwndObjectTree)); if (CurrentPath) { ListToObject(CurrentPath); supHeapFree(CurrentPath); } supSetWaitCursor(FALSE); }
uint8_t tcp_handle_msg(IpHost *iph) { TcpFrame *tcprf = tcp_get_header(&iph->mdev->recvFrame); TcpHeader *tcprh = &tcprf->tcpHead; if(tcprh->tcpFlags & TCP_SYN) { dout("new connection from %hhx %08x %i to %i.\n", tcprh->tcpFlags, HTONL(tcprf->ipHead.srcAddr), HTONS(tcprh->srcPort), HTONS(tcprh->destPort)); TcpSession *tcps = tcp_create_session(iph, tcprf->ipHead.srcAddr, tcprh->srcPort, tcprh->destPort); if(!arp_has_addr(&iph->arph, tcprf->ipHead.srcAddr)) arp_add_entry(&iph->arph, tcprf->ipHead.mac.srcAddr, tcprf->ipHead.srcAddr); tcps->remoteSeqNumber = HTONL(tcprh->seqNumber) + 1; TcpFrame *tcpsf = tcp_init_head(iph, tcps); TcpHeader *tcpsh = &tcpsf->tcpHead; tcpsh->tcpFlags = TCP_SYN | TCP_ACK; tcp_finish_frame(&iph->mdev->sendFrame, tcpsf, 0); return 1; } if(tcprh->tcpFlags & TCP_PSH) { TcpSession *tcps = tcp_get_session(iph, tcprf->ipHead.srcAddr, tcprf->tcpHead.srcPort, tcprf->tcpHead.destPort); TcpFrame *tcpsf = tcp_init_head(iph, tcps); TcpHeader *tcpsh = &tcpsf->tcpHead; uint8_t *dptr = tcp_get_payload(tcpsf); tcpsh->tcpFlags = TCP_PSH | TCP_ACK; uint16_t l = _strlen(htstr) + 1; _memcpy(dptr, htstr, l); tcp_finish_frame(&iph->mdev->sendFrame, tcpsf, l); return 1; } dout("tcp-wtf? %x %x %i %i\n", tcprh->tcpFlags, HTONL(tcprf->ipHead.srcAddr), HTONS(tcprh->srcPort), HTONS(tcprh->destPort)); #if 1 uint8_t *prbuf = iph->mdev->recvFrame.packet; int len = iph->mdev->recvFrame.writePtr, i; for(i = 0; i < len; i++) { dout("%02hhx ", *(prbuf++)); } #endif return 0; }