1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
/* Les includes */
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/sem.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <xti.h>
#if 0
#include <tiuser.h>
#endif
...
/* definitions des variables locales */
int i_cr_tli ; /* Code retour fonctions TLI */
int i_cr ; /* Code retour */
int tfd ; /* Descripteur stream TCP */
struct t_info st_info ; /* Infos service transport */
struct sockaddr_in st_adr_serv ; /* Adresse serveur */
struct t_bind st_bind ; /* Structure pour bind */
struct t_bind *pst_bind_ret = NULL; /* Structure retour bind */
struct t_optmgmt st_opt_req ; /* Options demandees */
struct t_optmgmt st_opt_ret ; /* Options rendues */
char tc_opt_req[100] ; /* Buffer options demandees */
char tc_opt_ret[100] ; /* Buffer options rendues */
struct t_opthdr *pst_sockopt ; /* Option socket */
long l_opt ;
/* code d'appel aux fonctions reseaux */
i_cr_tli = NOK ;
i_cr = NOK ;
/* Ouverture STREAM */
tfd = tli_t_open(C_TLI_DEVICE, O_RDWR|O_NDELAY|O_NONBLOCK, &st_info) ;
pst_etat_stream->fd = tfd ;
st_adr_serv.sin_addr.s_addr = htonl(INADDR_ANY);
st_adr_serv.sin_port = htons(pst_etat_stream->port_appele) ;
/* Bind */
st_bind.addr.maxlen = sizeof(st_adr_serv) ;
st_bind.addr.len = sizeof(st_adr_serv) ;
st_bind.addr.buf = (char *) &st_adr_serv ;
st_bind.qlen = 5 ;
/* Allocation structure retour fonction t_bind */
pst_bind_ret = (struct t_bind *)t_alloc(tfd, T_BIND, T_ALL) ;
i_cr_tli = tli_t_bind (tfd, &st_bind, (struct t_bind *)pst_bind_ret) ;
/* Option SO_REUSEADDR pour que le port specifie puisse etre reutilise */
/* Structure entree */
memset ((char *)&st_opt_req, 0, sizeof(st_opt_req)) ;
st_opt_req.opt.len = OPTLEN(sizeof(struct t_opthdr) + sizeof(long)) ;
st_opt_req.opt.maxlen = sizeof(tc_opt_req) ;
st_opt_req.opt.buf = tc_opt_req ;
st_opt_req.flags = T_NEGOTIATE ;
/* Structure rendue */
memset ((char *)&st_opt_ret, 0, sizeof(st_opt_ret)) ;
st_opt_ret.opt.len = 0 ;
st_opt_ret.opt.maxlen = sizeof(tc_opt_ret) ;
st_opt_ret.opt.buf = tc_opt_ret ;
st_opt_ret.flags = 0;
/* Option demandee */
l_opt = 1 ;
pst_sockopt = (struct t_opthdr *)tc_opt_req ;
pst_sockopt->len = OPTLEN(sizeof(long)) ;
pst_sockopt->level = SOL_SOCKET ;
pst_sockopt->name = SO_REUSEADDR ;
memcpy((char *)&pst_sockopt[1], (char *)&l_opt, pst_sockopt->len);
i_cr_tli = t_optmgmt(tfd, &st_opt_req, &st_opt_ret) ;
if (i_cr_tli < 0)
{
/* Erreur */
tli_close (pst_etat_stream->fd) ;
pst_etat_stream->etat = CP_CNX_EN_ERREUR ;
pst_etat_stream->fd = -1 ;
...
} |
Partager