The purpose of this guide is to explore the various networking options offered by the Linux kernel. The network hardware independent functions (protocol stacks, list of filters, etc..) Are grouped into the Networking and Networking Options menu. The network device drivers are available from menus and then Device Drivers Network device support.
1. Packet Socket
This feature is used to receive and send raw packets on the network devices without passing through a network protocol implemented in the kernel. Some programs, such as tcpdump, use this option. The term "socket" means the programming interface through which we will be able to access network resources from the nucleus. Creating an interface "socket" is performed by the system call as follows:
Code:
int socket ( family type, Protocol ) ;
int family ;
int type ;
int protocol ;
The 'family' is used to identify with any network protocol you want to work. All obtainable families is listed in the file /usr/include/linux/socket.h. Types define the transport protocol (TCP or UDP). A new socket family associated with this feature is available as well, namely AF_PACKET.
IO mapped
This option uses a mechanism of input-output faster.
Example 1. Using the packet socket
Code:
Stdio.h
# Include <sys/socket.h>
# Include <sys/ioctl.h>
# Include <net/if.h>
# Include <linux/if_ether.h>
# Include <linux/if_packet.h>
main ()
(
int sock_fd;
struct sll sockaddr_ll;
struct ifreq ifr;
char buffer [2000];
int nb_octet;
if (sock_fd = socket (AF_PACKET, SOCK_RAW, htons (ETH_P_ALL)) == -1) (
printf ("Error creating socket \ n");
return-1;
)
memset (& ifr, 0, sizeof (ifr));
strncpy (ifr.ifr_name, "eth0", sizeof (ifr.ifr_name));
if (ioctl (sock_fd, SIOCGIFINDEX, & ifr) == -1) (
printf ("Error in the search index \ n");
return -1;
)
memset (& sll, 0, sizeof (sll));
sll.sll_family = AF_PACKET;
sll.sll_ifindex = ifr.ifr_ifindex;
sll.sll_protocol = htons (ETH_P_ALL);
if (bind (sock_fd, (struct sockaddr *) & sll, sizeof (sll)) == -1) (
printf ("Error with bind \ n");
return -1;
);
nb_octet = recvfrom (sock_fd, buffer, sizeof (buffer), 0, NULL, 0);
printf ("Number of bytes received:% d \ n", nb_octet);
)
2. Kernel / User netlink socket
Kernel / User netlink socket: Sets a new socket family, AF_NETLINK. This socket allows for bidirectional communication between the kernel and user space. This option is required to use the tool iproute2 which allows the configuration of the network portion of the nucleus. In addition to this socket, communication can also be achieved for a user process, by reading or writing files special characters. These are special files major number 36 and are in the directory /dev .
Routing Messages
The kernel provides routing information via the file /dev/route with major number 36 and minor number 0.
Netlink device emulation
Allows compatibility with older features. Option led to disappear.
3. Socket Filtering
This feature allows, in user-mode programs, setting up filters at the sockets. It has the ability to authorize or prohibit the types of data through a socket. This feature is derived from the Berkeley Packet Filter.
Bookmarks