如果是 MacBook (with the ARM64 M1 chip)
sudo -i切换为 root 用户
2、输入dhclient -v
再输入ifconfig就可以看到多了一个 ip 地址
有的同学说重启后命令失效,请参考下面的方法:
1、执行vim ~/.bashrc
2、在最后一行添加dhclient -v 3、保存退出
4、执行source ~/.bashrc使其立即生效
Preparations
cs144 官网
Virtual machine
setup instructions
Lab_FAQs
origin https://github.com/cs144/sponge (fetch) origin
https://github.com/cs144/sponge (push)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 cs144@cs144vm:~/sponge/build$ git config --list user.email=FacundoChan01@gmail.com user.name=Facundo Chan core.editor=vim core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true remote.origin.url=https://github.com/cs144/sponge remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* branch.master.remote=origin branch.master.merge=refs/heads/master branch.lab0-startercode.remote=origin branch.lab0-startercode.merge=refs/heads/lab0-startercode branch.lab1-startercode.remote=origin branch.lab1-startercode.merge=refs/heads/lab1-startercode branch.lab2-startercode.remote=origin branch.lab2-startercode.merge=refs/heads/lab2-startercode
推荐使用:vscode + ssh 连接虚拟机
Lab Checkpoint 0:
networking warmup
2.1 Fetch a Web page
1 2 3 4 5 $ telnet cs144.keithw.org http Trying 104.196.238.229... Connected to cs144.keithw.org. Escape character is '^]' .
输入下面的内容(太慢可能会关闭,可以先输入好后复制粘贴)。Hit the
Enter key two times
1 2 3 GET /hello HTTP/1.1 Host : cs144.keithw.orgConnection : close
1 2 3 4 5 6 7 8 9 10 11 12 HTTP/1.1 200 OKDate : Fri, 28 Oct 2022 16:55:15 GMTServer : ApacheLast-Modified : Thu, 13 Dec 2018 15:45:29 GMTETag : "e-57ce93446cb64"Accept-Ranges : bytesContent-Length : 14Connection : closeContent-Type : text/plainHello, CS144! Connection closed by foreign host.
2.3 Listening and connecting
可能出现下面的错误 :
1 2 cs144@cs144vm:~/sponge/build$ netcat -v -l -p 9090 netcat: getnameinfo: Temporary failure in name resolution
The problem could be with the DNS resolver. Try updating the
namespace in /etc/resolv.conf as
follows.
3.4 Writing webget
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 void get_URL (const string &host, const string &path) { TCPSocket Tsocket; Address addr = Address (host, "http" ); Tsocket.connect (addr); string msg = "GET " + path + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n" ; Tsocket.write (msg); Tsocket.shutdown (SHUT_WR); while (!Tsocket.eof ()){ cout << Tsocket.read (); } Tsocket.close (); }
4 An in-memory reliable byte
stream
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 class ByteStream { private : std::deque<char > _deque{}; size_t _capacity; size_t _bytes_written; size_t _bytes_read; bool _input_ended; ... }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 ByteStream::ByteStream (const size_t capacity) : _capacity(capacity), _bytes_written(0 ), _bytes_read(0 ), _input_ended(false ) { }size_t ByteStream::write (const string &data) { size_t input_size = min (remaining_capacity (), data.length ()); for (size_t i = 0 ; i < input_size; ++i){ _deque.emplace_back (data[i]); } _bytes_written += input_size; return input_size; }string ByteStream::peek_output (const size_t len) const { string output = "" ; size_t output_size = min (buffer_size (), len); for (size_t i = 0 ; i < output_size; ++i){ output += _deque[i]; } return output; }void ByteStream::pop_output (const size_t len) { size_t pop_size = min (buffer_size (), len); for (size_t i = 0 ; i < pop_size; ++i){ _deque.pop_front (); } _bytes_read += pop_size; }std::string ByteStream::read (const size_t len) { string ret = peek_output (len); pop_output (len); return ret; }void ByteStream::end_input () { _input_ended = true ; }bool ByteStream::input_ended () const { return _input_ended; }size_t ByteStream::buffer_size () const { return _deque.size (); }bool ByteStream::buffer_empty () const { return buffer_size () == 0 ; }bool ByteStream::eof () const { return buffer_empty () && input_ended (); }size_t ByteStream::bytes_written () const { return _bytes_written; }size_t ByteStream::bytes_read () const { return _bytes_read; }size_t ByteStream::remaining_capacity () const { return _capacity - buffer_size (); }