Chapter18 broadcasting. contents Introduction broadcast address unicast versus broadcast dg_cli function using broadcasting Race conditions.

Slides:



Advertisements
Similar presentations
UDP Sockets UDP: unreliable delivery, no connection DNS, NFS, SNMP.
Advertisements

Echo server The client reads a line of text from its standard input and writes the line to the server The server reads the line from its network input.
Ipv4 Socket Address Structure struct in_addr { in_addr_t s_addr; /* 32-bit IPv4 address */ /* network byte ordered */ }; struct sockaddr_in { uint8_t sin_len;
CMPE 150- Introduction to Computer Networks 1 CMPE 150 Fall 2005 Lecture 25 Introduction to Computer Networks.
ADVANCED NETWORK PROGRAMMING BİLGİN METİN ADVANCED SOCKET OPTIONS  IPv4&IPv6 Interoperability  IOCTL Options  Advanced I/O Functions  Nonblocking I/O.
Programming with UDP – I Covered Subjects: IPv4 Socket Address Structure Byte Ordering Functions Address Access/Conversion Functions Functions: 1.socket()
21.1 Chapter 21 Network Layer: Address Mapping, Error Reporting, and Multicasting Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction.
I/O Models Satish Krishnan. I/O Models Blocking I/O Non-blocking I/O I/O Multiplexing Signal driven I/O Asynchronous I/O.
I/O Multiplexing: select and poll
Chapter 6 I/O Multiplexing: select and poll function.
I/O Multiplexing Road Map: 1. Motivation 2. Description of I/O multiplexing 3. Scenarios to use I/O multiplexing 4. I/O Models  Blocking I/O  Non-blocking.
Elementary TCP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
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.
Chapter 10 SCTP Client / Server example. Simple echo server using SCTP protocol Send line of text from client to server Server sends the same line back.
Sockets Programming Introduction © Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid.
I/O Multiplexing© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science.
TDC561 Network Programming Camelia Zlatea, PhD Week 2 – part II: Socket Application Programming Interface.
1 Advanced I/O Computer Network Programming. 2 Regarding Project1 –Use RCS to store different revisions of your programs –this is a requirement! –you.
I/O Multiplexing Capability of tell the kernel that wants to be notified when one or more I/O conditions are ready. For example, I/O data is available.
1) The server should be concurrent. This implies that it should loop infinitely, listening for clients requests. It should NOT terminate after accepting.
Computer Network Architecture and Programming
Lecture 8 UDP Sockets & I/O Multiplexing
Chapter 5. TCP Client-Server Example. Contents –Introduction –TCP Echo Server –TCP Echo Client –Normal Startup and Termination –Posix Signal Handling.
Broadcast and Multicast. Unicast Host 2Host 1 Broadcast Packet received by every host on network (including the sender!)
Elementary UDP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
1 Introduction to Raw Sockets 2 IP address Port address MAC address TCP/IP Stack 67 Bootp DHCP OSPF protocol frame type UDP Port # TCP Port.
ECE 4110 – Internetwork Programming Client-Server Model.
1 Non-blocking I/O Computing Network Programming.
UNIX Network Programming1 UNIX Network Programming 2nd Edition.
Chapter 8 Elementary UDP Socket. Contents u recvfrom and sendto Function u UDP Echo Server( main, de_echo Function) u UDP Echo Client( main, de_cli Function)
UNIX Network Programming1 Chapter 15. Nonblocking I/O.
Review: How to create a TCP end point? What is the right format for sin_port and sin_addr in the sockaddr_in data structure? How many different ways we.
Broadcasting & Multicasting with UDP sockets Chap 20, 21.
Chaptere19 multicasting. contents multicast address multicasting versus broadcasting on a LAN multicasting on a WAN multicast socket option mcast_join.
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)
TELE 402 Lecture 4: I/O multi … 1 Overview Last Lecture –TCP socket and Client-Server example –Source: Chapters 4&5 of Stevens’ book This Lecture –I/O.
1 I/O Multiplexing We often need to be able to monitor multiple descriptors:We often need to be able to monitor multiple descriptors: –a generic TCP client.
CSCE 515: Computer Network Programming Select Wenyuan Xu Department of Computer Science and Engineering.
Advanced Sockets API-II Vinayak Jagtap
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
Network Layer4-1 Datagram networks r no call setup at network layer r routers: no state about end-to-end connections m no network-level concept of “connection”
TELE 402 Lecture 6: Name and address conversions 1 Overview Last Lecture –Socket Options and elementary UDP sockets This Lecture –Name and address conversions.
Threads and Locking Ioctl operations. Threads Lightweight processes What’s wrong with processes? –fork() is expensive – 10 to 100 times slower –Inter.
I/O Multiplexing. What is I/O multiplexing? When an application needs to handle multiple I/O descriptors at the same time –E.g. file and socket descriptors,
Chapter 18 Host Configuration : DHCP
TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 1 Overview Last Lecture –Advanced UDP sockets and threads –Source: Chapters 22&26 of Stevens’ book.
Introduction A Simple Daytime Client A Simple Daytime Server
Programming with UDP – II Covered Subjects: Creating UDP sockets Client Server Sending data Receiving data Connected mode.
Today’s topic: UDP Reliable communication over UDP.
TELE 402 Lecture 8: Broadcast and Multicast 1 Overview Last Lecture –IPv6 This Lecture –Broadcast and multicast sockets –Source: Chapters 20&21 of Stevens’
Review: –Concurrent server and multiplexed server How they work? Which one is better?
21.1 Chapter 21 Network Layer: Address Mapping, Error Reporting, and Multicasting Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction.
CMPT 471 Networking II Network Programming © Janice Regan,
UNIX Network Programming1 Chapter 13. Advanced I / O Functions.
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
1 UDP Sockets Programming Creating UDP sockets.Creating UDP sockets. –Client –Server Sending data.Sending data. Receiving data.Receiving data. Connected.
I/O Multiplexing.
Chapter 5. TCP Client-Server Example
Elementary UDP Sockets
Chapter 8 Elementary UDP Socket
UNIX Domain sockets The Linux Programming Interface (ch 57)
Chapter 5 (part 1) TCP Client /Server Example By: Lim Meng Hui.
UDP Sockets Programming
Lecture 11 Overview.
Advanced Network Programming spring 2007
Elementary UDP Sockets connectionless, unreliable, datagram
Chapter 06. UDP Server/Client.
I/O Multiplexing We often need to be able to monitor multiple descriptors: a generic TCP client (like telnet) need to be able to handle unexpected situations,
Chap 1 Foundation Broadcasting Chap 20.
Presentation transcript:

Chapter18 broadcasting

contents Introduction broadcast address unicast versus broadcast dg_cli function using broadcasting Race conditions

Introduction Multicasting support is optional in IPv4 but mandatory in IPv6 broadcasting support is not provided in IPv6 broadcasting and multicasting require UDP, they do not work with TCP internet application using broadcasting –ARP, BOOTP, NTP(network time protocol),routing daemon

Figure18.1

broadcast address Subnet-directed broadcast address:{netid, subnetid,-1} –this address all the interface on the specified subnet –most common today All-subnet-directed brocast address:{netid, -1, -1} –this address all subnet on the specified network network-directed broadcast address:{netid, -1} –this is used on network that does not use subnetting limited broadcast address:{-1, -1, -1}or –datagram destined to this address must never be forwarded by a router

Figure 18.2

unicast versus broadcast

dg_cli function using broadcasting Modify dg_cli function=> this allow to broadcast to the standard UDP daytime server, and printing all the replies. –Servaddr.sin_port = htons(13);

Figure 18.5 #include"unp.h" static voidrecvfrom_alarm(int); void dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen) { intn; const inton = 1; charsendline[MAXLINE], recvline[MAXLINE + 1]; socklen_tlen; struct sockaddr*preply_addr; preply_addr = Malloc(servlen); Setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)); Signal(SIGALRM, recvfrom_alarm); while (Fgets(sendline, MAXLINE, fp) != NULL) { Sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen); alarm(5);

for ( ; ; ) { len = servlen; n = recvfrom(sockfd, recvline, MAXLINE, 0, preply_addr, &len); if (n < 0) { if (errno == EINTR) break;/* waited long enough for replies */ else err_sys("recvfrom error"); } else { recvline[n] = 0;/* null terminate */ printf("from %s: %s", Sock_ntop_host(preply_addr, servlen), recvline); } } } } static void recvfrom_alarm(int signo) { return;/* just interrupt the recvfrom() */ } Figure 18.5

The subnet-directed broadcast address of >udpcli hi from …………… from ……………. from …………….. from ……………. Hello from ……………. from …………… from ……………. from …………….. from …………….

Race conditions When multiple processes are accessing data that is shared among them but the correct outcome depends on the execution order of the processes race conditions of a different type often exist when dealing with signals. Problem: a signal can normally be delivered at anytime while a program is executing A Race Condition (See Figure 18.5) –alarm(1) –sleep(1)

#include"unp.h" static void recvfrom_alarm(int); void dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen) { intn; const inton = 1; charsendline[MAXLINE], recvline[MAXLINE + 1]; sigset_tsigset_alrm; socklen_tlen; struct sockaddr*preply_addr; preply_addr = Malloc(servlen); Setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)); Sigemptyset(&sigset_alrm); Sigaddset(&sigset_alrm, SIGALRM); Signal(SIGALRM, recvfrom_alarm); while (Fgets(sendline, MAXLINE, fp) != NULL) { Sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen); Blocking and Unblocking the Signal

alarm(5); for ( ; ; ) { len = servlen; Sigprocmask(SIG_UNBLOCK, &sigset_alrm, NULL); n = recvfrom(sockfd, recvline, MAXLINE, 0, preply_addr, &len); Sigprocmask(SIG_BLOCK, &sigset_alrm, NULL); if (n < 0) { if (errno == EINTR) break;/* waited long enough for replies */ else err_sys("recvfrom error"); } else { recvline[n] = 0;/* null terminate */ printf("from %s: %s", Sock_ntop_host(preply_addr, servlen), recvline); } } } } static void recvfrom_alarm(int signo) { return;/* just interrupt the recvfrom() */ }

The unblocking of the signal, the call to recvfrom, and the blocking of the signal are all independent system calls. Assume recvfrom returns with the final datagram reply and the signal is delivered between the recvfrom and the blocking of the signal => the next call to recvfrom will blcok forever static void recvfrom_alarm(int signl) { had_alarm = 1; return; } Sigprocmask(SIG_UNBLOCK, &sigset_alrm, NULL); if (had_alarm == 1) break; n = recvfrom(sockfd, recvline, MAXLINE, 0, preply_addr, &len); Sigprocmask(SIG_BLOCK, &sigset_alrm, NULL);

#include"unp.h" static voidrecvfrom_alarm(int); void dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen) { intn; const inton = 1; charsendline[MAXLINE], recvline[MAXLINE + 1]; fd_setrset; sigset_tsigset_alrm, sigset_empty; socklen_tlen; struct sockaddr*preply_addr; preply_addr = Malloc(servlen); Setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)); FD_ZERO(&rset); Sigemptyset(&sigset_empty); Sigemptyset(&sigset_alrm); Sigaddset(&sigset_alrm, SIGALRM); Signal(SIGALRM, recvfrom_alarm); while (Fgets(sendline, MAXLINE, fp) != NULL) { Sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen); Blocking and Unblocking the signal with pselect

Sigprocmask(SIG_BLOCK, &sigset_alrm, NULL); alarm(5); for ( ; ; ) { FD_SET(sockfd, &rset); n = pselect(sockfd+1, &rset, NULL, NULL, NULL, &sigset_empty); if (n < 0) { if (errno == EINTR) break; else err_sys("pselect error"); } else if (n != 1) err_sys("pselect error: returned %d", n); len = servlen; n = Recvfrom(sockfd, recvline, MAXLINE, 0, preply_addr, &len); recvline[n] = 0;/* null terminate */ printf("from %s: %s", Sock_ntop_host(preply_addr, servlen), recvline); } } } static void recvfrom_alarm(int signo) { return;/* just interrupt the recvfrom() */ }

Figure 18.8 #include"unp.h" int pselect(int nfds, fd_set *rset, fd_set *wset, fd_set *xset, const struct timespec *ts, const sigset_t *sigmask) { intn; struct timevaltv; sigset_tsavemask; if (ts != NULL) { tv.tv_sec = ts->tv_sec; tv.tv_usec = ts->tv_nsec / 1000;/* nanosec -> microsec */ } sigprocmask(SIG_SETMASK, sigmask, &savemask);/* caller's mask */ n = select(nfds, rset, wset, xset, (ts == NULL) ? NULL : &tv); sigprocmask(SIG_SETMASK, &savemask, NULL);/* restore mask */ return(n); }

Using sigsetjump and siglongjump #include"unp.h" #include static voidrecvfrom_alarm(int); static sigjmp_bufjmpbuf; void dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen) { intn; const inton = 1; charsendline[MAXLINE], recvline[MAXLINE + 1]; socklen_tlen; struct sockaddr*preply_addr; preply_addr = Malloc(servlen); Setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)); Signal(SIGALRM, recvfrom_alarm); while (Fgets(sendline, MAXLINE, fp) != NULL) { Sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen);

alarm(5); for ( ; ; ) { if (sigsetjmp(jmpbuf, 1) != 0) break; len = servlen; n = Recvfrom(sockfd, recvline, MAXLINE, 0, preply_addr, &len); recvline[n] = 0;/* null terminate */ printf("from %s: %s", Sock_ntop_host(preply_addr, servlen), recvline); } static void recvfrom_alarm(int signo) { siglongjmp(jmpbuf, 1); } Figure 18.9

Using IPC from signal handler to function #include"unp.h" static void recvfrom_alarm(int); static intpipefd[2]; void dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen) { intn, maxfdp1; const inton = 1; charsendline[MAXLINE], recvline[MAXLINE + 1]; fd_setrset; socklen_tlen; struct sockaddr*preply_addr; preply_addr = Malloc(servlen); Setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)); Pipe(pipefd); maxfdp1 = max(sockfd, pipefd[0]) + 1; FD_ZERO(&rset); Signal(SIGALRM, recvfrom_alarm); while (Fgets(sendline, MAXLINE, fp) != NULL) { Sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen);

alarm(5); for ( ; ; ) { FD_SET(sockfd, &rset); FD_SET(pipefd[0], &rset); if ( (n = select(maxfdp1, &rset, NULL, NULL, NULL)) < 0) { if (errno == EINTR) continue; else err_sys("pselect error"); } if (FD_ISSET(sockfd, &rset)) { len = servlen; n = Recvfrom(sockfd, recvline, MAXLINE, 0, preply_addr, &len); recvline[n] = 0;/* null terminate */ printf("from %s: %s", Sock_ntop_host(preply_addr, servlen), recvline); } if (FD_ISSET(pipefd[0], &rset)) { Read(pipefd[0], &n, 1);/* timer expired */ break; } } } } Figure 18.10

static void recvfrom_alarm(int signo) { Write(pipefd[1], "", 1);/* write 1 null byte to pipe */ return; } Figure 18.10