Thursday, March 29, 2012

An Overview of C Programming Language

C is a general purpose computer programming language. It was originally created by Dennis M. Ritchie (circa 1971) for the specific purpose of rewriting much of the Unix operating system. This now famous operating system was at that time in its infancy: it had recently been written for a discarded DEC PDP - 7 computer by Ken Thompson, an electrical engineer and a colleague of Ritchie's at Bell Labs. Thompson had written the first UNIX in a language he chose to call B. The intention of these programmers was to port UNIX on to other, architecturally dissimilar machines. Clearly, using any assembly language was out of the question: what was required was a language that would permit assembly-like (i.e. low or hardware level) operations, such as bit manipulation, and at the same time be run able on different computers. None of the languages then available could have served the purpose: a new one was called for, and C was born. The rest is history: UNIX became spectacularly successful, in large measure because of its portability, and C, in which most of it was written, has since come to occupy a pre-eminent position in die development of systems programs.

The success of UNIX, and the consequent popularity of C for systems programming, forced it on the attention of applications programmers, who came to appreciate the rich variety of its operators and its control structures. These enable, and in fact encourage, the practice of modular programming: the individual sub-tasks that make up a large program can be written in independent blocks or modules, each of manageable size. In other words, the language possesses features which make possible a "divide and conquer" approach to large programming tasks. When programs are organized as modules they are necessarily well-planned, because each module contains only the instructions for a well-defined activity. Such programs are therefore more easily comprehensible by other readers than unstructured programs.

Another desirable, quality of modular Programs is that they may be modified without much difficulty. If changes are required, only a few modules may be affected, leaving the remainder of the program intact.

And last but not least, such programs are easier to debug, because errors can be localized to modules, and removed. For a concrete example suppose that you have to write a program to determine all prime numbers up to ten million which are of the form k * k + 1, where k is an integer (2, 5, 17 and 37 are trivial examples of such primes). Then one module of the program could be written to generate the number k * k + 1 for the next admissible value of k; and another module to test whether the last number generated is a prime. Organized in this way, not only will the program be elegant, it would also be easy to debug, understand or modify.

Wednesday, February 1, 2012

Find the size of data types in C

This is a simple program to find the size of different basic data types in C Programming Language. I have added only four data types you can add more if you wish.
#include <stdio.h>
#include <malloc.h>

main()
{
int i;
printf("Size of an Integer \t=\t %d (Bytes)\n",sizeof(int));
printf("Size of a Character \t=\t %d (Bytes)\n",sizeof(char));
printf("Size of a Float \t=\t %d (Bytes)\n",sizeof(float));
printf("Size of a Double \t=\t %d (Bytes)\n",sizeof(double));
}



THE OUTPUT WILL BE LIKE THIS:

 


Tuesday, December 20, 2011

What is bridge in computer networking?

Segmenting a large network with a network device has numerous benefits. Among these are reduced collisions (in an Ethernet network), contained bandwidth utilization, and the ability to filter out unwanted packets. However, if the addition of the interconnect device required extensive reconfiguration of stations, the benefits of the device would be outweighed by the administrative overhead required to keep the network running. Bridges were created to allow network administrators to segment their networks transparently. This means that individual stations need not know whether there is a bridge separating them or not. It is up to the bridge to make sure that packets get properly forwarded to their destinations. This is the fundamental principle underlying all of the bridging behaviors.

Bridges work at the Data Link layer of the OSI model. Since bridges work in the Data Link layer they do not examine the network layer addresses. They just look at the MAC addresses for Ethernet and Token Ring, token bus and determine whether or not to forward or ignore a packet.

Functions of a Bridge
  1. Isolates networks by MAC addresses
  2. Manages network traffic by filtering packets
  3. Translates from one MAC protocol to another

Now let us examine the functionality of a bridge in detail.

1. Isolates networks by MAC addresses

A bridge divides a network into separate collision domains. This reduces congestion as only frames that need to be forwarded are sent across interfaces. All transmissions between nodes connected to same segment are not forwarded and therefore do not load the rest of the network.

Thus bridges effectively improve the bandwidth of the network by reducing the unnecessary traffic in the network.

For example, if you have one segment called Segment 100: it has 50 users (in several departments) using this network segment. The Engineering Department is CAD (Computer Aided Design) - oriented, while the Accounting Department is into heavy number crunching (year end reports, month end statements, etc.). On this network, any traffic between Clients of Accounting Department and the Accounting File Server (in the Accounting Department) will be heard across the Segment 100. Likewise, any traffic between the Engineering Dept clients (to the CAD File Server) will be heard throughout the Network Segment. The result is that “Other” Department accesses to the Generic File Server are incredibly slow: this is because of the unnecessary traffic that’s being generated from other departments (Engineering and Accounting).

The solution is to use one Bridge to isolate the Accounting Department, and another bridge to isolate the Engineering Department. The Bridges will only allow packets to pass through that are not on the local segment. The bridge will first check its “routing” table to see if the packet is on the local segment. If it is, it will ignore the packet, and not forward it to the remote segment. If Client of Accounting Department sends a packet to the Accounting File Server then Bridge #1 will check its routing table (to see if the Accounting File Server is on the local port). If it is on the local port, then Bridge #1 will not forward the packet to the other segments. If a Client of Accounting Department sends a packet to the Generic File Server, Bridge #1 will again check its routing table to see if the Generic File Server is on the local port. If it is not, then Bridge #1 will forward the packet to the remote port.

2. Manages network traffic by filtering packets

Bridges listen to the network traffic, and build an image of the network on each side of the bridge. This image of the network indicates the location of each node (and the bridge’s port that accesses it). With this information, a bridge can make a decision whether to forward the packet across the bridge - if the destination address is not on the same port - or, it can decide not to forward the packet (if the destination is on the same port).

This process of deciding whether or not to forward a packet is termed “filtering packets.” Network traffic is managed by deciding which packets can pass through the bridge; the bridge filters packets.

3. Translates from one protocol to another

The MAC layer also contains the bus arbitration method used by the network. This can be CSMA/CD, as used in Ethernet, or Token Passing, as used in Token Ring. Bridges are aware of the Bus Arbitration and special translation bridges can be used to translate between Ethernet and Token Ring LANs.

Bridges physically separate a network segment by managing the traffic (that’s based on the MAC address). Bridges are store and forward devices. They receive a packet on the local segment, store it, and wait for the remote segments to be clear before forwarding the packet. The two physical types of bridges are Local and Remote Bridges.


Monday, December 19, 2011

What are the functions of Repeaters

All types of network connections suffer from attenuation and pulse distortion. For a given cable specification and bit rate, each has a maximum length of cable. Repeaters can be used to increase the maximum interconnection length and will do the following:

Functions of Repeaters
  • Clean signal pulses.
  • Pass all signals between attached segments.
  • Boost signal power.
  • Possibly translate between two different media types (e.g., fiber – optic to twisted – pair cable)

Sunday, December 18, 2011

Stop and Wait Protocol

The sender allows one message to be transmitted, checked for errors and an appropriate ACK (Affirmative Acknowledgement) or NAK (Negative Acknowledgement) returned to the sending station. No other data messages can be transmitted until the receiving station sends back a reply, thus the name STOP and WAIT is derived from the originating station sending a message, stopping further transmission and waiting for a reply.

Its major drawback is the idle line time that results when the stations are in the waiting period. If the ACK is lost then the sending station retransmits the same message to the receiver side. The redundant transmission could possibly create a duplicate frame. A typical approach to solve this problem is the provision for a sequence number in the header of the message. The receiver can then check for the sequence number to determine if the message is a duplicate. The Stop and Wait mechanism requires a very small sequence Number, since only one message is outstanding at any time. The sending and receiving station only use a one bit alternating sequence of 0 and 1 to maintain the relationship of the transmitted message and its ACK/NAK status.




Frequency Division & Time Division Multiplexing

Frequency Division Multiplexing (FDM)

In FDM the frequency spectrum is divided to form logical channels with each user having exclusive possession of the assigned channel.

Time Division Multiplexing (TDM)

In TDM, the users take turns (in a round robin); each one is periodically getting the entire bandwidth for the allotted time.

Television broadcasting provides an example of multiplexing. Each TV channel operates in a different frequency range, which is a portion of the allocated spectrum, with the inter-channel separation great enough to prevent interference. This system is an example of FDM. During the transmission of any program (Serial/film), there is an advertisement as well. These two alternate in time on the same frequency. This is an example of TDM.

What is Multiplexing?

In communication, Multiplexing is a technique that transmits signals from several sources over a single communication channel. So in order to minimize the cost of communication bearer, various techniques of sharing a communication channel between several users have been devised. These are known as multiplexing techniques.

Broadband Coaxial Cable

The other kind of coaxial cable systems uses analog transmission on standard cable television cabling. These can be used for digital data transfer also. It is cabled broadband. Although the term “broadband” comes from the telephone world, where it refers to anything wider than 4 kHz, in the computer networking world “broadband cable” means any cable network using analog transmission.

Since broadband networks use standard cable television technology, the cables can be used up to 300 MHz (and often up to 450 MHz) and can run for nearly 100 km due to the analog signaling, which is much less critical than digital signaling. To transmit digital signals on an analog network, each interface must contain electronics to convert the outgoing bit stream to an analog signal, and the incoming analog signal to a bit stream. Depending on the type of these electronics 1 bps may occupy roughly 1 Hz of bandwidth. At higher frequencies, many bits per Hz are possible using advanced modulation techniques.

Broadband systems are divided up into multiple channels. Frequently the 6MHz channels are used for television broadcasting. Each channel can be used for analog television, CD-quality audio or a digital bit stream at, say 3 Mbps, independent of the others. Television and data can be mixed on one cable.

Baseband Coaxial Cable

Another communication transmission medium is the coaxial cable. It has better shielding than twisted pairs, so it can span longer distances at higher speeds. Two kinds of coaxial cable are widely used. One kind, 50-ohm cable is commonly used for digital transmission and is the subject of this section. The other kind, 75-ohm cable, is commonly used for analog transmission and will be described in the next section. This distinction is based on historical, rather than technical factor, (e.g., early dipole antennas had an impedance of 300 ohms, and it was easy to build 4:1 impedance matching transformers).

A coaxial cable consists of a stiff copper wire as the core, surrounded by an insulating material. The construction and shielding of the coaxial cable give it a good combination of high bandwidth and excellent noise immunity. The bandwidth possible depends on the cable length. For 1 km cables, a data rate 1 or 2 Gbps is feasible. Longer cables can also be used, to be widely used within the telephone systems but have not largely been replaced by fiber optics on long-haul routes. In the United States alone, 1000 km of fiber is installed every day (counting a 100 km bundle with 10 strands of fiber as 1000 km). Coaxial cables are still widely used for cable television and some local area networks.

Twisted Pair Cables

The oldest and still most common transmission medium is twisted pair. A twisted pair consists of two insulated copper wires, typically about 1 mm thick. The wires are twisted together in a helical form. The purpose of twisting the wires is to reduce electrical interference from similar pairs close by.

The most common application of the twisted pair is the telephone systems. Twisted pairs can be used for either analog or digital transmission. The bandwidth depends on the thickness of the wire and the distance traveled, but several megabits/sec. can be achieved for a few kilometers in many cases. Due to their adequate performance and low cost, twisted pairs are widely used and are likely to remain so for years to come. Twisted pair cabling comes in several varieties, two of which are important for computer networks. Category 3 twisted pairs consist of two insulated wires gently twisted together. Four such pairs are typically grouped together in a plastic sheath for protection and to keep the eight wires together.

Starting around 1988, the more advanced category 5 twisted pairs were introduced. They are similar to category 3 pairs, but with more twists per centimeter and insulation, which results in less cross talk and a better quality signal over longer distances, making them more suitable for high–speed computer communication. Both of these wiring types are often referred to as UTP (Unshielded Twisted Pair), to contrast them with the bulky, expensive, shielded twisted pair cables IBM introduced in the early 1980s, but which have not proven popular outside of IBM installations.