Porting applications to IPv6 HowTo
4 stars based on
This chapter describes the sockets-based communication facilities using IPv6. The socket call creates a socket in the specified domain of the specified type, as in the following example:. Following are all of the domains that are available:.
For example, to create a stream socket in the IPv6 domain, use the following entry:. Consider the following example:. This ipv6 socket bind example can be used only at declaration time. For example, the following code will not work:. Like the unspecified address, the IPv6 loopback address is also provided in two forms: It is also aligned at an appropriate boundary so that pointers to it can be cast as pointers to protocol specific address structures and they can be used to access the fields of those structures without alignment problems.
A server process normally opens a stream socket and listens at a particular port number for sevice requests. The client ipv6 socket bind example a connection to the server's address and port number by calling connect. At this point, the server wakes up and services the client request. Example is an example of a server program that creates an IPv6 socket and binds a name to that socket.
The port number on which the socket is to be bound is provided on the command line. The program calls listen to mark the socket as ready to accept incoming connections. In this example, the number of ipv6 socket bind example that the server can accept ipv6 socket bind example set to five.
Each pass of the loop accepts a new connection and creates a new socket. The server ipv6 socket bind example and displays the messages from the socket and closes it.
If the request is accepted, the connection is complete and the program can send data. The port number provided on the command line should match the port number provided on the command line for the server program. With datagram sockets, data can be exchanged without requiring ipv6 socket bind example establishment. The sendto call sends data on an unconnected datagram socket. You can use recvfrom to receive data on a datagram socket. Example is an example program that creates a datagram socket, binds a name to it, then reads from the socket.
Ipv6 socket bind example port number provided on the command line should match the port number that is provided on the command line for the server program. Example shows its usage:. Several socket options are available for sending and receiving IPv6 multicast packets.
The following sections describe those options. If the interface index is specified as 0, the system selects the interface to use. Here the argument type is unsigned int. In the following example, ifindex is the interface index for the desired outgoing interface. If it is not set, the default is 1. Here the argument type is int.
If this option is set to 0, a copy is not looped back. If this option is not set, the default is 1. The argument type is unsigned int. In the following example, loop is 0 to disable loopback and 1 to enable loopback.
The following sections describe sending and receiving IPv6 multicast datagrams. To send an IPv6 multicast datagram, specify an IP multicast address in the range ff By default, IPv6 multicast datagrams ipv6 socket bind example sent with a hop limit of 1, which prevents it from being forwarded beyond a single subnetwork.
IPv6 multicast datagrams with a hop limit of 0 are not transmitted on any subnet but can be delivered locally if the following conditions exist:. Multicast datagrams with a hop limit greater than 1 might be delivered to more than one subnetwork if there is at least one multicast router attached to the first-hop subnetwork.
The IPv6 multicast addresses contain scope information encoded in the first part of the address. Before a node can receive IP multicast datagrams for a given multicast address, it must become a member of the associated IP multicast group.
Each membership is associated with a single interface and it is possible to join the same group on more than one interface. The mreq argument contains the same values as those used to ipv6 socket bind example the membership. The socket drops associated memberships when the socket is closed or the process holding the socket is killed. However, more than one socket may claim a membership in a particular group, and the node will remain a member of that group until the last claim is dropped.
Sockets-based Communication Using IPv6. Creation of ipv6 socket bind example IPv6 Socket. Protocol Independent Socket Address Structure.
Server and Client Programs. Connection-based Server and Client. Connectionless Server and Client. Socket Option for IPv6 Only. Broadcasting is not supported in IPv6. It is ipv6 socket bind example only in IPv4. Sending IPv6 Multicast Datagrams. Ipv6 socket bind example sending node belongs to the destination group.
Multicast loopback on the sending socket is enabled. Receiving IPv6 Multicast Datagrams. Introduction to RPC Programming.