<< Previous | Index | Next >>

udp_extopen


int udp_extopen( udp_Socket *s, int iface, word lport,
longword remip, word port, dataHandler_t datahandler,
long buffer, int buflen );

Description

This function is an extended version of udp_open(). It opens a socket on a given network interface (iface) on a given local port (lport). If the remote IP address is specified (remip), then only UDP datagrams from that host will be accepted.

The remote end of the connection is specified by remip and port. The following table explains the possible combinations and what they mean.

REMIP
Effect of REMIP value

0

The connection completes when the first datagram is received, supplying both the remote IP address and the remote port number. Only datagrams received from that IP/port address will be accepted.

-1

All remote hosts can send datagrams to the socket. All outgoing datagrams will be sent to the broadcast address unless udp_sendto() specifies otherwise.

>0

If the remote IP address is a valid IP address and the remote port is 0, the connection will complete when the first datagram is received, supplying the remote port number. If the remote IP address and the remote port are both specified when the function is called, the connection is complete at that point.

The buffer and buflen parameters allow a user to supply a socket buffer, instead of using a socket buffer from the pool.

If remip is non-zero, then the process of resolving the correct destination hardware address is started. Datagrams cannot be sent until sock_resolved() returns TRUE. If you attempt to send datagrams before this, then the datagrams may not get sent. The exception to this is if remip is -1 (broadcast) in which case datagrams may be sent immediately after calling this function.

This function also works with multicast addresses. If remip is a multicast address, then packets sent with this function will go to the multicast address, and packets received will also be from that multicast address. Also, if enabled, IGMP will be used to join the multicast groups. The group will be left when the socket is closed. Note that if port is 0 and remip is a multicast address, the port will not be filled in on the first received datagram (that is, the socket is non-binding to the port).

Parameters

s

Pointer to socket.

iface

Local interface on which to open the socket. Use IF_ANY if the socket is to accept datagrams from any interface. Otherwise, datagrams will be accepted only from the specified interface.

This parameter is supported as of Dynamic C 7.30. With earlier version of DC, this parameter should be IF_DEFAULT.

lport

Local port.

remip

Acceptable remote IP, or 0 for all.

port

Acceptable remote port, or 0 for all.

datahandler

Function to call when data is received, NULL for placing data in the socket's receive buffer.

buffer

Address of user-supplied socket buffer in xmem. If buffer is 0, the socket buffer for this socket is pulled from the buffer pool defined by the macro MAX_UDP_SOCKET_BUFFERS.

buflen

Length of user-supplied socket buffer.

Return value:

!0: Success.
 0: Failure; error opening socket, e.g., a buffer could not be allocated.

Library

UDP.LIB

See Also

udp_open, sock_resolved


TCP/IP Manual
Vol 1
<<Previous | Index | Next>> rabbit.com