DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Developing applications over TCP/IP using TLI

Example

This example uses options management to request that the TLI endpoint be configured to allow the sending of broadcast datagrams.

In this example, fd represents a UDP endpoint obtained by using t_open on _PATH_UDP (defined in <paths.h>).

\#include <sys/types.h>
\#include <sys/socket.h>
\#include <netinet/in.h>
\#include <tiuser.h>
\#include <fcntl.h>
\#include <paths.h>
    .
    .
    int fd, r;

fd = t_open(_PATH_UDP, O_RDWR, (struct t_info *)0); . . r = tli_set_broadcast(fd); . .

int tli_set_broadcast(fd) int fd; { struct t_optmgmt *opt; struct opthdr *ohdr;

/* use t_alloc to acquire a t_optmgmt structure */ if (!(opt = (struct t_optmgmt *) t_alloc(fd, T_OPTMGMT, T_ALL))) { fprintf(stderr, "Couldn't allocate t_optmgmt\n"); return -1; } /* set ohdr to point at the optmgmt structure */ ohdr = (struct opthdr *) opt->opt.buf; ohdr->level = SOL_SOCKET; /* generic option */ ohdr->name = SO_BROADCAST; /* desire broadcast ability */ ohdr->len = OPTLEN(sizeof(int)); /* rounds length by sizeof(long) */

/* store desired value immediately following the opthdr */ *((int *) OPTVAL(ohdr)) = 1; /* 1 means turn on */ opt->opt.len = sizeof(struct opthdr) + OPTLEN(sizeof(int)); opt->flags = T_NEGOTIATE; /* change current value */ if (t_optmgmt(fd, opt, opt) < 0) { fprintf(stderr,"Options management failed\n"); return -1; } (void) t_free(opt, T_OPTMGMT); return 0; }


Next topic: How TLI functions behave over TCP and UDP
Previous topic: Transport provider option management

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003