Remote Shell - NCLab, KAIST

Download Report

Transcript Remote Shell - NCLab, KAIST

Remote Shell
CS230 Project #4
Assigned : 2006. 05. 15
Due date : 2006. 05. 29
Socket
server
 Socket: a software abstraction
 designed to provide a
standard API for sending
and receiving data across a
computer network
 c.f.) pipe, file, shared
memory
 Sockets are designed to
accommodate virtually any
networking protocol (i.e.
TCP/IP and UDP/IP).
 Implemented in many different
programming languages and
for most operating systems.
socket()
bind()
client
listen()
socket()
accept()
recv()
send()
connection
request data
reply data
connect()
send()
recv()
IP, Port, and Internet Protocol
 IP:


A address assigned for network interface card
32bits address
 Port


End-point of a communication operation
16-bit number
 UDP



Connectionless
Unreliable
Un-ordered packet protocol
 TCP




Connection setup
Provide reliable connection
In-order byte stream protocol
Congestion Control
service
echo
daytime
netstat
ftp-data
ftp
telnet
smtp
time
domain
finger
http
pop-2
pop
sunrpc
uucp-path
nntp
talk
tcp udp
7
7
13 13
15
20
21
23
25
37 37
53 53
79
80
109
110
111 111
117
119
517
Functions (1/3)
 int socket(int domain, int type, int protocol)
create socket
 type



SOCK_STREAM: TCP
SOCK_DGRAM: UDP
 int bind(int sockfd, const struct sockaddr
*address, size_t address_len)

associate a socket with an IP address and port
number
 int listen(int sockfd, int n)

tell a socket to listen for incoming connections
Functions (2/3)
 int accept(int sockfd, struct sockaddr
*address, size_t *address_len)

accept an incoming connection on a listening
socket
 int connect(int sockfd, const struct
sockaddr *address, size_t address_len)

connect a socket to a server
 ssize_t recv(int sockfd, void *buf, size_t
len, int flag)

receive data on a socket
Functions (3/3)
 ssize_t send(int sockfd, const void *buf,
size_t len, int flags)

send data out over a socket
 int close(int sockfd)

close a socket descriptor
Specification (1/3)
 Enhance your own shell to allow remote access of single
client/server model
 Supplement built-in server/client commands for your shell

e.g.) $server 12345
$client 127.0.0.1 12345
 Remote access




Server receives commands from client’s standard input
The server executes the commands
The server returns its standard output to the client
How often inputs/outputs are exchanged between client and server?
Standard input
Standard output
client
server
Specification (2/3)
 Supplements file transfer commands

‘put filename’ command
Upload client’s file from client to server
 If server already has a file of the same name,
overwrite the existing file


‘get filename’ command
Download server’s file from server to client
 If client already has a file of the same name,
overwrite the existing file


Allow ‘!’ as generic console ftp programs do
to execute client’s side commands
Specification (3/3)
 Details



Use TCP connection
Do not use threads yet
Compile

-lxnet option
Reference
 http://beej.us/guide/bgnet/