Você está na página 1de 78

DCET

Network Programming Lab

INTRODUCTION
The Windows Sockets Specification has been built upon the Berkeley Sockets programming model which is the de facto standard for TCP/IP networking. It is intended to pro ide a high degree of familiarity for programmers who are used to program with sockets in !"I# and other en ironments$ and to simplify the task of porting e%isting sockets&based source code. The Windows Sockets 'PI is consistent with release (.) of the Berkeley Software *istribution +(.)BS*,. Network ' computer network is composed of a number of -network layers.$ each pro iding a different restriction and/or guarantee about the data at that layer. The protocols at each network layer generally ha e their own packet formats$ and headers. The se en traditional layers of a network are di ided into two groups/ upper layers and lower layers. The sockets interface pro ides a uniform 'PI to lower layers of a network$ and allows implementing upper layers within sockets application.

Socket
0. The basic building block for communication is the socket. A socket is an endpoint of comm nication to which a name may be bound. 1ach socket in use has a type and an associated process. Sockets e%ist within communication domains. 2. ' communication domain is an abstraction introduced to b nd!e common properties of t"reads communicating through sockets. Sockets normally e%change data only with sockets in the same domain. MOHAMMED ABDUL MATEEN ##$ #%&'##(''&)*

DCET

Network Programming Lab

). The Windows Sockets facilities support a single communication domain/ T"e Internet Domain$ which is used by processes which communicate using the Internet Protocol Suite. Two t+pes of sockets c rrent!+ are a,ai!ab!e to a ser-. 0. ' STREA/ socket pro ides bi&directional$ reliable$ se3uenced$ and unduplicated flow of data without record boundaries. 2. ' DATA0RA/ socket supports bi&directional flow of data which is not promised to be se3uenced$ reliable$ or unduplicated.

PROTOCOLS
IP1 TCP and UDP 0. TCP is a stream protocol$ while. TCP establishes a continuous open connection between a client and a ser er$ o er which bytes may be written&&and correct order guaranteed&&for the life of the connection. 4o er$ bytes written o er TCP ha e no built&in structure$ so higher&le el protocols are re3uired to delimit any data records and fields within the transmitted byte stream. 2. !*P is a datagram protocol does not re3uire any connection be established between client and ser er5 it simply transmits a message between addresses. ' feature of !*P is that its packets are self&delimiting each datagram indicates e%actly where it begins and ends. ' possible disad antage of !*P is that it pro ides no guarantee that packets will transmit in&order or not. 4igher&le el protocols built on top of !*P may$ of course$ pro ide handshaking and acknowledgements. Peers1 Ports1 Names1 and Addresses 0. Beyond the protocol&&TCP or !*P&&there are two things a Peer +a client or ser er, needs to know about the machine it communicates with/ 'n IP Address and a Port. 2. 'n IP address is a ').bit data alue$ usually represented for humans in -dotted 3uadnotation$ e.g.$ 6(.(0.6(.072. ). ' Port is a #%.bit data ,a! e$ usually simply represented as a number less than 688)6&& most often one in the tens or hundreds range. 'n IP address gets a packet to a machine$ a port lets the machine decide which process/ser ice +if any, to direct it to. (. Classful addressing di ides IP ( 'dresses into 8 classes/ Class '$ B$ C$ *$ and 1. where as port numbers ha e 9eser ed Port "umbers or Well&:nown Port "umbers +0&);;;,.

MOHAMMED ABDUL MATEEN

#)&

#%&'##(''&)*

DCET

Network Programming Lab

S2NTA3ES
In network applications process can be di ided into/ a Client and a Ser er. Creating a socket <include =sys/types.h> <include =sys/socket.h> When you create a socket there are three main parameters/ int socket 4intdomain1 int t+pe1 int protoco!5 Description Socket creates an endpoint for communication and returns a descriptor. The domain parameter specifies a communication domain this selects the protocol family which will be used for communication. These families are defined in =sys/socket.h>. The currently understood formats include/ Name '?@!"I#$ P?@ABC'A '?@I"1T '?@I"1T6 '?@IP# P rpose Aocal communication IP ( Internet protocols IP 6 Internet protocols IP# & "o ell protocols

The socket has the indicated type$ which specifies the communication semantics. Currently defined types are/ SOC67STREA/- Pro ides se3uenced$ reliable$ two&way$ connection& based byte streams. 'n out&of&band data transmission mechanism may be supported.
SOC67D0RA/-Supports datagrams +connectionless$ unreliable messages of a fi%ed ma%imum length,.

SOC67SE8PAC6ET- Pro ides a se3uenced$ reliable$ two&way connection& based data transmission path for datagrams of fi%ed ma%imum length5 a consumer is re3uired to read anentire packet with each read system call. SOC67RA9- Pro ides raw network protocol access. SOC67RD/- Pro ides a reliable datagram layer that does not guarantee ordering. SOC67PAC6ET- Bbsolete and should not be used in new programs.
MOHAMMED ABDUL MATEEN

#)#

#%&'##(''&)*

DCET

Network Programming Lab

The protocol specifies a particular protocol to be used with the socket. "ormally only a single protocol e%ists to support a particular socket type within a gi en protocol family. The protocol number to use is specific to the -communication domain- in which communication is to take place. Sockets of type SBC:@ST91'C are full&duple% byte streams$ similar to pipes. They do not preser e record boundaries. ' stream socket must be in a connected state before any data may be sent or recei ed on it. ' connection to another socket is created with a connect call. Bnce connected$ data may be transferred using read and write calls or some ariant of the send and rec calls. When a session has been completed a close may be performed. But&of&band data may also be transmitted as described in send and recei ed as described in rec . SBC:@*D9'C and SBC:@9'W sockets allow sending of datagrams to correspondents named in send calls. *atagrams are generally recei ed with rec from$ which returns the ne%t datagram with its return address. SBC:@P'C:1T is an obsolete socket type to recei e raw packets directly from the de ice dri er. Ret rn :a! e &0 is returned if an error occurs otherwise the return alue is a descriptor referencing the socket. E;amp!eSockfd < socket 4A=7INET1 SOC67STREA/1 IPPROTO7TCP5 WhereESockfdE is the file descriptor returned by the socket function. '?@I"1T is the address family. SBC:@ST91'C is the type of packet. IPP9BTB@TCP is the protocol. >inding a socket to a port and waiting for t"e connections >indBind will bind a name to socket$it gi es the socket sockfd$ the local address myaddr$ myaddr is addrlen bytes long.Traditionallythis is called assigning a name to a socket. When a socket is created with sockect +, it e%ists in a name space but has no name assigned. It is normally necessary to assign local address using bind before sock@stream socket may recei e connection. int bind 4intsockfd1 4str ctsockaddr ?5m+addr1sock!en7taddr!en5@ The struct necessary to make socket works is the structsockaddr@in address5 and then we ha e the follow lines to say to system the information about the socket. T"e t+pe of socket address.sin@family F '?@I"1T /G use a internet domain G/
MOHAMMED ABDUL MATEEN

#))

#%&'##(''&)*

DCET T"e IP sed

Network Programming Lab

address.sin@addr.s@addr F I"'**9@'"H /Guse a specific IP of hostG/ T"e port sed address.sin@port F htons +08;;;,5 /G use a specific port number G/ 'nd finally bind our port to the socket bind+create@socket $ +structsockaddr G,Iaddress$siJeof+address,,5 Ret rn :a! eBn success + , is return$ on error K0 is returned and errno is set to appropriately. ListenAisten for connections on a socket <include =sys/socket.h> int listen+int s$ int backlog,5 Description To accept connections$ a socket is first created with socket$ a willingness to accept incoming connections and a 3ueue limit for incoming connections are specified with listen$ and then the connections are accepted with accept. The !isten call applies only to sockets of type SBC:@ST91'C or SBC:@S1LP'C:1T.The backlog parameter defines the ma%imum length the 3ueue of pending connections may grow to. If a connection re3uest arri es with the 3ueue full the client may recei e an error with an indication of 1CB""91?!S1* or$ if the underlying protocol supports retransmission$ the re3uest may be ignored so that retries succeed. 9eturn Malue Bn success$ Jero is returned. appropriately. Bn error$ &0 is returned$ and errno is set

Connect/ initiate a connection on a socket.The connect operation is used on the client side to identify and$ possibly$ start the connection to the ser er. The connect synta% is <include =sys/types.h> <include =sys/socket.h> int connect+intsockfd$ conststructsockaddr Gser @addr$ siJeof+address,,5

MOHAMMED ABDUL MATEEN

#)'

#%&'##(''&)*

DCET Description

Network Programming Lab

The file descriptor sockfd must refer to a socket. If the socket is of type SBC:@*D9'C then the ser @addr address isthe address to which datagrams are sent by default$ and the only address from which datagrams are recei ed. If the socket is of type SBC:@ST91'C or SBC:@S1LP'C:1T$ this call attempts to make a connection to another socket. The other socket is specified by ser @addr$ which is an address +of length addrlen, in the communications space of the socket. 1ach communications space interprets the ser @addr parameter in its own way. Denerally$ connection&based protocol sockets may successfully connect only once5 connectionless protocols sockets may use connect multiple times to change their association. Connectionless sockets may dissol e the association by connecting to an address with the sa@family member of sockaddr set to '?@!"SP1C. 91T!9" M'A!1 If the connection or binding succeeds$ Jero is returned. Bn error$ &0 is returned$ and errno is set appropriately. Accept-it accepts a socket connection. 'nd to finish we ha e to tell the ser er to accept a connection$ using the accept+, function. 'ccept is used with connection based sockets such as streams. <include =sys/types.h> <include =sys/socket.h> int accept+int s$ structsockaddr Gaddr$ socklen@t Gaddrlen,5 DESCRIPTION The accept function is used with connection&based socket types +SBC:@ST91'C$ SBC:@S1LP'C:1T and SBC:@9*C,. It e%tracts the first connection re3uest on the 3ueue of pending connections$ creates a new connected socket with mostly the same properties as s$ and allocates a new file descriptor for the socket$ which is returned. The newly created socket is no longer in the listening state. The original socket s is unaffected by this call. "ote that any per file descriptor flags +e erything that can be set with the ?@S1T?A fcntl$ like non& blocking or async state, are not inherited across an accept. In order to be notified of incoming connections on a socket$ you can use select. ' readable e ent will be deli ered when a new connection is attempted and you may then call accept to get a socket for that connection. 'lternati ely$ you can set the socket to deli er SIDIB when acti ity occurs on a socket5 There may not always be a connection waiting after a SIDIB is deli ered or select or poll return a readability e ent because the connection might ha e been remo ed by an asynchronous MOHAMMED ABDUL MATEEN #)* #%&'##(''&)*

DCET

Network Programming Lab

network error or another thread before accept is called. If this happens then the call will block waiting for the ne%t connection to arri e. To ensure that accept ne er blocks$ the passed socket s needs to ha e the B@"B"BABC: flag set. RETURN :ALUE The call returns &0 on error. If it succeeds$ it returns a non&negati e integer that is a descriptor for the accepted socket REC:1 REC:=RO/-recei e a message from a socket <include =sys/types.h> <include =sys/socket.h> intrec +int s$ oid Gbuf$ siJe@tlen$ int flags,5 intrec from+int s$ oid Gbuf$ siJe@tlen$ int flags

Structsockaddr Gfrom$ socklen@t Gfromlen5 Description The rec from and rec msg calls are used to recei e messages from a socket$ and may be used to recei e data on socket whether or not it is connection&oriented. If from is not "!AA$ and the socket is not connection&oriented$ the source address of the message is filled in the argument fromlen is a alue&result parameter$ initialiJed to the siJe of the buffer associated with from$ and modified on return to indicate the actual siJe of the address stored there. The rec call is normally used only on a connected socket and is identical to rec from with a "!AA from parameter. RETURN :ALUE These calls return the number of bytes recei ed$ or &0 ifan error occurred. SENDTO1 SEND-send a message from a socket <include =sys/types.h> <include =sys/socket.h> int send+int s$ const oid Gmsg$ siJe@tlen$ int flags,5 intsendto+int s$ const oid Gmsg$ siJe@tlen$ intflags$conststructsockaddr Gto$ socklen@ttolen,5
MOHAMMED ABDUL MATEEN

#)A

#%&'##(''&)*

DCET Description

Network Programming Lab

Send$ sendto are used to transmit a message to another socket. Send may be used only when the socket is in a connected state$ while sendto may be used at any time. The address of the target is gi en by to with tolen specifying its siJe. The length of the message is gi en by len. If the message is too long to pass atomically through the underlying protocol$ the error 1CSDSIN1 is returned$ and the message is not transmitted. "o indication of failure to deli er is implicit in a send. Aocally detected errors are indicated by a return alue of&0. When the message does not fit into the send buffer of the socket$ send normally blocks$ unless the socket has been placed in non&blocking I/B mode. In non&blocking mode it would return 1'D'I" in this case. The select call may be used to determine when it is possible to send more data. RETURN :ALUE The calls return the number of characters sent$ or &0 if an error occurred.

Ser,er Software
Ser ers can be classified based on/& 0. Ser icing discipline +iterati e or concurrent,5 2. Communication methods +connection&oriented orconnectionless,5 ). Caintenance of history +stateless or stateful,. Iterati,e Ser,er 'n iterati e ser er ser es the re3uests one after the other.It is easier to design and implement. Iterati e design is suitable when the ser ice time for each re3uest is small +because the mean response time is still acceptably small,.It is suitable for simple ser ices such as the TIC1 ser ice.Iterati e design is not suitable when the ser ice time for are3uest may be large. E;amp!e Two clients are using a file transfer ser ice/ 0. The 0st client re3uests to get a file of siJe 2;; Cbytes$ 2. The 2nd client re3uests to get a file of siJe 2; bytes. If iterati e design is used$ the 2nd client has to wait a long time. Conc rrent Ser,er ' concurrent ser er ser es multiple clients simultaneously. Concurrency refers to either 0. real simultaneous computing +using multiple processors, 2. apparent simultaneous computing +by time sharing,.Concurrent design is more difficult to implement$ but it cangi e a smaller response time when ). *ifferent clients re3uire ery different ser ice time$ orthe ser ice re3uires significant I/B$ or the ser er is e%ecuted on a computer with multipleprocessors.

MOHAMMED ABDUL MATEEN

#)%

#%&'##(''&)*

DCET

Network Programming Lab

Connection.Oriented Ser,ers ' connection&oriented ser er uses TCP for connection&oriented communication. TCP pro ides reliable transport.The ser ers need not do so. The ser ers are simpler. ' ser er uses a separate socket for each connection. Connection!ess Ser,ers ' connectionless ser er uses !*P for connectionlesscommunication. !*P does not guarantee reliable transport.' connectionless ser er may need to realiJe reliabilitythrough timeout and retransmission.The ser er and client are relati ely complicated. State!ess Ser,er ' stateless ser er does not keep information about the on&going interactions with each client. E;amp!e Consider the ser ice that a client can read a file storedon the ser erEs computer. 0. Tomaintain stateless$ each clientEs re3uest must specifya file name$ a position in the file$ and the number ofbytes to read. 2. The ser er handles each re3uest independently/ ). Bpen the specified file$ (. Seek to the specified position$ 8. 9ead the specified number of bytes$ 6. Send these bytes to the client$ 7. Close the file. Stateless ser ers are less efficient but they are more reliable they may be a good choice for !*P transport. Statef ! Ser,ers ' stateful ser er keeps information about the status ongoing interactions with each client. E;amp!e Consider the file&reading ser ice. The ser er maintains the following information/ ?ile reading can be more efficient. =o r possib!e t+pes of ser,er designs0. Iterati e$ connection&oriented ser er. 2. Iterati e$ connectionless ser er. ). Concurrent$ connection&oriented ser er. (. Concurrent$ connectionless ser er. Some iterati e ser er use tcp because to send data reliably.

Process and T"read


We can use processes and threads to realiJe concurrency ona processor ia time sharing. Process- ' process is a fundamental unit of computation. The BShas to store information about each process. arious

T"read0. Windows pro ides a second form of concurrente%ecution known as threads of e%ecution or threads.
MOHAMMED ABDUL MATEEN

#)(

#%&'##(''&)*

DCET

Network Programming Lab

2. 1ach thread must be associated with a single process. ). ' thread is e%ecuted independently of other threads. (. 'll threads in a process share/ +i, global ariables and+ii, resources that the BS allocates to the process. 8. 1ach thread in a process has its own local ariables. ?or e%ample$ if multiple threads e%ecute the following piece of code$ ?or +iF05 i=F0;5 iOO, Printf +PQdRn.$ i,5 Then each thread has its own inde% ariable i.

Remote Proced re Ca!! 4RPC5


9emote Procedure Call +9PC, pro ides a different paradigm for accessing network ser ices. Instead of accessing remote ser ices by sending and recei ing messages$ a client in okes ser ices by making a local procedure call. The local procedure hides the details of the network communication. When making a remote procedure call/ 0. The calling en ironment is suspended$ procedure parameters are transferred across the network to the en ironment where the procedure is to e%ecute$ and the procedure is e%ecuted there. 2. When the procedure finishes and produces its results$ its results are transferred back to the calling en ironment$ where e%ecution resumes as if returning from a regular procedure call. The main goal of 9PC is to hide the e%istence of the network from a program. 's a result$ 9PC doesnSt 3uite fit into the BSI model/ 0. The message&passing nature of network communication is hidden from the user. The user doesnSt first open a connection$ read and write data$ and then close the connection. Indeed$ clients often does not e en know they are using the networkT 2. 9PC often omits many of the protocol layers to impro e performance. 1 en a small performance impro ement is important because a program may in oke 9PCs often. ?or e%ample$ on +diskless, Sun workstations$ e ery file access is made ia an 9PC. 9PC is especially well suited for client&ser er +e.g.$ 3uery&response, interaction in which the flow of control alternates between the caller and callee. Conceptually$ the client and ser er do not both e%ecute at the same time. Instead$ the thread of e%ecution Uumps from the caller to the callee and then back again. The following steps take place during an 9PC/

MOHAMMED ABDUL MATEEN

#)B

#%&'##(''&)*

DCET

Network Programming Lab

1. ' client in okes a client stub procedure$ passing parameters in the usual way. The client

stub resides within the clientSs own address space.


2. The client stubmarshalls the parameters into a message. Carshalling includes con erting

the representation of the parameters into a standard format$ and copying each parameter into the message. ). The client stub passes the message to the transport layer$ which sends it to the remote ser er machine.
4. Bn the ser er$ the transport layer passes the message to a server stub$ which demarshalls

the parameters and calls the desired ser er routine using the regular procedure call mechanism. 8. When the ser er procedure completes$ it returns to the ser er stub +e.g.$ ia a normal procedure call return,$ which marshalls the return alues into a message. The ser er stub then hands the message to the transport layer. 6. The transport layer sends the result message back to the client transport layer$ which hands the message back to the client stub. 7. The client stub demarshalls the return parameters and e%ecution returns to the caller.

MOHAMMED ABDUL MATEEN

#)$

#%&'##(''&)*

DCET

Network Programming Lab

MOHAMMED ABDUL MATEEN

#'&

#%&'##(''&)*

DCET

Network Programming Lab

#C Understanding of Arp1 Te!net1 =tp1 =inger1 Tracero te1 Ifconfig1 Netstat1 Ping Commands iC ARP arp & manipulate the system '9P cache arp V&e nW V&4 typeW V&i ifW &a VhostnameW arp V& W V&i ifW &d hostname VpubW arp V& W V&4 typeW V&i ifW &s hostname hw@addr VtempW arp V& W V&4 typeW V&i ifW &s hostname hw@addr Vnetmask nmW pub arp V& W V&4 typeW V&i ifW &*s hostname ifa Vnetmask nmW pub arp V& n*W V&4 typeW V&i ifW &f VfilenameW DESCRIPTION 'rp manipulates the kernelEs '9P cache in arious ways. The primary options are clearing an address mapping entry and manually setting up one. ?or debugging purposes$ the '9P program also allows a complete dump of the '9P cache.
OPTIONS & $ && erbose

Tell the user what is going on by being erbose. shows numerical addresses instead of port or user names. When setting or reading the '9P cache$ this optional parameter tells arp which class of entries it should check for.

&n$ &&numeric &4 type$ &&hw&type type$ &t type

&a VhostnameW$ &&display VhostnameW

Shows the entries of the specified hosts. If the hostname parameter is not used$ all entries will be displayed. The entries will be displayed in alternate +BS*, style. 9emo e any entry for the specified host. !se the interface ifaSs hardware address. #'#

&d hostname$ &&delete hostname &*$ &&use&de ice


MOHAMMED ABDUL MATEEN

#%&'##(''&)*

DCET &e &i If$ &&de ice If

Network Programming Lab shows the entries in default +Ainu%, style. Select an interface. When dumping the '9P cache only entries matching the specified interface will be printed. Canually create an '9P address mapping entry forhost hostname with hardware address set to hw@addr class$ but for most classes one can assume that the usual presentation can be used. Similar to the &s option$ only this time the address info is taken from file filename set up. The name of the data file is ery often /etc/ethers$ but this is not official. If no filename is specified /etc/ethers is used as default.

&s hostname hw@addr$ &&set hostname

&f filename$ &&file filename

iiC

TELNET

user interface to the T1A"1T protocol telnet V&X1?:Aacdfr%W V&# authtypeW V&b hostaliasW V&e escapecharW V&k realmW V&l userW V&n tracefileW Vhost VportWW DESCRIPTION The telnet command is used to communicate with another host using the T1A"1T protocol. If telnet is in oked without the host argument$ it enters command mode$ indicated by its prompt +telnet>,. In this mode$ it accepts and e%ecutes the commands listed below. If it is in oked with arguments$ it performs an open command with those arguments.
OPTIONS

&X &1 #%&'##(''&)*

Specifies an X&bit data path. This causes an attempt to negotiate the T1A"1T BI"'9H option on both input and output. Stops any character from being recogniJed as an escape character. #')

MOHAMMED ABDUL MATEEN

DCET &?

Network Programming Lab If :erberos M8 authentication is being used$ the &? option allows the local credentials to be forwarded to the remote system including any credentials that ha e already been forwarded into the local en ironment. Specifies no automatic login to the remote system. Specifies an X&bit data path on output. This causes the BI"'9H option to be negotiated on output. disables the atype type of authentication. 'ttempt automatic login. Currently$ this sends the user name ia the !S19 ariable of the 1"MI9B" option if supported by the remote system. !ses bind+2, on the local socket to bind it to an aliased address or to the address of another interface than the one naturally chosen by connect+2,. disables the reading of the userSs .telnetrc file. sets the initial alue of the debug toggle to T9!1. Sets the initial telnet escape character to escape char. If escape char is omitted$ then there will be no escape character. If :erberos M8 authentication is being used$ the &f option allows the local credentials to be forwarded to the remote system. If :erberos authentication is being used$ the &k option re3uests that telnet obtain tickets for the remote host in realm realm instead of the remote hostSs realm$ as determined by krb@realmofhost+),. this option implies the &a option. This option may also be used with the open command. Bpens tracefile for recording trace information. Specifies a user interface similar to rlogin+0,. In this mode$ the escape character is set to the tilde +Y, character$ unless modified by the &e option. turns on encryption of the data stream if possible. Indicates the official name$ an alias$ or the Internet address of remote host. a

&: &A &# atype &a

&b hostalias

&c &d &eescapechar &f &k realm

&l user &n tracefile &r

&% host

MOHAMMED ABDUL MATEEN

#''

#%&'##(''&)*

DCET port

Network Programming Lab Indicates a port number +address of an application,. If a number is not specified$ the default telnet port is used. When in rlogin mode$ a line of the form Y. *isconnects from the remote prompt. =IN0ER

iiiC

finger & user information lookup program finger V&lmspW Vuser ...W VuserZhost ...W DESCRIPTION The finger displays information about the system users.
OPTIONS

&s

?inger displays the userSs login name$ real name$ terminal name and write status +as a [[GSS after the terminal name if write permission is denied,$ idle time$ login time$ office location and office phone number. produces a multi&line format displaying all of the information Pre ent matching of user names. !ser is usually a login name5 howe er$ matching will also be done on the usersS real names$ unless the &m option is supplied. 'll name matching performed by finger is case insensiti e. =TP

&l &m

i,C

ftp & Internet file transfer program ftp V&pineg dW VhostW pftp V&ineg dW VhostW
DESCRIPTION ?tp is the user interface to the Internet standard ?ile Transfer Protocol. The program allows a user to transfer files to and from a remote network site. Bptions may be specified at the command line$ or to

the command interpreter.

OPTIONS

&p

!se passi e mode for data transfers. 'llows use of ftp in en iron\ments where a firewall pre ents connections from the outside world back to the client machine. #'*

MOHAMMED ABDUL MATEEN

#%&'##(''&)*

DCET &i &n &e &g & &d ,C

Network Programming Lab turn off interacti e prompting during multiple file transfers. 9estrains ftp from attempting [[auto&loginSS upon initial connection. *isables command editing and history support$ if it was compiled into the ftp e%ecutable. Btherwise$ does nothing. *isables file name globing. erbose option forces ftp to show all responses from the remote ser er$ as well as report on data transfer statistics. 1nables debugging. The client host with which ftp is to communicate may be specified on the command line. TRACEROUTE

The traceroute command traces the network path of Internet routers that packets take as they are forwarded from your computer to a destination address. The -length- of the network connection is indicated by the number of Internet routers in the traceroute path. Traceroutes can be useful to diagnose slow network connections. Bn a Windows computer$ you can run a traceroute in an CS*BS or Command window by typing -tracert- followed by the domain name$ for e%ample as in -tracertwww.yahoo.com-

OPTIONS

Bption *efinition
MOHAMMED ABDUL MATEEN

#'A

#%&'##(''&)*

DCET

Network Programming Lab

&m

Set the ma%imum Time To Ai e +TTA, for the trace$ measured as the number of hosts the program will trace before ending$ default of ); Set the number of !*P packets to send for each setting$ default of ). Set the amount of seconds to wait for an answer from each host before gi ing up$ default of 8 Specify the other hostSs in alid port address$ default of ))()(

&3

&w

&p

Print the route packets take to network host.

,iC

NETSTAT

"etstat command displays the contents of arious network&related data structures in arious formats$ depending on the options you select. The first form of the command displays a list of acti e sockets for each protocol. The second form selects one from among arious other network data structures. The third form shows the state of the interfaces. The fourth form displays the routing table$ the fifth form displays the multicast routing table$ and the si%th form displays the state of *4CP on one or all interfaces. S2NTA3 netstat V&aW V&nW V& W netstat V&g ] &m ] &p ] &s ] &f address@family W V&nW V&P protocolW netstat V &i W V &I interface W V inter al W netstat &r V&aW V&nW V& W netstat &C V&nW V&s W netstat &* V &I interface W &a Show the state of all sockets and all routing table entries5 normally$ sockets MOHAMMED ABDUL MATEEN #'% #%&'##(''&)*

DCET

Network Programming Lab used by ser er processes are not shown and only interface$ host$ network$ and default routes are shown.

&n & &g &m &p &s &i &r &C &d &*

Show network addresses as numbers. netstat normally displays addresses as symbols. This option may be used with any of the display formats. Merbose. Show additional information for the sockets and the routing table. Show the multicast group memberships for all interfaces. Show the ST91'CS statistics. Show the address resolution +'9P, tables. Show per&protocol statistics. When used with the &C option$ show multicast routing statistics instead. Show the state of the interfaces that are used for TCP/IP traffic. Show the routing tables. Show the multicast routing tables. When used with the &s option$ show multicast routing statistics instead. Show the state of all interfaces that are under *ynamic 4ost Configuration Protocol +*4CP, control. Show the status of *4CP configured interfaces.

&f address@family imit statistics or address control block reports to those of the specified address@family$ which can be one of/ inet &P protocol & I interface ?or the '?@I"1T uni% ?or the '?@!"I# address family address family

Aimit display of statistics or state of all sockets to those applicable to protocol. Show the state of a particular interface. interface can be any alid interface such as ie; or le;.

MOHAMMED ABDUL MATEEN

#'(

#%&'##(''&)*

DCET

Network Programming Lab

,iiC

I=CON=I0

The -ifconfig- command allows the operating system to setup network interfaces and allow the user to iew information about the configured network interfaces. S2NTA3 ifconfig V&AW V&mW interface VcreateW Vaddress@familyW VaddressV/prefi%lengthW Vdest@addressWW VparametersW ifconfig interface destroy ifconfig &a V&AW V&dW V&mW V&uW Vaddress@familyW ifconfig &l V&dW V&uW Vaddress@familyW ifconfig V&AW V&dW V&mW V&uW V&CW address ?or the *'9P'&Internet family$ the address is either a host name present in the host name data base$ or a *'9P' Internet address e%pressed in the Internet standard [[dot notationSS. It is also possible to use the CI*9 notation +also known as the slash notation, to include the netmask. That is$ one can specify an address like 0^2.06X.;.0/06. addres@family Specify the address family which affects interpretation of the remaining parameters. Since an interface can recei e transmissions in differing protocols with different naming schemes$ specifying the address family is recommended. The address or protocol families currently supported are [[inetSS$ [[inet6SS$ Specify the address of the correspondent on the other end of a point to point link. This parameter is a string of the form [[name unitSS$ for e%ample$ [[en;SS.

dest@address interface

,iiiC

PIN0

Sends ICCP 1C4B@91L!1ST packets to network hosts. S2NTA3

MOHAMMED ABDUL MATEEN

#'B

#%&'##(''&)*

DCET

Network Programming Lab

ping &s V&dW V&lW V&AW V&nW V&rW V&9W V& W V &i interface@address W V&I inter alW V&t ttlW host VpacketsiJeW VcountW &d &l &A Set the SB@*1B!D socket option. Aoose source route. !se this option in the IP header to send the packet to the gi en host and back again. !sually specified with the &9 option. Turn off loopback of multicast packets. "ormally$ if there are members in the host group on the out& going interface$ a copy of the multicast packets will be deli ered to the local machine. Show network addresses as numbers. ping normally displays addresses as host names. Bypass the normal routing tables and send directly to a host on an attached network. If the host is not on a directly&attached network$ an error is returned. This option can be used to ping a local host through an interface that has been dropped by the router daemon. 9ecord route. Sets the IP record route option$ which will store the route of the packet inside the IP header. The contents of the record

&n &r

&9

Ping computerhope.com & Would ping the host computerhope.com to see if it is ali e

MOHAMMED ABDUL MATEEN

#'$

#%&'##(''&)*

DCET

Network Programming Lab

#C Imp!ementation of Conc rrent Ec"o ser,er sing connection. oriented Socket S+stem Ca!!sC
SER:ER<include=stdio.h> <include=sys/types.h> <include=sys/socket.h> <include=netinet/in.h> <include=arpa/inet.h> main+int argc$char Garg VW, _ int sockfd$new@sockfd$r al$pid5 char buff0V0;;W$buff2V0;;W5 struct sockaddr@in ser er$client5 int len5 sockfdFsocket+'?@I"1T$SBC:@ST91'C$IPP9BTB@TCP,5 if+sockfdFF&0, _ perror+-Rn sock@errRn-,5 e%it+0,5 ` ser er.sin@familyF'?@I"1T5 ser er.sin@addr.s@addrFinet@addr+-arg V0W-,5 ser er.sin@portFhtons+atoi+arg V2W,,5 r alFbind+sockfd$+struct sockaddrG,Iser er$siJeof+ser er,,5 if+r alTF&0, _ listen+sockfd$8,5
MOHAMMED ABDUL MATEEN

#*&

#%&'##(''&)*

DCET new@sockfdFaccept+sockfd$+struct sockaddrG,Iclient$Ilen,5 if+new@sockfdTF&0, _ pidFfork+,5 if+pidFF;, _ printf+-Rn child process e%ecutingRn-,5 printf+-Rn child process id is Qd-$getpid+,,5 r alFrec +new@sockfd$buff0$0;;$;,5 if+r alFF&0, _ perror+-Rn 91CM@199Rn-,5 e%it+0,5 ` else _ printf+-Rn recei ed message is QsRn-$buff0,5 ` r alFsend+new@sockfd$buff0$siJeof+buff0,$;,5 if+r alTF&0, _ printf+-Rn message sentto successfullyRn-,5 ` else _ perror+-Rn S1"*@199Rn-,5 e%it+0,5
MOHAMMED ABDUL MATEEN

Network Programming Lab

#*#

#%&'##(''&)*

DCET ` ` else _ printf+-Rnparents processRn-,5 printf+-Rnparents process id is QdRn-,5 e%it+0,5 ` ` else _ perror+-Rn'CC1PT@199Rn-,5 e%it+0,5 ` ` else _ perror+-RnBI"*@199Rn-,5 close+sockfd,5

Network Programming Lab

CLIENT<include=stdio.h> <include=sys/types.h> <include=sys/socket.h> <include=netinet/in.h> <include=arpa/inet.h>


MOHAMMED ABDUL MATEEN

#*)

#%&'##(''&)*

DCET main+int argc$char Garg V0W, _ int sockfd$r al5 char buff0V0;;W$buff2V0;;W5 struct sockaddr@in ser er$client5 int len5 sockfdFsocket+'?@I"1T$SBC:@ST91'C$IPP9BTB@TCP,5 if+sockfdFF&0, _ perror+-Rn SBC:@199Rn-,5 e%it+0,5 ` ser er.sin@familyF'?@I"1T5 ser er.sin@addr.s@addrFinet@addr+-0^2.06X.;.8-,5 ser er.sin@portFhtons+8()2,5 r alFconnect+sockfd$+struct sockaddrG,Iser er$siJeof+ser er,,5 if+r alTF&0, _ printf+-Rnenter a messageRn-,5 scanf+-Qs-$buff0,5 r alFsend+sockfd$buff0$siJeof+buff0,$;,5 if+r alFF&0, _ perror+-RnS1"*@199Rn-,5 e%it+0,5 ` r alFrec +sockfd$buff2$0;;$;,5
MOHAMMED ABDUL MATEEN

Network Programming Lab

#*'

#%&'##(''&)*

DCET if+r alTF&0, _ printf+-Rn recei ed message is Qs Rn-$buff2,5 ` else _ perror+-Rn 91CM@199Rn-,5 e%it+0,5 ` ` else _ printf+-Rn CB""1CT@199-,5 e%it+0,5 ` `

Network Programming Lab

OUTPUTSer,er e;ec tioncc 00s.c ./a.out 0^2.06X.;.8 )(86 Child process e%ecuting Parent process Parent process I* is 727) Child process I* is 7^(7 9ecei ed message is hello Cessage sent successfully
MOHAMMED ABDUL MATEEN

#**

#%&'##(''&)*

DCET

Network Programming Lab

C!ient e;ec tion cc 00c.c ./a.out 0^2.06X.;.8 )(86] 1nter a message 4ello 9ecei ed message is hell

MOHAMMED ABDUL MATEEN

#*A

#%&'##(''&)*

DCET

Network Programming Lab

)C Imp!ementation of Conc rrent Ec"o Ser,er Using Connection. Less Socket S+stem Ca!!sC
SER:ER
<include=stdio.h> <include=sys/types.h> <include=sys/socket.h> <include=netinet/in.h> <include=arpa/inet.h> main+int argc$char Garg VW, _ int sockfd$r al$pid5 char buff0V0;;W$buff2V0;;W5 struct sockaddr@in ser er$client5 int len5 sockfdFsocket+'?@I"1T$SBC:@*D9'C$IPP9BTB@!*P,5 if+sockfdFF&0, _ perror+-Rn SBC:@199Rn-,5 e%it+0,5 ` ser er.sin@familyF'?@I"1T5 ser er.sin@addr.s@addrFinet@addr+arg V0W,5 ser er.sin@portFhtons+atoi+arg V2W,,5 r alFbind+sockfd$+struct sockaddr G,Iser er$siJeof+ser er,,5 if+r alTF&0, _ pidFfork+,5
MOHAMMED ABDUL MATEEN

#*%

#%&'##(''&)*

DCET if+pidFF;, _ printf+-Rn childprocess e%ecutingRn-,5 printf+-Rn childprocess I* is/QdRn-$getpid+,,5 lenFsiJeof+client,5 r alFrec from+sockfd$buff0$2;$;$+struct sockaddr G,Iclient$Ilen,5 if+r alFF&0, _ perror+-Rn 91CM@199Rn-,5 e%it+0,5 ` else _ printf+-Rn recei ed message is/QsRn-$buff0,5 `

Network Programming Lab

r alFsendto+sockfd$buff0$siJeof+buff0,$;$+struct sockaddr G,Iclient$siJeof+client,,5 if+r alTF&0, _ printf+-Rn message sent successfullyRn-,5 ` else _ perror+-Rn S1"*@199Rn-,5 e%it+0,5 ` ` else
MOHAMMED ABDUL MATEEN

#*(

#%&'##(''&)*

DCET printf+-Rn parent processRn-,5 printf+-parent process I* isQdRn-$getppid+,,5 ` else _ perror+-Rn BI"*@199Rn-,5 e%it+0,5 ` `

Network Programming Lab

CLIENT <include=stdio.h> <include=sys/types.h> <include=sys/socket.h> <include=netinet/in.h> <include=arpa/inet.h> main+int argc$char Garg VW, _ int sockfd$r al5 char buff0V0;;W$buff2V0;;W5 struct sockaddr@in ser er$client5 int len5 sockfdFsocket+'?@I"1T$SBC:@*D9'C$IPP9BTB@!*P,5 if+sockfdFF&0, _ perror+-Rn SBC:@199Rn-,5 e%it+0,5
MOHAMMED ABDUL MATEEN

#*B

#%&'##(''&)*

DCET ` ser er.sin@familyF'?@I"1T5 ser er.sin@addr.s@addrFinet@addr+arg V0W,5 ser er.sin@portFhtons+atoi+arg V2W,,5 r alFbind+sockfd$+struct sockaddr G,Iclient$siJeof+client,,5 if+r alFF&0, _ perror+-Rn BI"*@199Rn-,5 e%it+0,5 ` printf+-Rn enter a messageRn-,5 scanf+-QS-$buff0,5

Network Programming Lab

r alFsendto+sockfd$buff0$siJeof+buff0,$;$+struct sockaddr G,Iser er$siJeof+ser er,,5 if+r alTF&0, _ printf+-Rn message sent successfullyRn-,5 ` else _ perror+-Rn S1"*@199Rn-,5 e%it+0,5 ` lenFsiJeof+ser er,5 r alFrec from+sockfd$buff0$2;$;$+struct sockaddr G,Iser er$Ilen,5 if+r alFF&0, _ perror+-Rn 91CM@199Rn-,5
MOHAMMED ABDUL MATEEN

#*$

#%&'##(''&)*

DCET e%it+0,5 ` else _ printf+-Rn recei ed message is QsRn-$buff0,5 `` OUTPUTSer,er e;ec tion cc 02s.c ./a.out 0^2.06X.;.8 ^866 Child process e%ecuting Child process I* is 08872 Parent process Parent process I* is 007)6 9ecei ed message is hellow Cessage sent successfully

Network Programming Lab

C!ient e;ec tion cc 02c.c ./a.out 0^2.06X.;.8 ^866 1nter a message 4ellow Cessage sent successfully.

MOHAMMED ABDUL MATEEN

#A&

#%&'##(''&)*

DCET

Network Programming Lab

'C Imp!ementation of Iterati,e Ec"o Ser,er Using Connection.Oriented Socket S+stem Ca!!
SER:ER<include=stdio.h> <include=sys/types.h> <include=sys/socket.h> <include=netinet/in.h> <include=arpa/inet.h> main+int argc$char Garg VW, _ int sockfd$new@sockfd$r al$pid5 char buff0V2;W$buff2V2;W5 struct sockaddr@in ser er$client5 socklen@t len5 sockfdFsocket+'?@I"1T$SBC:@ST91'C$IPP9BTB@TCP,5 if+sockfdFF&0, _ perror+-Rn sock@199Rn-,5 e%it+0,5 ` ser er.sin@familyF'?@I"1T5 ser er.sin@addr.s@addrFinet@addr+arg V0W,5 ser er.sin@portFhtons+atoi+arg V2W,,5 r alFbind+sockfd$+struct sockaddrG,Iser er$siJeof+ser er,,5 if+r alTF&0, _
MOHAMMED ABDUL MATEEN

#A#

#%&'##(''&)*

DCET listen+sockfd$8,5 while+0, _ new@sockfdFaccept+sockfd$+struct sockaddrG,Iclient$Ilen,5 if+new@sockfdTF&0, _ r alFrec +new@sockfd$buff0$2;$;,5 if+r alFF&0, _ perror+-Rn 91CM@199 Rn-,5 e%it+0,5 ` else _ printf+-Rn recie ed message is Qs Rn-$buff0,5 ` r alFsend+new@sockfd$buff0$siJeof+buff0,$;,5 if+r alTF&0, _ printf+-Rn message sent successfully Rn-,5 ` else _ perror+-Rn S1"*@199 Rn-,5 e%it+0,5 ` `
MOHAMMED ABDUL MATEEN

Network Programming Lab

#A)

#%&'##(''&)*

DCET else _ perror+-Rn 'CC1PT@199 Rn-,5 e%it+0,5 ` ` else _ perror+-Rn BI"*@199Rn-,5 close+sockfd,5 `

Network Programming Lab

CLIENT<include=stdio.h> <include=sys/types.h> <include=sys/socket.h> <include=netinet/in.h> <include=arpa/inet.h> main+int argc$char Garg VW, _ int sockfd$r al5 char buff0V2;W$buff2V2;W5 struct sockaddr@in ser er$client5 int len5 sockfdFsocket+'?@I"1T$SBC:@ST91'C$IPP9BTB@TCP,5 if+sockfdFF&0, _ perror+-Rn SBC:@199 Rn-,5
MOHAMMED ABDUL MATEEN

#A'

#%&'##(''&)*

DCET e%it+0,5 ` ser er.sin@familyF'?@I"1T5 ser er.sin@addr.s@addrFinet@addr+arg V0W,5 ser er.sin@portFhtons+atoi+arg V2W,,5 r alFconnect+sockfd$+struct sockaddrG,Iser er$siJeof+ser er,,5 if+r alTF&0, _ printf+-Rn enter a messageRn-,5 scanf+-Qs-$buff0,5 r alFsend+sockfd$buff0$siJeof+buff0,$;,5 if+r alFF&0, _ perror+-Rn S1"*@199 Rn-,5 e%it+0,5 ` r alFrec +sockfd$buff2$siJeof+buff2,$;,5 if+r alTF&0, _ printf+-Rn recie ed message is Qs Rn-$buff2,5 ` else _ perror+-Rn 91CM@199 Rn-,5 e%it+0,5 ` `
MOHAMMED ABDUL MATEEN

Network Programming Lab

#A*

#%&'##(''&)*

DCET else _ printf+-Rn CB""1CT@199 Rn-,5 e%it+0,5 ` `

Network Programming Lab

OUTPUT-

Ser,er e;ec tion


cc 0)s.c ./a.out 9ecei ed message is hellow Cessage sent successfully

C!ient e;ec tion cc 0)c.c ./a.out 1nter a message 4ellow 9ecei ed message is hellow

MOHAMMED ABDUL MATEEN

#AA

#%&'##(''&)*

DCET

Network Programming Lab

*C Imp!ementation of Iterati,e Ec"o Ser,er Using Connection!ess Socket S+stem Ca!!C


SER:ER<include=stdio.h> <include=sys/types.h> <include=sys/socket.h> <include=netinet/in.h> <include=arpa/inet.h> main+int argc$char Garg VW, _ int sockfd$r al5 char buff0V0;;W$buff2V0;;W5 struct sockaddr@in ser er$client5 int len5 sockfdFsocket+'?@I"1T$SBC:@*D9'C$IPP9BTB@!*P,5 if+sockfdFF&0, _ perror+-Rn sock@errRn-,5 e%it+0,5 ` ser er.sin@familyF'?@I"1T5 ser er.sin@addr.s@addrFinet@addr+arg V0W,5 ser er.sin@portFhtons+atoi+arg V2W,,5 r alFbind+sockfd$+struct sockaddrG,Iser er$siJeof+ser er,,5 if+r alTF&0, _ lenFsiJeof+client,5
MOHAMMED ABDUL MATEEN

#A%

#%&'##(''&)*

DCET

Network Programming Lab

r alFrec from+sockfd$buff0$0;;$;$+struct sockaddrG,Iclient$Ilen,5 if+r alFF&0, _ perror+-Rn91CM@199Rn-,5 e%it+0,5 ` else _ printf+-Rnrecei ed message is QsRn-$buff0,5 ` r alFsendto+sockfd$buff0$siJeof+buff0,$;$+struct sockaddrG,Iclient$siJeof+client,,5 if+r alTF&0, _ printf+-Rnmessage sent successfullyRn-,5 ` else _ perror+-RnS1"*@199Rn-,5 e%it+0,5 ` ` `

CLIENT<include=stdio.h> <include=sys/types.h> <include=sys/socket.h>


MOHAMMED ABDUL MATEEN

#A(

#%&'##(''&)*

DCET <include=netinet/in.h> <include=arpa/inet.h> main+int argc$char Garg VW, _ int sockfd$r al5 char buff0V0;;W$buff2V0;;W5 struct sockaddr@in ser er$client5 int len5 sockfdFsocket+'?@I"1T$SBC:@*D9'C$IPP9BTB@!*P,5 if+sockfdFF&0, _ perror+-RnSBC:@199Rn-,5 e%it+0,5 ` ser er.sin@familyF'?@I"1T5 ser er.sin@addr.s@addrFinet@addr+arg V0W,5 ser er.sin@portFhtons+atoi+arg V2W,,5 r alFbind+sockfd$+struct sockaddrG,Iclient$siJeof+client,,5 if+r alFF&0, _ perror+-RnBI"*@199Rn-,5 e%it+0,5 ` printf+-Rnenter a messageRn-,5 scanf+-Qs-$buff0,5

Network Programming Lab

r alFsendto+sockfd$buff0$siJeof+buff0,$;$+struct sockaddrG,Iser er$siJeof+ser er,,5 if+r alTF&0,


MOHAMMED ABDUL MATEEN

#AB

#%&'##(''&)*

DCET _ printf+-Rnmessage sent successfullyRn-,5 ` else _ perror+-RnS1"*@199Rn-,5 e%it+0,5 ` lenFsiJeof+ser er,5

Network Programming Lab

r alFrec from+sockfd$buff0$0;;$;$+struct sockaddrG,Iser er$Ilen,5 if+r alFF&0, _ perror+-Rn91CM@199Rn-,5 e%it+0,5 ` else _ printf+-Rnrecei ed message is QsRn-$buff0,5 ``

OUTPUTSer,er e;ec tion


cc 0(s.s ./a.out 0^2.06X.;.8 8787 recei ed message is hellow message sent successfully

C!ient e;ec tion


MOHAMMED ABDUL MATEEN

#A$

#%&'##(''&)*

DCET cc 0(c.c ./a.out 0^2.06X.;.8 8787 1nter a message 4ellow Cessage sent successfully

Network Programming Lab

MOHAMMED ABDUL MATEEN

#%&

#%&'##(''&)*

DCET

Network Programming Lab

AC Imp!ementation of time ser,ice as Connection Oriented Conc rrent Ser,er sing Socket S+stem Ca!!sC
SER:ER/ <include=stdio.h> <include=sys/types.h> <include=sys/socket.h> <include=netinet/in.h> <include=arpa/inet.h> main+int argc$char Garg VW, _ int sockfd$new@sockfd$r al$pid5 char buff0V0;;W$buff2V0;;W5 struct sockaddr@in ser er$client5 int len5 str ct time,a! t,@ sockfdFsocket+'?@I"1T$SBC:@ST91'C$IPP9BTB@TCP,5 if+sockfdFF&0, _ perror+-Rn sock@errRn-,5 e%it+0,5 ` ser er.sin@familyF'?@I"1T5 ser er.sin@addr.s@addrFinet@addr+arg V0W,5 ser er.sin@portFhtons+atoi+arg V2W,,5 r alFbind+sockfd$+struct sockaddrG,Iser er$siJeof+ser er,,5 if+r alTF&0,
MOHAMMED ABDUL MATEEN

#%#

#%&'##(''&)*

DCET _ listen+sockfd$8,5 new@sockfdFaccept+sockfd$+struct sockaddrG,Iclient$Ilen,5 if+new@sockfdTF&0, _ pidFfork+,5 if+pidFF;, _ printf+-Rn child process e%ecutingRn-,5 printf+-Rn child process id is Qd-$getpid+,,5 r alFrec +new@sockfd$buff0$0;;$;,5 if+r alFF&0, _ perror+-Rn 91CM@199Rn-,5 e%it+0,5 ` else _ printf+-Rn recei ed message is QsRn-$buff0,5 ` r alFsend+new@sockfd$buff0$siJeof+buff0,$;,5 if+r alTF&0, _ printf+-Rn message sent successfullyRn-,5 ` else _
MOHAMMED ABDUL MATEEN

Network Programming Lab

#%)

#%&'##(''&)*

DCET perror+-Rn S1"*@199Rn-,5 e%it+0,5 ` gettimeofda+4Dt,1NULL5@ send4new7sockfd14c"ar ?5t,Ct,7sec1siEeof4t,Ct,7sec51&5@ ` else _ printf+-Rn parents processRn-,5 printf+-Rn parents process id is QdRn-$ getppid+,,5 e%it+0,5 `` else _ perror+-Rn'CC1PT@199Rn-,5 e%it+0,5 `` else _perror+-RnBI"*@199Rn-,5 close+sockfd,5 ``

Network Programming Lab

CLIENT<include=stdio.h> <include=sys/types.h> <include=sys/socket.h> <include=netinet/in.h> <include=arpa/inet.h>


MOHAMMED ABDUL MATEEN

#%'

#%&'##(''&)*

DCET main+int argc$char Garg V0W, _ int sockfd$r al5 char buff0V0;;W$buff2V0;;W5 struct sockaddr@in ser er$client5 int len5 sockfdFsocket+'?@I"1T$SBC:@ST91'C$IPP9BTB@TCP,5 if+sockfdFF&0, _ perror+-Rn SBC:@199Rn-,5 e%it+0,5 ` ser er.sin@familyF'?@I"1T5 ser er.sin@addr.s@addrFinet@addr+arg V0W,5 ser er.sin@portFhtons+atoi+arg V2W,,5 r alFconnect+sockfd$+struct sockaddrG,Iser er$siJeof+ser er,,5 if+r alTF&0, _ printf+-Rn enter a messageRn-,5 scanf+-Qs-$buff0,5 r alFsend+sockfd$buff0$siJeof+buff0,$;,5 if+r alFF&0, _ perror+-RnS1"*@199Rn-,5 e%it+0,5 ` r alFrec +sockfd$buff2$0;;$;,5
MOHAMMED ABDUL MATEEN

Network Programming Lab

#%*

#%&'##(''&)*

DCET if+r alTF&0, _ printf+-Rn recei ed message is Qs Rn-$buff2,5 ` else _ perror+-Rn 91CM@199Rn-,5 e%it+0,5 ` printf4Ftime is G ! F1b ff)5@ ` else _ printf+-Rn CB""1CT@199-,5 e%it+0,5 ``

Network Programming Lab

OUTPUTSer,er e;ec tion


cc 08s.c ./a.out 0^2.06X.;.8 82(8 Child process e%ecuting Parent process Parent process I* is 007;8 Child process is 070(2 9ecei ed message is hellow Cessage sent successfully
MOHAMMED ABDUL MATEEN

#%A

#%&'##(''&)*

DCET

Network Programming Lab

C!ient e;ec tion cc 08c.c ./a.out 0^2.06X.;.8 82(8 1neter a message 4ellow 9ecei ed message is hellow Time is ')#$)%'$B*

MOHAMMED ABDUL MATEEN

#%%

#%&'##(''&)*

DCET

Network Programming Lab

%C Imp!ementation of Da+ Time Ser,ice as Connection Oriented Conc rrent Ser,er Using Socket S+stem Ca!!sC
SER:ER<include=stdio.h> <include=sys/types.h> <include=sys/socket.h> <include=netinet/in.h> <include=arpa/inet.h> main+int argc$char Garg VW, _ int sockfd$new@sockfd$r al$pid5 char buff0V0;;W$buff2V0;;W5 struct sockaddr@in ser er$client5 int len5 time7t t@ sockfdFsocket+'?@I"1T$SBC:@ST91'C$IPP9BTB@TCP,5 if+sockfdFF&0, _ perror+-Rn sock@errRn-,5 e%it+0,5 ` ser er.sin@familyF'?@I"1T5 ser er.sin@addr.s@addrFinet@addr+arg V0W,5 ser er.sin@portFhtons+atoi+arg V2W,,5 r alFbind+sockfd$+struct sockaddrG,Iser er$siJeof+ser er,,5 if+r alTF&0,
MOHAMMED ABDUL MATEEN

#%(

#%&'##(''&)*

DCET _ listen+sockfd$8,5 new@sockfdFaccept+sockfd$+struct sockaddrG,Iclient$Ilen,5 if+new@sockfdTF&0, _ pidFfork+,5 if+pidFF;, _ printf+-Rn child process e%ecutingRn-,5 printf+-Rn child process id is Qd-$getpid+,,5 r alFrec +new@sockfd$buff0$0;;$;,5 if+r alFF&0, _ perror+-Rn 91CM@199Rn-,5 e%it+0,5 ` else _ printf+-Rn recei ed message is QsRn-$buff0,5 ` t<time4NULL5@ snprintf4b ff#1siEeof4b ff#51FGsF1ctime4Dt55@ r alFsend+new@sockfd$buff0$siJeof+buff0,$;,5 if+r alTF&0, _ printf+-Rn message sent to successfullyRn-,5 `
MOHAMMED ABDUL MATEEN

Network Programming Lab

#%B

#%&'##(''&)*

DCET else _ perror+-Rn S1"*@199Rn-,5 e%it+0,5 ` ` else _ printf+-Rn parents processRn-,5 printf+-Rn parents process id is QdRn-$ getppid+,,5 e%it+0,5 `` else _ perror+-Rn'CC1PT@199Rn-,5 e%it+0,5 `` else _perror+-RnBI"*@199Rn-,5 close+sockfd,5 ``

Network Programming Lab

CLIENT<include=stdio.h> <include=sys/types.h> <include=sys/socket.h> <include=netinet/in.h> <include=arpa/inet.h>


MOHAMMED ABDUL MATEEN

#%$

#%&'##(''&)*

DCET main+int argc$char Garg V0W, _ int sockfd$r al5 char buff0V0;;W$buff2V0;;W5 struct sockaddr@in ser er$client5 int len5 sockfdFsocket+'?@I"1T$SBC:@ST91'C$IPP9BTB@TCP,5 if+sockfdFF&0, _ perror+-Rn SBC:@199Rn-,5 e%it+0,5 ` ser er.sin@familyF'?@I"1T5 ser er.sin@addr.s@addrFinet@addr+arg V0W,5 ser er.sin@portFhtons+atoi+arg V2W,,5 r alFconnect+sockfd$+struct sockaddrG,Iser er$siJeof+ser er,,5 if+r alTF&0, _ printf+-Rnenter a messageRn-,5 scanf+-Qs-$buff0,5 r alFsend+sockfd$buff0$siJeof+buff0,$;,5 if+r alFF&0, _ perror+-RnS1"*@199Rn-,5 e%it+0,5 ` r alFrec +sockfd$buff2$0;;$;,5
MOHAMMED ABDUL MATEEN

Network Programming Lab

#(&

#%&'##(''&)*

DCET if+r alTF&0, _ printf+-Rn recei ed message is Qs Rn-$buff2,5 ` else _ perror+-Rn 91CM@199Rn-,5 e%it+0,5 ` ` else _ printf+-Rn CB""1CT@199-,5 e%it+0,5 `

Network Programming Lab

OUTPUTSer,er e;ec tion cc 06s.c ./a.out 0^2.06X.;.8 62)8 child process e%ecuting parent process parent process I* is 0;7866^; child process I* is 280); rece ied message is hellow message sent successfully
MOHAMMED ABDUL MATEEN

#(#

#%&'##(''&)*

DCET

Network Programming Lab

c!ient e;ec tion


cc 06c.c ./a.out 0^2.06^.;.8 62)8 enter a message hellow recei ed message is T" =eb #* #)C&%-&& )&#'

MOHAMMED ABDUL MATEEN

#()

#%&'##(''&)*

DCET

Network Programming Lab

(C Remote Command E;ec tion Using An+ S"e!! Commands


SER:ER <include =stdio.h> <include =fcntl.h> <include =sys/types.h> <include =sys/socket.h> <include =netinet/in.h> <include =arpa/inet.h> main+int argc$char Garg VW, _ int sockfd$ new@sockfd$ r al$ fd5 char buff0V(;;W$buff2V(;;W5 struct sockaddr@in ser er$ client5 int len5 sockfdFsocket+'?@I"1T$SBC:@ST91'C$IPP9BTB@TCP,5 if+sockfdFF&0, _ perror+-Rnsock@errorRn-,5 e%it+0,5 ` ser er.sin@familyF'?@I"1T5 ser er.sin@addr.s@addrFinet@addr+arg V0W,5 ser er.sin@portFhtons+atoi+arg V2W,,5 r alFbind+sockfd$+struct sockaddrG,Iser er$siJeof+ser er,,5 if+r alTF&0,
MOHAMMED ABDUL MATEEN

#('

#%&'##(''&)*

DCET _ listen+sockfd$8,5 while+0, _ lenFsiJeof+client,5 new@sockfdFaccept+sockfd$+struct sockaddrG,Iclient$Ilen,5 if+new@sockfdTF&0, _ r alFrec +new@sockfd$buff0$siJeof+buff0,$;,5 if+r alFF&0, _ perror+-Rn rece @errorRn-,5 e%it+0,5 ` else _ strcat+buff0$->file.t%t-,5 system+buff0,5 fdFopen+-file.t%t-$B@9*B"AH$;666,5 if+fdFF&0, _ printf+-Rn file@errorRn-,5 e%it+0,5

Network Programming Lab

` read+fd$buff2$siJeof+buff2,,5 `
MOHAMMED ABDUL MATEEN

#(*

#%&'##(''&)*

DCET r alFsend+new@sockfd$buff2$siJeof+buff2,$;,5 if+r alTF&0, _ printf+-Rn message sent successfullyTRn-,5 ` else _ perror+-Rn send@errorRn-,5 e%it+0,5 ` ` else _ perror+-Rn accept@error-,5 e%it+0,5 ``` else _ perror+-Rn bind@errorRn-,5 close+sockfd,5 ` ` CLIENT<include =stdio.h> <include =sys/socket.h> <include =sys/types.h> <include =arpa/inet.h>
MOHAMMED ABDUL MATEEN

Network Programming Lab

#(A

#%&'##(''&)*

DCET <include=netinet/in.h> main+int argc$ char Garg VW,_ int sockfd$r al5 char buff0V(;;W$buff2V(;;W5 struct sockaddr@in ser er5 sockfdFsocket+'?@I"1T$SBC:@ST91'C$IPP9BTB@TCP,5 if+sockfdFF&0, _ perror+-RnSBC:@199Rn-,5 e%it+0,5 ` ser er.sin@familyF'?@I"1T5 ser er.sin@addr.s@addrFinet@addr+arg V0W,5 ser er.sin@portFhtons+atoi+arg V2W,,5 r alFconnect+sockfd$+struct sockaddrG,Iser er$siJeof+ser er,,5 if+r alTF&0, _ printf+-Rn 1nter any shell command/ Rn-,5 scanf+-Qs-$buff0,5 r alFsend+sockfd$buff0$siJeof+buff0,$;,5 if+r alFF&0, _ perror+-RnS1"*@199Rn-,5 e%it+0,5 ` r alFrec +sockfd$buff2$siJeof+buff2,$;,5 if+r alTF&0,
MOHAMMED ABDUL MATEEN

Network Programming Lab

#(%

#%&'##(''&)*

DCET _ printf+-Rn recei ed data is/QsRn-$ buff2,5 ` else _ printf+-Rn 91CM@199Rn-,5 ` ` else _ perror+-RnCB""1CT@199Rn-,5 ` ` OUTPUTSer,er e;ec tion cc remotecommande%ecutionser er.c ./a.out 0^2.06X.;.8 8;;^ message sent successfullyT

Network Programming Lab

C!ient e;ec tion cc remotecommande%ecutionclient.c ./a.out 0^2.06X.;.8 8;;^

1nter any shell command/ Ps recei ed data is/ PI* TTH )082 pts/0 ;;/;;/;; bash #(( TIC1 CC*

MOHAMMED ABDUL MATEEN

#%&'##(''&)*

DCET )22^ pts/0 PI* TTH 082 pts/0 22^ pts/0 ;;/;;/;; a.out TIC1 CC* ;;/;;/;; bash ;;/;;/;; a.out

Network Programming Lab

MOHAMMED ABDUL MATEEN

#(B

#%&'##(''&)*

DCET

Network Programming Lab

BC Demonstrate t"e Use of Ad,anced Socket S+stem Ca!!s


iC 0etsockopt4 5

<include=stdio.h> <include=unistd.h> <include=sys/socket.h> <include=netinet/in.h> <include=sys/types.h> int main+ oid, _ int msg5 int lenFsiJeof+msg,5 int sfdFsocket+'?@I"1T$SBC:@ST91'C$;,5 setsockopt+sfd$SBA@SBC:1T$SB@S"*B!?$+char G,Imsg$len,5 printf+-the source no QdRn-$msg,5 ` OUTPUT-

cc 0^.c /a.out the source no 627;002

iiC

Setsockopt4 5 #($

MOHAMMED ABDUL MATEEN

#%&'##(''&)*

DCET <include=stdio.h> <include=unistd.h> <include=sys/socket.h> <include=netinet/in.h> <include=sys/types.h> int main+ oid, _ int msgF072205 int lenFsiJeof+msg,5 int sfdFsocket+'?@I"1T$SBC:@ST91'C$;,5 setsockopt+sfd$SBA@SBC:1T$SB@S"*B!?$+char G,Imsg$len,5 printf+-the source no QdRn-$msg,5 `

Network Programming Lab

cc 0X.c ./a.out the source no 07220

Se!ect4 5
<include=stdio.h> <include=sys/time.h> <include=sys/types.h> <include=unistd.h> int main+ oid, _ fd@set rfds5 struct time al t 5 int ret al5
MOHAMMED ABDUL MATEEN

#B&

#%&'##(''&)*

DCET ?*@N19B+Irfds,5 ?*@S1T+;$Irfds,5 t .t @secF85 t .t @usecF;5 ret alFselect+0$Irfds$"!AA$"!AA$It ,5 if+ret alFF&0, perror+-select+,-,5 else if+ret al, printf+-Rn data is a ailable now-,5 else printf+-Rn no data within 8 sec-,5 return ;5 ` OUTPUT -

Network Programming Lab

cc 20.c ./a.out no data wit"in A sec

./a.out Nafar data is a,ai!ab!e now

4iii5CRead,4 5 and 9rite,4 5 Step #- create a fi!e named fi!eCt;t Step )- Imp!ementation of write, <include=stdio.h>
MOHAMMED ABDUL MATEEN

#B#

#%&'##(''&)*

DCET <include=sys/types.h> <include=sys/socket.h> <include=arpa/inet.h> <include =netinet/in.h> <include=sys/uio.h> <include=fcntl.h> main+, _ char s0V2;W$s2V2;W$s)V2;W$s(V2;W5 struct io ec io V(W5 int fd5 fdFopen+-file.t%t-$B@W9B"AH,5 printf+-enter 0st stringRn-,5 scanf+-Qs-$Is0,5 printf+-enter 2nd stringRn-,5 scanf+-Qs-$Is2,5 printf+-enter )rd stringRn-,5 scanf+-Qs-$Is),5 printf+-enter (th stringRn-,5 scanf+-Qs-$Is(,5 io V;W.io @baseFs05 io V;W.io @lenFsiJeof+s0,5 io V0W.io @baseFs25 io V0W.io @lenFsiJeof+s2,5 io V2W.io @baseFs)5 io V2W.io @lenFsiJeof+s),5 io V)W.io @baseFs(5
MOHAMMED ABDUL MATEEN

Network Programming Lab

#B)

#%&'##(''&)*

DCET io V)W.io @lenFsiJeof+s(,5 write +fd$+struct io ecG,Iio $(,5 ` OUTPUT-

Network Programming Lab

cc 07a.c ./a.out enter #st string hello enter )nd string my enter 'rd string nameis enter *t" string 'hsan

Step '- imp!ementation of read, <include=sys/types.h> <include=sys/socket.h> <include=arpa/inet.h> <include =netinet/in.h> <include=sys/uio.h> <include=fcntl.h> main+, _ char s0V2;W$s2V2;W$s)V2;W$s(V2;W5
MOHAMMED ABDUL MATEEN

#B'

#%&'##(''&)*

DCET struct io ec io V(W5 int fd5 io V;W.io @baseFs05 io V;W.io @lenFsiJeof+s0,5 io V0W.io @baseFs25 io V0W.io @lenFsiJeof+s2,5 io V2W.io @baseFs)5 io V2W.io @lenFsiJeof+s),5 io V)W.io @baseFs(5 io V)W.io @lenFsiJeof+s(,5 fdFopen+-file.t%t-$B@9*B"AH,5 read +fd$+struct io ecG,Iio $(,5 printf+-first string isQs Rn-$s0,5 printf+-second string is QsRn-$s2,5 printf+-third string is Qs Rn-$s),5 printf+-fourth string is QsRn-$s(,5 `

Network Programming Lab

OUTPUTcc 07b.c ./a.out first string is"e!!o second string is m+ third string is nameis fourth string is A"san 4iii5C 0etpeername4 5 <include =stdio.h> <include =sys/types.h>
MOHAMMED ABDUL MATEEN

#B*

#%&'##(''&)*

DCET <include =netinet/in.h> <include =sys/types.h> <define 199B9 &0 main+, _ int s$k5 struct sockaddr@in ser er$addr5 socklen@t len5 sFsocket+'?@I"1T$SBC:@ST91'C$;,5 ser er.sin@familyF'?@I"1T5 inet@aton+-0^2.06X.;.8-$Iser er.sin@addr,5 ser er.sin@portFhtons+X;,5 kFconnect+s$+struct socaddr G,Iser er$siJeof+ser er,,5 if+kFF;, _perror+-connect-,5 e%it+;,5 ` lenFsiJeof+addr,5 getpeername+s$+struct sockaddr G,Iaddr$Ilen,5 printf+-peer IP address/ Qs Rn-$inet@ntoa+addr.sin@addr,,5 printf+-peer port/ Qd Rn-$ntohs+addr.sin@port,,5 ` OUTPUTcc 2;.c ./a.out peer IP address/ 2X.082.(.X peer port/ 2^0X(
MOHAMMED ABDUL MATEEN

Network Programming Lab

#BA

#%&'##(''&)*

DCET

Network Programming Lab

$C Imp!ementation Of Conc rrent C"at Ser,er T"at A!!ows C rrent!+ Logged In User To Comm nicate 9it" One Anot"erC Use Socket S+stem Ca!!sC
SER:ER <include=sys/socket.h> <include=netinet/in.h> <include=string.h> <include=errno.h> <include=stdlib.h> short myport5 main+int argc$char Garg VW, _ int sockfd$newfd$nbyte$n$p5 struct sockaddr@in myaddr$claddr5 char buffV802W $ buff0V802W5 if+argcTF2, _ perror+-in alid no of arguments-,5 e%it+0,5 ` if++sockfdFsocket+'?@I"1T$SBC:@*D9'C$;,,FF&0, _ perror+-unable to create socket- ,5 e%it +0,5 ` myportFatoi+arg V0W,5 myaddr.sin@familyF'?@I"1T5
MOHAMMED ABDUL MATEEN

#B%

#%&'##(''&)*

DCET myaddr.sin@portFhtons+myport,5 myaddr.sin@addr.s@addrFI"'**9@'"H5 bJero+I+myaddr.sin@Jero,$X,5

Network Programming Lab

if++bind+sockfd$+struct sockaddr G,Imyaddr$siJeof+myaddr,,,FF &0, _ perror+-bind error-,5 e%it+0,5 ` write+0$-Rn waiting for Client-$siJeof+-Rn Wait for Client-,,5 newfdFsiJeof+claddr,5 nFrec from+sockfd$buff0$siJeof+buff0,$;$+struct sockaddr G,Icladdr$Inewfd,5 if+nFF&0, _ perror+-91C1IM1 199B9-,5 e%it+0,5 ` printf+-Rn CAI1"T CB""1CT1*I..-,5 write+0$-Rn Client /- $0;, 5 write+0$buff0$n,5 // for+55, pFfork+,5 if+p=;, _ perror+-C4IA* C'""BT B1 C91'T1*I.-,5 e%it+0,5 ` if+p>;,
MOHAMMED ABDUL MATEEN

#B(

#%&'##(''&)*

DCET _ for+55, _ write+0$-Rn Ser er /- $0;,5 nFread+;$buff$802,5 if++sendto+sockfd$buff$n$;$+struct sockaddr G,Icladdr$newfd,,FF&0, _ perror+-S1"* 199B9-,5 e%it+0,5 ` ` ` else _ for+55, _

Network Programming Lab

nFrec from+sockfd$buff0$siJeof+buff0,$;$+struct sockaddr G,Icladdr$Inewfd,5 write+0$-RrClient /-$0;,5 write+0$buff0$n,5 write+0$-RnSer er / -$siJeof+-RnSer er/-,,5 ```

CLIENT<include=stdio.h> <include=sys/socket.h> <include=netinet/in.h> <include=string.h> <include=errno.h>


MOHAMMED ABDUL MATEEN

#BB

#%&'##(''&)*

DCET <include=stdlib.h> short myport$destport5 main+int argc$char Garg VW, _ int sockfd$newfd$nbyte$n$na$p$35 struct sockaddr@in myaddr$ser addr5 char buffV802W$buff0V802W5 /Gif+argcTF(, _ perror+-in alid no of arguments-,5 e%it+0,5 `G/ sockfdFsocket+'?@I"1T$SBC:@*D9'C$;,5 if+sockfdFF&0, _ perror+-unable to create socket -,5 e%it +0,5 ` myportFatoi+arg V0W,5 myaddr.sin@familyF'?@I"1T5 myaddr.sin@portFhtons+myport,5 myaddr.sin@addr.s@addrFinet@addr+-0^2.06X.;.8-,5 bJero+I+myaddr.sin@Jero,$X,5 destportFatoi+arg V2W,5 ser addr.sin@familyF'?@I"1T5 ser addr.sin@portFhtons+destport,5 ser addr.sin@addr.s@addrFinet@addr+-0^2.06X.;.8-,5
MOHAMMED ABDUL MATEEN

Network Programming Lab

#B$

#%&'##(''&)*

DCET bJero+I+myaddr.sin@Jero,$X,5 3Fbind+sockfd$+struct sockaddr G,Imyaddr$siJeof+myaddr,,5 if+3FF&0, _ perror+-bind error-,5 e%it+0,5 ` newfdFsiJeof+ser addr,5

Network Programming Lab

write+0$-Rn 1"T19 C1SS'D1 TB CB""1CT TB T41 S19M19I.. / -$87, 5 // for+55, pFfork+,5 if+p=;, _ perror+-C4IA* C'""BT B1 C91'T1*I.-,5 e%it+0,5 ` if+p>;, _ for+55, _ write+0$-Rn Client /- $siJeof+-RnClient / -,,5 naFread+;$buff$802,5 if++sendto+sockfd$buff$na$;$+struct sockaddr G,Iser addr$newfd,,FF&0, _ perror+-S1"* 199B9-,5 e%it+0,5 `
MOHAMMED ABDUL MATEEN

#$&

#%&'##(''&)*

DCET `` else _ for+55, _

Network Programming Lab

nFrec from+sockfd$buff0$siJeof+buff0,$;$+struct sockaddr G,Iser addr$Inewfd,5 if+nFF&0, _ perror+-91C1IM1 199B9-,5 e%it+0,5 ` write+0$-RrSer er /-$0;,5 write+0$buff0$n,5 write+0$-RnClient / -$0;,5 ` OUTPUTSer,er e;ec tion cc chats.c ./a.out (()' waiting for Clie hello C!ient- how are u Ser,er- were are u

C!ient e;ec tion cc chatc.c CHaCo t (('# (()' #$)C#%BC&CA 1"T19 C1SS'D1 TB CB""1CT TB T41 S19M19I/ Ser er / hello
MOHAMMED ABDUL MATEEN

#$#

#%&'##(''&)*

DCET Client / how are u Ser er /were are u

Network Programming Lab

Note- . 772) +ser erEs port number, 77)0 +clientEs port number,

MOHAMMED ABDUL MATEEN

#$)

#%&'##(''&)*

DCET

Network Programming Lab

#&CImp!ementation of Remote fi!es Access sing RPCC


STEP #i file.%

program ?IA1@'CC1SS_ ersion ?IA1@M19SIB"_ string getfile+string name,F05 `F05 `F;%)02)(8675

STEP )I rpcgen .a fi!eC;

STEP '-

i file@ser er.c

Jinc! deKstdioC"L <include -file.hJinc! deKrpcHrpcC"L Jdefine ma;siEe A&& =ILE ?fp@ char GG getfile@0@s c+char GGargp$ struct s c@re3 Gr3stp, _ static char G result5 static c"ar b ffMma;siEeN@ c"ar tempM#&&N@ c"ar ?fi!e<?argp@
MOHAMMED ABDUL MATEEN

#$'

#%&'##(''&)*

DCET c"ar ?not7fo nd<Fno s c" fi!e bo ndF@ printf4Fstep #F5@ fp<fopen4fi!e1FrF5@ if4fp<<NULL5 res !t<not7fo nd@ e!se O printf4Fstep)F5@ fgets4b ff1siEeof4temp5.#1fp5@ w"i!e4Pfeof4fp55 O fgets4temp1siEeof4temp5.#1fp5@ strcat4b ff1temp5@ Q res !t<Db ffM&N@ printf4Fstep'F5@ ` return Iresult5 `

Network Programming Lab

STEP *cc fi!e7ser,erCc fi!e7s,cCc .o fi!e7ser,er CHfi!e7ser,erD V2W 0)(7^ STEP A,i fi!e7c!ientCc

Jinc! deKstdioC"L <include -file.hMOHAMMED ABDUL MATEEN

#$*

#%&'##(''&)*

DCET Jinc! deKrpcHrpcC"L oid file@access@0+char Ghost, _ CAI1"T Gclnt5 char G Gresult@05 char G getfile@0@arg5 c"ar fi!eM#&&N@ <ifndef *1B!D

Network Programming Lab

clnt F clnt@create +host$ ?IA1@'CC1SS$ ?IA1@M19SIB"$ -udp-,5 if +clnt FF "!AA, _ clnt@pcreateerror +host,5 e%it +0,5 ` <endif /G *1B!D G/ printf4Fenter a fi!e nameF5@ scanf4FGsF1Dfi!e5@ getfi!e7#7arg<Dfi!eM&N@ result@0 F getfile@0+Igetfile@0@arg$ clnt,5 if +result@0 FF +char GG, "!AA, _ clnt@perror +clnt$ -call failed-,5 ` printf4Ft"e fi!e is GsF1?res !t7#5@ <ifndef *1B!D clnt@destroy +clnt,5 <endif /G *1B!D G/ `
MOHAMMED ABDUL MATEEN

#$A

#%&'##(''&)*

DCET int main +int argc$ char Garg VW, _ char Ghost5

Network Programming Lab

if +argc = 2, _ printf +-usage/ Qs ser er@hostRn-$ arg V;W,5 e%it +0,5 ` host F arg V0W5 file@access@0 +host,5 e%it +;,5 ` Step %cc fi!e7c!ientCc fi!e7c!ntCc .o fi!e7c!ient CHfi!e7c!ient #$)C#%BC&CA enter a file name fi!eC; the file is program ?IA1@'CC1SS_ ersion ?IA1@M19SIB"_ string getfile+string name,F05 `F05 `F;%)02)(8675

MOHAMMED ABDUL MATEEN

#$%

#%&'##(''&)*

Você também pode gostar