cmu ssd8: networks tools and ftp protocols
DESCRIPTION
CMU SSD8: Networks Tools and FTP Protocols. Tan Yi Software College Northwestern Polytechnical University. Network Tools ( 常用的网络工具 ). Netstat Ping/tracert Nslookup. netstat. displays the contents of various net- work-related data structures. The options have the following meaning: - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/1.jpg)
CMU SSD8: Networks Tools and FTP Protocols
Tan Yi
Software College
Northwestern Polytechnical University
![Page 2: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/2.jpg)
Network Tools ( 常用的网络工具 )
• Netstat• Ping/tracert• Nslookup
![Page 3: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/3.jpg)
netstat
• displays the contents of various net- work-related data structures.
• The options have the following meaning: – -a With the default display, show the state of
all sockets; normally sockets used by server processes are not shown.
– -s Show per-protocol statistics.
![Page 4: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/4.jpg)
Ping/tracert
• ICMP• Traceroute
![Page 5: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/5.jpg)
FTP 文件传输协议(File Transfer Protocol)
Reference:
RFC 959
![Page 6: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/6.jpg)
FTP 目标 Objectives( 摘录于 RFC 959)
• promote sharing of files
• encourage indirect use of remote computers
• shield user from variations in file storage
• transfer data reliably and efficiently
• “FTP, although usable directly by a user at a terminal, is designed mainly for use by programs”
![Page 7: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/7.jpg)
![Page 8: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/8.jpg)
HTTP 与 FTP 的比较
• 都是文件传输协议, TCP• FTP 使用两个并行的 TCP 连接 control connectio
n, data connection.• FTP 的控制信息是 out-of-band• HTTP 是带内 in-band 传输信息
![Page 9: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/9.jpg)
The FTP Model
![Page 10: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/10.jpg)
• FTP client ( 客户机 ) 首先与 server( 服务器 ) 在21 号端口上建立一个用于控制的 TCP 连接。
• FTP client
![Page 11: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/11.jpg)
Control and Data Connections
• Control functions (commands) and reply codes are transferred over the control connection.
• All data transfer takes place over the data connection.
• The control connection must be “up” while data transfer takes place.
![Page 12: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/12.jpg)
Control Connection
• The control connection is the “well known” service. Port 21
• The control connection uses the TELNET protocol.
• Commands and replies are all line oriented text (default is ASCII).
![Page 13: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/13.jpg)
Standard Connection Model
ControlControl
DataDataAAAA BBBB
![Page 14: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/14.jpg)
Alternative Connection Model
ControlControl
DataData
AA
BBBB CCCC
ControlControl
![Page 15: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/15.jpg)
Access Control Commands
USER specify user 用户名PASS specify password 口令CWD change directory 换目录CDUP change directory to parent
上一级目录QUIT logout 退出
![Page 16: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/16.jpg)
Transfer Parameter Commands
PORT publish local data port
PASV server should listen
TYPE establish data representation
MODE establish transfer mode
STRU establish file structure
![Page 17: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/17.jpg)
Service Commands
RETR retrieve file
SORT send file
STOU send file and save as unique
APPE send file and append
ABOR abort prev. service command
PWD print working directory
LIST transfer list of files over data link
![Page 18: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/18.jpg)
FTP Replies
• All replies are sent over control connection.
• Replies are a single line containing– 3 digit status code (sent as 3 numeric chars).– text message.
• The FTP spec. includes support for multiline text replies.
![Page 19: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/19.jpg)
FTP Reply Status Code example
• 331 Username OK, password required• 125 Data connection already open; transfer
starting• 425 Can’t open data connection• 452 Error writing file
![Page 20: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/20.jpg)
FTP Reply Status Code
First digit of status code indicates type of reply:‘1’: Positive Preliminary Reply (got it, but wait).
‘2’: Positive Completion Reply (success).
‘3’: Positive Intermediate Reply (waiting for more information).
‘4’: Transient Negative Completion (error - try again).
‘5’: Permanent Negative Reply (error - can’t do).
![Page 21: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/21.jpg)
FTP Reply Status Code
• 2nd digit indicates function groupings.‘0’: Syntax (problem with command syntax).
‘1’: Information (reply to help or status cmds).
‘2’: Connections (problem with a connection).
‘3’: Authentication (problem with login).
‘4’: Unspecified.
‘5’: File system (related to file system).
• 3rd digit indicates specific problem within function group.
![Page 22: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/22.jpg)
Data Transfer Modes
• STREAM: file is transmitted as a stream of bytes.
• BLOCK: file is transmitted as a series of blocks preceded by headers containing count and descriptor code (EOF, EOR, restart marker).
• COMPRESSED: uses a simple compression scheme - compressed blocks are transmitted.
![Page 23: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/23.jpg)
RFC 959
• The RFC includes lots more information and many details including:– parameters for commands– lists of reply status codes– protocol state diagrams– support for a variety of file structures– sample sessions
![Page 24: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/24.jpg)
TFTPTrivial File Transfer Protocol
References:
RFC 783, 1350
![Page 25: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/25.jpg)
TFTP Usage and Design
• Transfer files between processes.
• Minimal overhead (no security).
• Designed for UDP, although could be used with many transport protocols.
![Page 26: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/26.jpg)
TFTP Usage and Design (cont.)
• Easy to implement
• Small - possible to include in firmware
• Often uses to bootstrap workstations and network devices.
![Page 27: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/27.jpg)
Diskless Workstation Booting 1The call for help
DisklessWorkstation
Help! I don't know who I am!My Ethernet address is:4C:23:17:77:A6:03
RARP
![Page 28: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/28.jpg)
Diskless Workstation Booting 2
The answer from the all-knowing
DisklessWorkstation
I know all! You are to be know as: 128.113.45.211
RARP REPLY
RARPServer
![Page 29: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/29.jpg)
DisklessWorkstation
I need the file named boot-128.113.45.211
TFTP Request (Broadcast)
Diskless Workstation Booting 3
The request for instructions
![Page 30: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/30.jpg)
Diskless Workstation Booting 4
The dialog
DisklessWorkstation
TFTP File Transfer
TFTPServer
here is part 1
I got part 1
here is part 2
boot file
![Page 31: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/31.jpg)
TFTP Protocol
5 message types:– Read request– Write request– Data– ACK (acknowledgment)– Error
![Page 32: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/32.jpg)
Messages
• Each is an independent UDP Datagram
• Each has a 2 byte opcode 操作字 (1st 2 bytes)
• The rest depends on the opcode.
![Page 33: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/33.jpg)
Message Formats
OPCODE 0 0FILENAME MODE
BLOCK# DATA
BLOCK#
OPCODE
OPCODE
OPCODE BLOCK# ERROR MESSAGE 0
2 bytes 2 bytes
![Page 34: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/34.jpg)
Read Request
0202 filenamefilename 00 modemode 00
2 byte opcode2 byte opcodenetwork byte ordernetwork byte order
null terminated ascii stringnull terminated ascii stringcontaining name of filecontaining name of file
null terminated ascii stringnull terminated ascii stringcontaining transfer modecontaining transfer mode
variable length fields!variable length fields!
![Page 35: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/35.jpg)
Write Request
0202 filenamefilename 00 modemode 00
2 byte opcode2 byte opcodenetwork byte ordernetwork byte order
null terminated ascii stringnull terminated ascii stringcontaining name of filecontaining name of file
null terminated ascii stringnull terminated ascii stringcontaining transfer modecontaining transfer mode
variable length fields!variable length fields!
![Page 36: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/36.jpg)
TFTP Data Packet
0303 block #block # data 0 to 512 bytesdata 0 to 512 bytes
2 byte opcode2 byte opcodenetwork byte ordernetwork byte order
2 byte block number2 byte block numbernetwork byte ordernetwork byte order
all data packets have 512 bytesall data packets have 512 bytesexcept the last one.except the last one.
![Page 37: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/37.jpg)
TFTP Acknowledgment
0404 block #block #
2 byte opcode2 byte opcodenetwork byte ordernetwork byte order
2 byte block number2 byte block numbernetwork byte ordernetwork byte order
![Page 38: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/38.jpg)
TFTP Error Packet
0505 errcodeerrcode errstringerrstring
2 byte opcode2 byte opcodenetwork byte ordernetwork byte order
2 byte error code2 byte error codenetwork byte ordernetwork byte order
null terminated ascii error stringnull terminated ascii error string
00
![Page 39: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/39.jpg)
TFTP Error Codes
0 - not defined
1 - File not found
2 - Access violation
3 - Disk full
4 - Illegal TFTP operation
5 - Unknown port
6 - File already exists
7 - No such user
![Page 40: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/40.jpg)
TFTP transfer modes
• “netascii” : for transferring text files.– all lines end with \r\n (CR,LF).– provides standard format for transferring text files.– both ends responsible for converting to/from netascii f
ormat.
• “octet” : for transferring binary files.– no translation done.
![Page 41: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/41.jpg)
NetAscii Transfer Mode
Unix - end of line marker is just '\n'
• receiving a file– you need to remove '\r' before storing data.
• sending a file– you need to replace every '\n' with "\r\n" before
sending
![Page 42: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/42.jpg)
Lost Data Packets - Original Protocol
Specification• Sender uses a timeout with restransmission.
– sender could be client or server.
• Duplicate data packets must be recognized and ACK retransmitted.
• This original protocol suffers from the "sorcerer’s apprentice syndrome".
![Page 43: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/43.jpg)
Sorcerer’s Apprentice Syndrome
send DATA[n]
(time out)retransmit DATA[n]
receive ACK[n]send DATA[n+1]
receive ACK[n] (dup)send DATA[n+1]
(dup)
...
receive DATA[n]send ACK[n]
receive DATA[n] (dup)send ACK[n] (dup)
receive DATA[n+1] send ACK[n+1]
receive DATA[n+1] (dup)send ACK[n+1] (dup)
![Page 44: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/44.jpg)
The Fix
• Sender should not resend a data packet in response to a duplicate ACK.
• If sender receives ACK[n] - don’t send DATA[n+1] if the ACK was a duplicate.
![Page 45: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/45.jpg)
Concurrency
• TFTP servers use a "well known address" (UDP port number).
• How would you implement a concurrent server?– forking (alone) may lead to problems!– Can provide concurrency without forking, but it
requires lots of bookkeeping.
![Page 46: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/46.jpg)
TFTP Concurrency
• According to the protocol, the server may create a new udp port and send the initial response from this new port.
• The client should recognize this and send all subsequent messages to the new port.
![Page 47: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/47.jpg)
RRQ (read request)
• Client sends RRQ• Server sends back data chunk #0• Client acks chunk #0• Server sends data chunk #1• ...
![Page 48: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/48.jpg)
WRQ (write request)
• Client sends WRQ• Server sends back ack #0• Client data chunk #1 (the first chunk!)• Server acks data chunk #1• …
there is no data chunk #0!
![Page 49: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/49.jpg)
When is it over?
• There is no length of file field sent!
• All data messages except the last one contain 512 bytes of data.– message length is 2 + 2 + 512 = 516
• The last data message might contain 0 bytes of data!
![Page 50: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/50.jpg)
Issues
What if more than 65535 chunks are sent?– 65536 blocks x 512 bytes/block = 33,554,432 bytes.
• The RFC does not address this issue!• Remember that the network can duplicate
packets!
![Page 51: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/51.jpg)
Timeouts
• Set up an alarm to go off after a few seconds.• Call recvfrom (or recv or read).
– Check for error and EINTR– Can also set a flag in the SIGALRM signal handler.
![Page 52: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/52.jpg)
Timeout & RetransmissionParameters
• Reasonable Values:– wait no more than 5 seconds– retransmit no more than 5 times
• If no response - give up!
![Page 53: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/53.jpg)
Avoiding Sorcerer's Apprentice Syndrome
• Sender should timeout and retransmit.• Sender should ignore duplicate ACKs.
– don't retransmit data!
• Receiver should transmit ACK whenever data is received.– could be duplicate ACK, that's OK.
![Page 54: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/54.jpg)
Building Messages
• The messages are built in memory.
• Entire message is given to sendto.
• Opcode, block# are binary, network byte order, 2-byte integers.
![Page 55: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/55.jpg)
Suggestions
• Write a function that builds a message.buildmsg(char *buf, int op, int block, ...
– one place in the code to worry about network byte order!
• Write a function that extracts fields from a message.
![Page 56: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/56.jpg)
Stuffing binary values into a buffer
short int opcode; char *buffer;
Using memcpy - need to convert to NBO first:
tmp = htons(opcode);
memcpy(buffer, (char *) &tmp, 2);
![Page 57: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/57.jpg)
Advanced Stuffing Techniques
(a great name for a band!)
Stuffing NBO short in to a buffer:*((short int *) buffer) = htons(opcode);
Extracting a NBO short from a bufferopcode = ntohs( *((short int *) buffer+2));
doesn't have to be the beginning of the buffer!
![Page 58: CMU SSD8: Networks Tools and FTP Protocols](https://reader036.vdocuments.net/reader036/viewer/2022062500/568151bc550346895dbfedef/html5/thumbnails/58.jpg)