void TelnetProtocol::SendOption(BYTE code, BYTE option) { BYTE buf[3] = {cdIAC, code, option}; printf("SEND: %s %u\n", code2name(code), (unsigned)option); SendRaw(buf, sizeof(buf)); }
void TelnetProtocol::SendOption(BYTE code, BYTE option) { cout << name << " SEND: " << code2name(code) << " " << (unsigned)option << endl; streamEncoded += (BYTE)cdIAC; streamEncoded += code; streamEncoded += option; }
static void choose_hash_function (reiserfs_filsys_t fs) { unsigned long max; int hash_code; int i; max = 0; hash_code = func2code (0); for (i = 0; i < stats (fs)->hash_amount; i ++) { /* remember hash whihc got more hits */ if (stats (fs)->hash_hits [i] > max) { hash_code = i; max = stats (fs)->hash_hits [i]; } if (stats (fs)->hash_hits [i]) fsck_log ("%s got %lu hits\n", code2name (i), stats (fs)->hash_hits [i]); } if (max == 0) { /* no names were found. take either super block value or default */ reiserfs_hash (fs) = code2func (rs_hash (fs->s_rs)); if (!reiserfs_hash (fs)) reiserfs_hash (fs) = code2func (DEFAULT_HASH); return; } /* compare the most appropriate hash with the hash set in super block */ if (hash_code != rs_hash (fs->s_rs)) { fsck_progress ("Selected hash (%s) does not match to one set in super block (%s).\n", code2name (hash_code), code2name (rs_hash (fs->s_rs))); /* if (!fsck_user_confirmed (fs, "Overwrite?(Yes)", "Yes", 1)) { fsck_progress ("Not confirmed\n"); exit (4); } */ set_hash (fs->s_rs, hash_code); } else { fsck_progress ("\t%s hash is selected\n", code2name (hash_code)); } reiserfs_hash (fs) = code2func (hash_code); }
int TelnetProtocol::Write(const void *pBuf, int count) { for (int i = 0 ; i < count ; i++) { BYTE ch = ((const BYTE *)pBuf)[i]; switch (state) { case stData: if (ch == cdIAC) state = stCode; else WriteRaw(&ch, 1); break; case stCode: switch (ch) { case cdIAC: WriteRaw(&ch, 1); state = stData; break; case cdSB: case cdWILL: case cdWONT: case cdDO: case cdDONT: code = ch; state = stOption; break; default: printf("RECV: unknown code %u\n", (unsigned)ch); state = stData; } break; case stOption: printf("RECV: %s %u\n", code2name(code), (unsigned)ch); switch (code) { case cdSB: option = ch; params.clear(); state = stSubParams; break; case cdWILL: switch (options[ch].remoteOptionState) { case OptionState::osCant: SendOption(cdDONT, ch); break; case OptionState::osNo: options[ch].remoteOptionState = OptionState::osYes; SendOption(cdDO, ch); break; case OptionState::osYes: break; } break; case cdWONT: switch (options[ch].remoteOptionState) { case OptionState::osCant: case OptionState::osNo: break; case OptionState::osYes: options[ch].remoteOptionState = OptionState::osNo; SendOption(cdDONT, ch); break; } break; case cdDO: switch (options[ch].localOptionState) { case OptionState::osCant: SendOption(cdWONT, ch); break; case OptionState::osNo: options[ch].localOptionState = OptionState::osYes; SendOption(cdWILL, ch); break; case OptionState::osYes: break; } break; case cdDONT: switch (options[ch].localOptionState) { case OptionState::osCant: case OptionState::osNo: break; case OptionState::osYes: options[ch].localOptionState = OptionState::osNo; SendOption(cdWONT, ch); break; } break; default: printf(" ignored\n"); }; if (state == stOption) state = stData; break; case stSubParams: if (ch == cdIAC) state = stSubCode; else params.push_back(ch); break; case stSubCode: switch (ch) { case cdIAC: state = stSubParams; break; case cdSE: printf(" "); { for (BYTE_vector::const_iterator i = params.begin() ; i != params.end() ; i++) printf("%u ", (unsigned)*i); } printf("SE\n"); switch (option) { case opTerminalType: params.clear(); params.push_back(0); params.insert(params.end(), terminalType.begin(), terminalType.end()); SendSubNegotiation(option, params); break; default: printf(" ignored\n"); } state = stData; break; default: printf("RECV: unknown sub code %u\n", (unsigned)ch); state = stData; }; break; } } return count; }
HUB_MSG *TelnetProtocol::Decode(HUB_MSG *pMsg) { _ASSERTE(started == TRUE); _ASSERTE(pMsg->type == HUB_MSG_TYPE_LINE_DATA); DWORD len = pMsg->u.buf.size; BYTE_string org(pMsg->u.buf.pBuf, len); const BYTE *pBuf = org.data(); // discard original data from the stream if (!pMsgReplaceBuf(pMsg, HUB_MSG_TYPE_LINE_DATA, NULL, 0)) return NULL; for (; len ; len--) { BYTE ch = *pBuf++; switch (state) { case stData: if (ch == cdIAC) state = stCode; else streamDecoded += ch; break; case stCode: switch (ch) { case cdIAC: streamDecoded += ch; state = stData; break; case cdNOP: cout << name << " RECV: " << code2name(ch) << endl; state = stData; break; case cdSB: case cdWILL: case cdWONT: case cdDO: case cdDONT: code = ch; state = stOption; break; default: cout << name << " RECV: unknown code " << (unsigned)ch << endl; state = stData; } break; case stOption: cout << name << " RECV: " << code2name(code) << " " << (unsigned)ch << endl; switch (code) { case cdSB: option = ch; params.clear(); state = stSubParams; break; case cdWILL: if (options[ch] == NULL || options[ch]->stateRemote == TelnetOption::osCant) { SendOption(cdDONT, ch); } else if (options[ch]->stateRemote == TelnetOption::osNo) { options[ch]->stateRemote = TelnetOption::osYes; SendOption(cdDO, ch); } break; case cdWONT: if (options[ch] != NULL && options[ch]->stateRemote == TelnetOption::osYes) { options[ch]->stateRemote = TelnetOption::osNo; SendOption(cdDONT, ch); } break; case cdDO: if (options[ch] == NULL || options[ch]->stateLocal == TelnetOption::osCant) { SendOption(cdWONT, ch); } else if (options[ch]->stateLocal == TelnetOption::osNo) { options[ch]->stateLocal = TelnetOption::osYes; SendOption(cdWILL, ch); } break; case cdDONT: if (options[ch] != NULL && options[ch]->stateLocal == TelnetOption::osYes) { options[ch]->stateLocal = TelnetOption::osNo; SendOption(cdWONT, ch); } break; default: cout << " ignored" << endl; }; if (state == stOption) state = stData; break; case stSubParams: if (ch == cdIAC) state = stSubCode; else params.push_back(ch); break; case stSubCode: switch (ch) { case cdIAC: params.push_back(ch); state = stSubParams; break; case cdSE: cout << " "; { for (BYTE_vector::const_iterator i = params.begin() ; i != params.end() ; i++) cout << (unsigned)*i << " "; } cout << "SE" << endl; if (!options[option] || !options[option]->OnSubNegotiation(params, &pMsg)) cout << " ignored" << endl; if (!pMsg) return NULL; state = stData; break; default: cout << name << " RECV: unknown sub code " << (unsigned)ch << endl; state = stData; }; break; } } return FlushDecodedStream(pMsg); }