Network Programming
Network Programming
• They are not recognized globally (assigned for local use only).
➢ Each layer adds information to the data by prepending headers (and sometimes
adding trailer information) to the data that it receives.
➢ The unit of data that IP sends to the network interface is called a packet (IP
datagram).
➢ The stream of bits that flows across the Ethernet is called a frame.
➢ The numbers at the bottom of the headers and trailer of the Ethernet frame in the
Figure are the typical sizes of the headers in bytes.
➢ A physical property of an Ethernet frame is that the size of its data must be between
46 and 1500 bytes.
➢ We could draw a nearly identical picture for UDP data. The only changes are that the
unit of information that UDP passes to IP is called a UDP datagram, and the size of
the UDP header is 8 bytes.
➢ IP must add some type of identifier to the IP header that it generates, to indicate the
layer to which the data belongs.
➢ IP handles this by storing an 8-bit value in its header called the protocol field. A value
of 1 is for ICMP, 2 is for IGMP, 6 indicates TCP, and 17 is for UDP.
➢ Similarly, many different applications can be using TCP or UDP at anyone time.
➢ The transport layer protocols store an identifier in the headers they generate to
identify the application.
➢ Both TCP and UDP use 16-bit port numbers to identify applications.
➢ TCP and UDP store the source port number and the destination port number in their
respective headers.
➢ The network interface sends and receives frames on behalf of IP, ARP, and RARP.
➢ There must be some form of identification in the Ethernet header indicating which
protocol generated the data.
➢ To handle this there is a 16-bit frame type field in the Ethernet header.
➢ Many administrators use the natural 8-bit boundary in the 16 bits of a class B host ID
as the subnet boundary.
➢ This makes it easier to determine the subnet ID from a dotted-decimal number, but
there is no requirement that the subnet boundary for a class A or class B address be
on a byte boundary.
➢ Subnetting is also allowed for a class C address, but there are fewer bits to work
with.
➢ Subnetting is rarely shown with a class D address because there are so few available
bits allocated to host ID.
➢ Get port number, given the service name and protocol type.
>>> service_name="ftp"
>>> print(getservbyname(service_name)) 21
>>> print(getservbyname(service_name,"tcp")) 21
Note by default the protocol type is tcp.