Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > I

IP(7P)

HP-UX 11i Version 3: February 2007
» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

NAME

IP — Internet Protocol

SYNOPSIS

#include <sys/socket.h> #include <netinet/in.h> s = socket(AF_INET, SOCK_DGRAM, 0);

DESCRIPTION

IP is the network-layer protocol used by the Internet protocol family. It encapsulates TCP and UDP messages into datagrams to be transmitted by the network interface. Normally, applications do not need to interface directly to IP. However, certain multicast socket options are controlled by passing options to the IPPROTO_IP protocol level through a UDP socket, and IP Type of Service is controlled by passing an option to the IPPROTO_IP protocol level through either a TCP or UDP socket. (See the getsockopt(2) manual page.)

The following socket options are defined in the include file <netinet/in.h>. The type of the variable pointed to by the optval parameter is indicated in parentheses. The data types struct ip_mreq and struct in_addr are defined in <netinet/in.h>.

IP_TOS

(unsigned int) Sets the IP Type of Service. Allowable values for optval are 4 for high reliability, 8 for high throughput, and 16 for low delay. Other values will not return an error, but may have unpredictable results. Default: zero.

IP_ADD_MEMBERSHIP

(struct ip_mreq) Requests that the system join a multicast group.

IP_DROP_MEMBERSHIP

(struct ip_mreq) Allows the system to leave a multicast group.

IP_MULTICAST_IF

(struct in_addr) Specifies a network interface other than the default to be used when sending multicast datagrams through this socket. Default: multicast datagrams are sent from the interface associated with the specific multicast group, with the default multicast route or with the default route.

IP_MULTICAST_LOOP

(unsigned char; boolean) Enables or disables loopback in the IP layer for multicast datagrams sent through this socket. The value of the variable pointed to by optval is zero (disable) or non-zero (enable). This option is provided for compatibility only. Normally, multicast datagrams are always looped back if the system has joined the group. See DEPENDENCIES below. Default: enabled.

IP_MULTICAST_TTL

(unsigned char) Specifies the time-to-live value for multicast datagrams sent through this socket. The value of the variable pointed to by optval can be zero through 255. Default: one.

IP_ADD_MEMBERSHIP requests that the system join a multicast group on the specified interface. For example:

struct ip_mreq mreq; mreq.imr_multiaddr.s_addr = net_addr("224.1.2.3"); mreq.imr_interface.s_addr = INADDR_ANY; setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));

A system must join a group on an interface in order to receive multicast datagrams sent on the network to which that interface connects. If imr_interface is set to INADDR_ANY, the system joins the specified group on the interface that datagrams for that group would be sent from, based the routing configuration. Otherwise, imr_interface should be the IP address of a local interface. An application can join up to IP_MAX_MEMBERSHIPS multicast groups on each socket. IP_MAX_MEMBERSHIPS is defined in <netinet/in.h>. However, each network interface may impose a smaller system-wide limit because of interface resource limitations and because the system uses some link-layer multicast addresses.

The application must also bind to the destination port number in order to receive datagrams that are sent to that port number. If the application binds to the address INADDR_ANY, it may receive all datagrams that are sent to the port number. If the application binds to a multicast group address, it may receive only datagrams sent to that group and port number. It is not necessary to join a multicast group in order to send datagrams to it.

IP_DROP_MEMBERSHIP allows the system to leave a multicast group. For example:

struct ip_mreq mreq; mreq.imr_multiaddr.s_addr = net_addr("224.1.2.3"); mreq.imr_interface.s_addr = INADDR_ANY; setsockopt(s, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq));

The system remains a member of the multicast group until the last socket that joined the group is closed or has dropped membership in the group.

IP_MULTICAST_IF specifies a local network interface to be used when sending multicast datagrams through this socket. For example:

#include <arpa/inet.h> struct in_addr addr; addr.s_addr = inet_addr("192.1.2.3"); setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &addr, sizeof(addr));

Normally, applications do not need to specify the interface. By default, multicast datagrams are sent from the interface specified by the routing configuration, namely the interface associated with the specific multicast group, with the default multicast route or with the default route. If addr is set to the address INADDR_ANY, the default interface is selected. Otherwise, addr should be the IP address of a local interface.

IP_MULTICAST_LOOP enables or disables loopback for multicast datagrams sent through this socket. For example:

unsigned char loop = 1; setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop));

Note that the type of the optval parameter is unsigned char instead of int, which is common for boolean socket options. This option is provided for compatibility only. Normally, if a multicast datagram is sent to a group that the system has joined, a copy of the datagram is always looped back and delivered to any applications that are bound to the destination port. See DEPENDENCIES below.

IP_MULTICAST_TTL controls the scope a multicast by setting the time-to-live value for multicast datagrams sent through this socket. For example:

unsigned char ttl = 64; setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl));

Note that the type of optval parameter is unsigned char instead int, which is common for socket options. By default, the time-to-live field (TTL) is one, which limits the multicast to the local network. If the TTL is zero, the multicast is limited to the local system (loopback). If the TTL is two, the multicast can be forwarded through at most one gateway; and so forth. Multicast datagrams can be forwarded to other networks only if there are special multicast routers on the local and intermediate networks.

DEPENDENCIES

The behavior of IP_MULTICAST_LOOP depends on the network driver and interface card. Normally, loopback cannot be disabled, even if IP_MULTICAST_LOOP is set to zero, because it occurs in the driver or in the network interface. However, if the outbound interface is lo0 (127.0.0.1), or if IP_MULTICAST_TTL is set to zero, setting IP_MULTICAST_LOOP to zero will disable loopback for multicast datagrams sent through the socket.

ERRORS

One of the following errors may be returned if a call to setsockopt() or getsockopt() fails.

EADDRINUSE

The specified multicast group has been joined already on socket.

EADDRNOTAVAIL

The specified IP address is not a local interface address; or there is no route for the specified multicast address; or the specified multicast group has not been joined.

EINVAL

The parameter level is not IPPROTO_IP; or optval is the NULL address; or the specified multicast address is not valid.

ENOBUFS

Insufficient memory is available for internal system data structures.

ENOPROTOOPT

The parameter optname is not a valid socket option for the IPPROTO_IP level.

EOPNOTSUPP

The socket type is not SOCK_DGRAM.

ETOOMANYREFS

An attempt to join more than IP_MAX_MEMBERSHIPS multicast groups on a socket.

AUTHOR

The socket interfaces to IP were developed by the University of California, Berkeley. Multicast extensions were developed by the Stanford University.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.