Socket Program Training 10/27/2010. What is a Socket ? An interface between an application process and transport layer (TCP or UDP). 2.

Slides:



Advertisements
Similar presentations
Introduction to Information Security Networking. Transmission Control Protocol (aka TCP) Most widely used protocol A TCP Connection is based on 6 crucial.
Advertisements

Socket Programming Application Programming Interface.
Elementary TCP Sockets Computer Networks Computer Networks Term B10 UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Quick Overview. 2 ISO/OSI Reference Model Application Application Presentation Presentation Session Session Transport Transport Network Network Data Link.
Tutorial 8 Socket Programming
Client Server Model The client machine (or the client process) makes the request for some resource or service, and the server machine (the server process)
ISP – 9 th Recitation Socket programming – Client side.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
Introduction to Linux Network 劉德懿
Introduction to Information Security Networking. Transmission Control Protocol (aka TCP) Most widely used protocol A ‘reliable’ (but not secure!) protocol.
Sockets CIS 370 Fall 2009, UMassD. Introduction  Sockets provide a simple programming interface which is consistent for processes on the same machine.
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
Socket Programming Based on tutorial prepared by EUISOK CHUNG CS3320 Spring2008.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
Sockets and intro to IO multiplexing. Goals We are going to study sockets programming as means to introduce IO multiplexing problem. We will revisit socket.
Fall 2000Datacom 11 Socket Programming Review Examples: Client and Server-Diagnostics UDP versus TCP Echo.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Network Programming Tutorial #9 CPSC 261. A socket is one end of a virtual communication channel Provides network connectivity to any other socket anywhere.
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
IT1352-NETWORK PROGRAMMING AND MANAGEMENT
Computer Network Sritrusta Sukaridhoto. Computer Network – Sritrusta Sukaridhoto Why Computer Network ??? Stand alone Computer …. FOR WHAT ???
Sirak Kaewjamnong Computer Network Systems
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
CS162B: IPv4 Socketing Jacob T. Chan. Socketing in the Real World  Most computer games are multiplayer in nature or have multiplayer components  DotA,
Computer Network Sritrusta Sukaridhoto. Why Computer Network ??? Stand alone Computer …. FOR WHAT ???
Ports Port - A 16-bit number that identifies the application process that receives an incoming message. Reserved ports or well-known ports (0 to 1023)
Remote Shell CS230 Project #4 Assigned : Due date :
Socket Program Training 10/24/2011. Introduction Video Streaming Server –Darwin VoIP –Asterisk Socket Program –Ex: FTP Backdoor Program 2.
Socket Programming Lec 2 Rishi Kant. Review of Socket programming Decide which type of socket – stream or datagram. Based on type create socket using.
1 COMP445 Fall 2006 Lab assignment 1. 2 STEP1: Get the name of the second party STEP2: Get phone number from white pages CALLERRECEIVER STEP1: Plug the.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
CPSC 441 TUTORIAL – FEB 13, 2012 TA: RUITNG ZHOU UDP REVIEW.
1 Computer Networks An Introduction to Computer Networks University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani Lecture 3: Sockets.
Elementary TCP Sockets UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
Socket Programming Tutorial Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
CSCI 330 UNIX and Network Programming Unit XV: Transmission Control Protocol.
Socket Program Training 10/29/ TCP Client Socket ( ) Connect ( ) send ( ) Close ( ) send ( ) Read ( ) Accept ( ) recv ( ) Listen ( ) Bind ( ) Socket.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
Introduction to Sockets
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
2: Application Layer 1 Socket Programming UNIX Network Programming, Socket Programming Tutorial:
UNIX Sockets Outline UNIX sockets CS 640.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Carnegie Mellon Proxy & Networking : Introduction to Computer Systems – Recitation H April 11, 2011.
Socket Programming in C CS587x Lecture 3 Department of Computer Science Iowa State University.
1 Socket Interface. 2 Client-Server Architecture The client is the one who speaks first Typical client-server situations  Client and server on the same.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
SOCKET PROGRAMMING Presented By : Divya Sharma.
Sockets and Beginning Network Programming
Sockets and Beginning Network Programming
CS 1652 Jack Lange University of Pittsburgh
Introduction to Information Security
Socket Programming in C
Review: TCP Client-Server Interaction
Imam Ahmad Trinugroho, ST., MMSI
Transport layer API: Socket Programming
UNIX Sockets Outline Homework #1 posted by end of day
Socket Program Training
TCP/IP Socket Programming in C
Training 2018/10/11.
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
Internet Networking recitation #8
Outline Communications in Distributed Systems Socket Programming
Presentation transcript:

Socket Program Training 10/27/2010

What is a Socket ? An interface between an application process and transport layer (TCP or UDP). 2

3 TCP Client Socket ( ) Connect ( ) send ( ) Close ( ) send ( ) Read ( ) Accept ( ) recv ( ) Listen ( ) Bind ( ) Socket ( ) recv ( ) Close ( ) Waiting for the requests from client Build a connection Data (request) Data (reply) Deal with the request TCP Server Notify the end of the file

4 FTP Server source code #include …… #define MAXDATA 1024 int main(void){ int sockfd; // sockfd is the socket file descriptor returned by socket() int recfd; int length; int filename, ndata, fdesc, fk; char buf[BUFSIZ]; char data[MAXDATA]; struct sockaddr_in myaddr; struct sockaddr_in client_addr;

5 FTP Server source code //Get a socket into TCP/IP if((sockfd=socket(AF_INET,SOCK_STREAM,0))<0){ // int socket (int family, int type, int protocol) perror("socket error"); return 0;} // AF_INET  IPv4, AF_INET6  IPv6 //SOCK_STREAM  TCP, SOCK_DGRAM  UDP //Set up address memset((char*)&myaddr,0,sizeof(myaddr)); myaddr.sin_family=AF_INET; myaddr.sin_addr.s_addr=htonl(INADDR_ANY); myaddr.sin_port=htons(1234);

6 FTP Server source code if(bind(sockfd,(struct sockaddr*)&myaddr,sizeof(myaddr))<0){ perror("bind failed"); return 0;} if(listen(sockfd,1)<0){ // int listen (int sockfd, int backlog) ; perror("listen error"); return 0;} //Loop continuously, waiting for connection requests and performing the service length=sizeof(client_addr); printf("Server start !\n");

7 FTP Server source code while(1){ if((recfd=accept(sockfd,(struct sockaddr*)&client_addr,&length))<0){ perror("accept error"); return 0;} if((fk=fork())<0){ perror("fork error"); exit(1);} if(fk==0){ if((filename=read(recfd,buf,BUFSIZ))<0){ perror("server read error"); return 0;}

8 FTP Server source code printf("Create socket #%d from %s : %d\n",recfd,inet_ntoa(client_addr.sin_addr),htons(client_addr.sin_p ort)); printf("receive: %s\n",&buf); //Reserve three parts for you if((fdesc……)<0){ perror("open file error"); exit(1); } for(;;){ ndata……; if(ndata==0){ printf("file %s transmit complete ! \n",&buf); break; }else{

9 FTP Server source code if((write……)<0){ perror("server write error"); return 0;} memset(buf,0,sizeof(buf)); close(recfd);} close(sockfd); return 0;}

10 FTP Client source code int main (int argc, char *argv[]) //ex: file option1 option2 option3 //argc = 4, argv[0]="file“,argv[1]="option1“, argv[2]="option2“,argv[3]="option3" { …… int ndata, fdesc, k, fk, index; int nbytes, count; …… //Check for proper usage if(argc < 4){ printf("use : ftpc IP file_count file1 file2...\n"); return 0;}

11 FTP Client source code count=atoi(argv[2]); printf("%d files request!\n",count); index=3; for(k=0;k<count;k++){ if((fk=fork())<0){ perror("fork error!");} if(fk==0){ if((sockfd=socket(AF_INET,SOCK_STREAM,0))<0){ printf("socket error\n"); return 0;}

FTP Client source code memset((char*)&myaddr,0,sizeof(myaddr)); myaddr.sin_family=AF_INET; myaddr.sin_addr.s_addr=htonl(INADDR_ANY); myaddr.sin_port=htons(0); if(bind(sockfd,(struct sockaddr*)&myaddr,sizeof(myaddr))<0){ printf("bind error\n"); return 0;} memset((char*)&servaddr,0,sizeof(servaddr)); servaddr.sin_family=AF_INET; servaddr.sin_port=htons(1234); servaddr.sin_addr.s_addr=inet_addr(argv[1]); 12

13 FTP Client source code if(connect(sockfd,(struct sockaddr*)&servaddr,sizeof(servaddr))<0){ printf("connect failed!"); return 0;} //Reserve four parts for you if(write……)<0){ // use argv function printf("write error!\n"); exit(1);} fdesc…… index++; if(fdesc<0){ perror("open error!"); exit(1);}

14 FTP Client source code for(;;){ if((nbytes=read(……))<0){ perror("first read"); exit(1);} if(nbytes==0){ printf("file %s transmit complete ! \n",argv[ ]); close(fdesc); close(sockfd); exit(1); break;} else{ if(write(……)<0){ perror("write error!"); exit(1); ……

15 Compile gcc -o filename filename.c –# gcc -o server server.c –# gcc -o client client.c Execute the filename –#./filename –#./filename server_IP number_of_file file1 file2 file3

Tcpdump and Tcpstat

17 Tcpdump and Tcpstat Listen the interfaces (network cards) of the router and write into a dump file. –Tcpdump options –-i, -w Listen the interfaces of the server and client.

18 Tcpdump and Tcpstat Gather statistics from the dump files. –Tcpstat options –-r, -f ‘ ’, -o “ ” –Ex: -f ‘port …’, -o “……” Filter out the three different files. –Tcpdump primitives –port, src net,

19 Tcpdump and Tcpstat Output formatting –%a: the average packet size –%b: the number of bits per second –% I : the number of IPv4 packets –%n the number of packets –%p: the number of packets per second

Backdoor program 20

Defined as a function in: net/ipv4/ip_input.c, line 379 net/ipv4/ip_input.c, line 379 Defined as a function prototype in: include/net/ip.h, line 93 include/net/ip.h, line 93 Referenced (in 3 files total) in: include/net/ip.h, line 93 include/net/ip.h, line 93 net/ipv4/af_inet.c, line 1560 net/ipv4/ip_input.c, line 379 Defined as a function in: net/ipv4/ip_input.c, line 379 net/ipv4/ip_input.c, line 379 Defined as a function prototype in: include/net/ip.h, line 93 include/net/ip.h, line 93 Referenced (in 3 files total) in: include/net/ip.h, line 93 include/net/ip.h, line 93 net/ipv4/af_inet.c, line 1560 net/ipv4/ip_input.c, line 379

IP Layer int count(struct sk_buff* skb){ struct iphdr *iph; struct udphdr *udph; struct timeval tv; static int total_packet = 0; static int last_timestamp = 0; 22

IP Layer iph = skb->nh.iph; printk("=================IP=================\n"); //IP Header printk("Version = %d\n",iph-> version); printk("IHL = %d\n",iph-> ihl*4); printk("Type of Service = %d\n",iph-> tos); printk("Total Length = %d\n",ntohs(iph-> tot_len)); printk("Identification = %d\n",iph-> id); printk("Fragmentation Offset = %d\n",iph-> frag_off); printk("Time to live = %d\n",iph-> ttl); printk("Protocol = %d\n",iph-> protocol); 23

IP Layer printk("Header Checksum = 0x%x\n",iph-> check); printk("Source Address = %d.%d.%d.%d\n",*(skb->nh.raw+12),*(skb- >nh.raw+13),*(skb->nh.raw+14),*(skb->nh.raw+15)); printk("Distination Address = %d.%d.%d.%d\n",*(skb- >nh.raw+16),*(skb->nh.raw+17),*(skb->nh.raw+18),*(skb- >nh.raw+19)); 24

TCP Layer if(iph-> protocol == IPPROTO_UDP) {//UDP Header printk("================UDP=================\n"); udph = (struct udphdr *)(skb->nh.raw + iph->ihl*4); printk("Source Port = %d\n",ntohs(udph->source)); printk("Distination Address = %d\n",ntohs(udph-> dest)); printk("Segment Length = %d\n",ntohs(udph-> len)); printk("Checksum = 0x%x\n",udph-> check); 25

Q&A 26