You are on page 1of 4

7/21/2017

Topics
• ioctl
Introduction to Advanced • sysctl
Sockets • Broadcasting
• Ping
Harshad B. Prajapati
• Traceroute
Associate Professor
Information Technology Department,
Dharmsinh Desai University, Nadiad

ioctl ioctl
• The ioctl is for input/output control (device). #include <sys/ioctl.h>
• The ioctl() function manipulates the underlying int ioctl(int d, int request, ... /* void * arg */);
device parameters of special files. • d: must be an open file descriptor.
• request: device-dependent request code.
• many operating characteristics of character special
• Third argument: void pointer
files (e.g. terminals) may be controlled with ioctl()
requests.
• Usually, on success zero is returned.
• It is a system call for device-specific operations and
• On error, -1 is returned, and errno is set appropriately.
other operations which cannot be expressed by
• A few ioctl() requests use the return value as an output
regular system calls. parameter and return a nonnegative value on success.
• Request codes are often device-specific.

ioctl ioctl
• Different control operations are provided by ioctl. • Socket operations (Datatype: int)
• Each category of calls work with different data-type (to third – Requests begin with SIOC
argument of the call). • Knowing read pointer is at out-of-band mark
• Categories of ioctl operations • Knowing process ID or the process group ID is set to receive the
– Socket operations (Datatype: int) SIGIO or SIGURG signal for this socket.
– File operations (Datatype: int) • Setting either process ID or the process group ID to receive the
SIGIO or SIGURG signal for this socket.
– Interface configuration operations (Datatype: struct ifconf, struct ifreq)
– ARP cache operations (Datatype: struct arpreq)
– Routing operation (Datatype: struct rtentry)

1
7/21/2017

ioctl ioctl
• File operations (Datatype: int) • Interface configuration operations (Datatype: struct
– Requests begin with FIO ifconf, struct ifreq)
– It applies to certain type of files in addition to sockets. – Request begin with
– Operations • Get : SIOCGIF
• Set: SIOCSIF
• Setting socket for non-blocking I/O.
• Setting socket for asynchronous I/O. – E.g., usage: Knowing all interfaces configured on the
• Know number of bytes in socket receive buffer. This feature also system.
works for files, pipes, and terminals. – How to use
• Set/Get owner of receiving SIGIO or SIGURG signals. • You need to allocate a buffer in case you want to get information
from the system.
• Allocate space for ifconf structure.
• Then call ioctl.
• It involves manipulation on linked list.

ioctl ioctl
• Interface configuration operations • ARP cache operations (Datatype: struct arpreq)
– It involves various operations related to interface. – Requests
– The GUI based network interface setting and ifconfig • Set (add) new entry to ARP cache: SIOCSARP
command internally use the ioctl call. • Delete entry from ARP cache : SIOCDARP
• Get entry from ARP cache : SIOCGARP
– Most common operations are
• Setting subnet mask.
• Getting subnet mask.
• Getting broadcast address.
• Setting broadcast address.

ioctl sysctl
• Routing operation (Datatype: struct rtentry) • The sysctl system call exports the ability to fine-tune
• Requests kernel parameters.
– Add an entry to routing table: SIOCADDRT • For network related operations, use CTL_NET as
– Delete an entry from routing table: SIOCDELRT element name.

2
7/21/2017

sysctl Broadcasting
• Sub-element names: • TCP works with only unicast address.
– AF_INET:
• Get or Set variables affecting the Internet protocols
• Multicasting support is optional in IPv4 but
– AF_LINK mandatory in IPv6.
• Get or set link-layer information • Broadcasting support is not provided in IPv6.
– AF_ROUTE
• Information on either routing table or the interface list.
• Broadcasting and Multicasting require UDP.
– AF_UNSPEC They do not work with TCP.
• Get or set some socket layer variables, such as the maximum size
of socket send or receive buffer.

Broadcasting Broadcasting
• Use of broadcasting • Broadcast address
– Resource discovery: Locate a server on the local If we denote an IPv4 address as {netid, subnetid, hostid},
subnet but the unicast IP address of the server is then we have four types of broadcast address.
not known. – 1. Subnet directed broadcast address:
• {netid,subnetid,255}. It addresses all the interfaces on the
– Knowing hardware address of networked specified subnet.
machine. Used by ARP. • Routers normally do not forward these broadcasts
– Routing daemons (routed) broadcasts its routing – 2. All subnets directed broadcast address:
• {netid,255,255}. Addresses all subnets on the specified network
table on LAN.
– 3. Network directed broadcast address:
• {netid, 255}.A network that does not use subnetting.
– 4. Limited broadcast address:
• {255.255.255.255}. Routers must not forward these broadcasts.

Broadcasting Ping
• ICMP port unreachable error is not generated • Ping is used to check whether a networked node is
for broadcast packet to avoid broadcast storm. reachable.
• Raw socket is used by ping. I.e., SOCK_RAW.
• An ICMP echo request is sent to some IP address and
that node responds with an ICMP echo reply.
• Identifier, sequence number, and any optional data
are placed in echo request and they are returned in
echo reply.
– If we place timestamp in the packet, we can calculate RTT
when the reply is received.

3
7/21/2017

Traceroute
• The traceroute lets us determine the path that IP datagram
follow from our host to some other destination.
• Traceroute uses the IPv4 TTL field.
• Working
– Send a UDP datagram to the destination host with a TTL (or hop limit)
of 1.
– This datagram causes the first hop router to return an ICMP “time
exceeded in transit ” error.
– The TTL is then increased by one and another UDP datagram is sent,
which locates the next router in the path.
– When the UDP datagram reaches the final destination, that host
returns ICMP “port unreachable” error.

You might also like