Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ sendto(2) — OSF/1 3.0 αXP

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

recv(2)

recvfrom(2)

recvmsg(2)

send(2)

sendmsg(2)

shutdown(2)

socket(2)

select(2)

getsockopt(2)

setsockopt(2)

sendto(2)  —  System Calls

NAME

sendto − Sends messages through a socket

SYNOPSIS

#include <sys/types.h> #include <sys/socket.h> int sendto (
int socket,
char ∗message_addr,
int length,
int flags,
struct sockaddr ∗dest_addr,
int dest_len );

PARAMETERS

socketSpecifies the unique name for the socket. 

message_addr
Points to the address containing the message to be sent.

lengthSpecifies the size of the message in bytes. 

flagsAllows the sender to control the message transmission.  The flags value to send a call is formed by logically ORing the following values, defined in the sys/socket.h file:

MSG_OOBProcesses out-of-band data on sockets that support out-of-band data. 

MSG_DONTROUTE
Sends without using routing tables.  (Not recommended, for debugging purposes only.)

dest_addrPoints to a sockaddr structure, the format of which is determined by the domain and by the behavior requested for the socket.  The sockaddr structure is an overlay for a sockaddr_in, sockaddr_un, or sockaddr_ns structure, depending on which of the supported address families is active.  If the compile-time option _SOCKADDR_LEN is defined before the sys/socket.h header file is included, the sockaddr structure takes 4.4BSD behavior, with a field for specifying the length of the socket address.  Otherwise, the default 4.3BSD sockaddr structure is used, with the length of the socket address assumed to be 14 bytes or less.  If _SOCKADDR_LEN is defined, the 4.3BSD sockaddr structure is defined with the name osockaddr. 

dest_lenSpecifies the length of the sockaddr structure pointed to by the dest_addr parameter. 

DESCRIPTION

The sendto() function allows an application program to send messages through an unconnected socket by specifying a destination address. 

To broadcast on a socket, issue a setsockopt() function using the SO_BROADCAST option to gain broadcast permissions. 

Use the dest_addr parameter to provide the address of the target.  Specify the length of the message with the length parameter. 

If the sending socket has no space to hold the message to be transmitted, the sendto() function blocks unless the socket is in a nonblocking I/O mode. 

Use the select() function to determine when it is possible to send more data. 

RETURN VALUES

Upon successful completion, the sendto() function returns the number of characters sent.  Otherwise, the a value of -1 is returned, and errno is set to indicate the error. 

ERRORS

If the sendto() function fails, errno may be set to one of the following values:

[EBADF]The socket parameter is not valid. 

[ENOTSOCK]
The socket parameter refers to a file, not a socket. 

[EFAULT]The dest_addr parameter is not in a writable part of the user address space. 

[EMSGSIZE]The message is too large to be sent all at once, as the socket requires. 

[EWOULDBLOCK]
The socket is marked nonblocking, and no space is available for the sendto() function. 

RELATED INFORMATION

Functions: recv(2), recvfrom(2), recvmsg(2), send(2), sendmsg(2), shutdown(2), socket(2), select(2), getsockopt(2), setsockopt(2)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026