* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download LURP
Survey
Document related concepts
Dynamic Host Configuration Protocol wikipedia , lookup
Distributed firewall wikipedia , lookup
Airborne Networking wikipedia , lookup
Parallel port wikipedia , lookup
Recursive InterNetwork Architecture (RINA) wikipedia , lookup
Asynchronous Transfer Mode wikipedia , lookup
Computer network wikipedia , lookup
Power over Ethernet wikipedia , lookup
Multiprotocol Label Switching wikipedia , lookup
IEEE 802.1aq wikipedia , lookup
Network tap wikipedia , lookup
Deep packet inspection wikipedia , lookup
Point-to-Point Protocol over Ethernet wikipedia , lookup
Zero-configuration networking wikipedia , lookup
Virtual LAN wikipedia , lookup
Transcript
UDP User Datagram Protocol (UDP) Unreliable and unordered datagram service Adds multiplexing 0 16 No flow control SrcPort Endpoints identified by ports Optional checksum servers have well-known ports see /etc/services on Unix pseudo header + udp header + data Header format Checksum 31 DstPort Length Data Initiating a Session Client initiates the connection and sends the clients port in the message header Server port is contained in /etc/services DNS=53 talk=517 Connectionless Primary purpose demux (demultiplex) Demux Process Application process Application process Application process Ports Queues Packets demultiplexed Port 3000 Port 3100 Port 2000 UDP Packets arrive Using it TCP s=socket(AF_INET, SOC_STREAM,0) bind listen accept connect read/write UDP S=socket(AF_INET, SOCK_DGRAM, 0) bind (receiver) sendto, recvfrom Broadcasting with UDP You have to enable broadcasting on the socket Set up the address you will be passing to “sendto” to refer to 255.255.255.255 (0xffffffff) Anyone in the broadcast domain will be able to read the packet. A broadcast domain will generally be machines on one port of a router What is a broadcast domain? Networks are built from hubs (not used much anymore), ethernet switches and routers Packets from machines on different ports of a hub will collide (A hub is like tying the wires together) The collision domain for a network built from hubs is all of the ports on the hub Broadcast packets from machines on different ports of a ethernet switch will be seen on all ports of the switch The broadcast domain for a network built from switches is all of the ports on the switch How does a ethernet switch work? When you try to connect to mail.cs.byu.edu, your ethernet card doesn’t know which ethernet address to put into the destination So it sends an Address Resolution Protocol (ARP) packet to the broadcast ethernet address asking if anyone knows about mail.cs.byu.edu Everyone else will ignore it, mail.cs.byu.edu should respond with a packet indicating what his ethernet address is Your machine then puts this address into the destination field Ethernet switches An ethernet switch learns where certain ethernet addresses are by looking at source addresses It starts by behaving like a hub, and forwards all packets out every port When it sees a new source ethernet address on a port, it adds that address to a cache of known addresses When this ethernet address appears in the destination address of a packet, the switch sends it only to the port where this address was seen as a source address Broadcast Addresses When you send a packet to the broadcast IP address, the broadcast ethernet address is placed in the destination address for the packet. Switches forward packets that are sent to the broadcast ethernet address to all of their ports. Routers ignore these packets, and only forward packets that are sent directly to their address That is why you have to configure a gateway Where do I send packets? Check to see if the destination IP address is in your broadcast domain Look at the network mask and see if you both resolve to the same network If the destination is not in the same network, send it to the gateway If the destination is in the same network, then ARP to find the ethernet address ARP Tables You can use /sbin/arp to see current arp table $ /sbin/arp -a cs-private-2.cs.byu.edu (192.168.2.1) at 00:E0:B1:62:C8:2C [ether] on eth0 You can look at your network mask with ifconfig $ /sbin/ifconfig eth0 Link encap:Ethernet HWaddr 00:08:74:30:AD:2F inet addr:192.168.2.210 Bcast:192.168.2.255 Mask:255.255.255.0 inet6 addr: fe80::208:74ff:fe30:ad2f/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:35618047 errors:0 dropped:0 overruns:0 frame:0 TX packets:34395541 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:1641338780 (1.5 GiB) TX bytes:2883262518 (2.6 GiB) Example (router R2) Network Mask Network Number Next Hop 255.255.255.0 128.187.1 R3 (128.187.4.1) 255.255.255.0 128.187.2 R1 (128.187.3.1) 255.255.255.255 128.187.4.1 (R3) Interface 0 0.0.0.0 0.0.0.0 R1 (128.187.3.1) 255.255.255.255 128.187.3.1 (R1) Interface 1 Network 1 (Ethernet) Hn = Host Rn = Router H1 H2 H7 H3 R3 Network 4 (point-to-point) Network 2 (Ethernet) R1 Interface 0 R2 Interface 1 H4 Network 3 (Token Ring) H5 H8 H6 Dst=128.187.2.3 Dst=128.187.4.8 Dst=128.187.1.5 Routers? Hubs? Switches 128.187.173.X 128.187.171.X 171 H1 H2 H3 128.187.172.X 172 H4 H5 H6 Packet from H1 to H2 Packet from H1 to H10 Packet from H4 to broadcast H7 H8 H9 173 128.187.174.X Hub H10 H11 H12 Seen 171,172,173,174 Seen 171,172,173,174 Seen 171,172,173,174 174 Routers? Hubs? Switches/Bridges Learn from source Ethernet addresses (layer 2) 128.187.173.X 128.187.171.X 171 H1 H2 H3 128.187.172.X 172 H4 H5 H6 Packet from H1 to H2 Packet from H1 to H10 Packet from H4 to broadcast H7 H8 H9 173 128.187.174.X Switch H10 H11 H12 Seen 171 Seen 171,174 Seen 171,172,173,174 174 Routers? Hubs? Switches Use routing protocols and static configurations (layer 3) 128.187.173.X 128.187.171.X 171 H1 H2 H3 128.187.172.X 172 H4 H5 H6 Packet from H1 to H2 Packet from H1 to H10 Packet from H4 to broadcast H7 H8 H9 173 128.187.174.X Router H10 H11 Seen 171 Seen 171,174 Seen 172 H12 174 Routers? Hubs? Switches D 128.187.174.10 D 44.fe.34.56.32.d5 S 128.187.171.2 S fe.34.56.32.d5.29 171 H1 H2 D 128.187.174.10 D 44.fe.34.56.32.d5 S 128.187.171.2 S fe.34.56.32.d5.29 H3 H7 H8 H9 173 Hub 172 H4 H5 H6 D 128.187.174.10 D 44.fe.34.56.32.d5 S 128.187.171.2 S fe.34.56.32.d5.29 H10 H11 H12 D 128.187.174.10 D 44.fe.34.56.32.d5 S 128.187.171.2 S fe.34.56.32.d5.29 H10= IP 128.187.174.10, Ethernet 44.fe.34.56.32.d5 174 Routers? Hubs? Switches D 128.187.174.10 D 44.fe.34.56.32.d5 S 128.187.171.2 S fe.34.56.32.d5.29 171 H1 H2 Normally uses only Ethernet addresses H3 H7 H8 H9 173 Switch 172 H4 H5 H6 H10 H11 H12 D 128.187.174.10 D 44.fe.34.56.32.d5 S 128.187.171.2 S fe.34.56.32.d5.29 H10= IP 128.187.174.10, Ethernet 44.fe.34.56.32.d5 174 Routers? Hubs? Switches D 128.187.174.10 D 56.47.ef.c6.34.78 S 128.187.171.2 S fe.34.56.32.d5.29 171 H1 H2 Default Gateway H3 H7 H8 H9 173 56.47.ef.c6.34.78 Router 172 H4 H5 H6 H10 H11 H12 55.7e.c6.11.78.99 D 128.187.174.10 D 44.fe.34.56.32.d5 S 128.187.171.2 S 55.7e.c6.11.78.99 H10= IP 128.187.174.10, Ethernet 44.fe.34.56.32.d5 174 Our Department We have ethernet switches throughout the labs We have a router on the edge between us and the university Broadcast packets will be seen in most of the labs They wont go outside of the department Some administrators may block UDP broadcasts, because they fill every network link in the broadcast domain If you have a really bad bug in your program, you may bring down the network Perl Code Sender use IO::Socket::INET; $MySocket=new IO::Socket::INET->new( PeerPort=>1234,Proto=>'udp',PeerAddr=>'localhost'); $msg="This is the message"; $MySocket->send($msg); Receiver $MySocket=new IO::Socket::INET->new( LocalPort=>1234, Proto=>'udp') $MySocket->recv($text,128); print "\nReceived message '", $text,"'\n"; # Client Program use IO::Socket::INET; print ">> Client Program <<"; # Create a new socket $MySocket=new IO::Socket::INET->new(PeerPort=>1234,Proto=>'udp',Broadcast=>1, PeerAddr=>inet_ntoa(INADDR_BROADCAST)); # Send messages $def_msg="Enter message to send to server : "; print "\n",$def_msg; while($msg=<STDIN>) { chomp $msg; if($msg ne '') { print "\nSending message '",$msg,"'"; if($MySocket->send($msg)) { print ".....<done>","\n"; print $def_msg; } } else { # Send an empty message to server and exit $MySocket->send(''); exit 1; } } # Server Program use IO::Socket::INET; print ">> Server Program <<\n"; # Create a new socket $MySocket=new IO::Socket::INET->new(LocalPort=>1234,Proto=>'udp'); # Keep receiving messages from client $def_msg="\nReceiving message from client.....\n"; while(1) { $MySocket->recv($text,128); if($text ne '') { print "\nReceived message '", $text,"'\n"; } # If client message is empty exit else { print "Cilent has exited!"; exit 1; } } C Code Create a dgram socket sock = socket( AF_INET, SOCK_DGRAM, 0 ) setsockopt(sock, SOL_SOCKET, SO_BROADCAST,(char *) &one, sizeof(one)); Set the broadcast bit Bind to the port you want to receive on Recvfrom provides sender information in caller recvfrom( sock, buf, sizeof buf,0, (struct sockaddr *) &caller,&caller_len) Sendto parameter contains destination in socketname sendto(socket, buff,sendflags,(struct sockaddr *)&socketname, sizeof socketname ); Can be broadcast address Local URL Resolution Protocol Peer-to-Peer web-cache Bootstrapping & Peer Discovery Content Location UDP broadcast UDP broadcast for content Content Delivery Direct Download from single peer