#pragma module SIP_NETIO "SIP_NETIO-1-A" #define __MODULE__ "SIP_NETIO" /* **++ ** FACILITY: SIP Client - Command Line Utility ** ** MODULE DESCRIPTION: ** ** This module contaions low-level network I/O routines. ** ** AUTHORS: Ruslan R. Laishev ** ** ** CREATION DATE: 27-APR-2009 ** ** ** MODIFICATION HISTORY: ** **-- */ /* ** ** INCLUDE FILES ** */ #include #include #include #include #include #include #include #include #include #include #include #include #define __NEW_STARLET 1 #include $DESCRIPTOR(dsc_ucxdev,"UCX$DEVICE"); $DESCRIPTOR(dsc_tcpipdev,"TCPIP$DEVICE"); int netio_close ( short chan ) { return sys$dassgn (chan); } int netio_reset ( short chan ) { return sys$cancel(chan); } int netio_open ( short *chan, struct sockaddr_in *home ) { int status; struct { short proto; char type; char domain; } sck_parm = {INET$C_UDP,INET_PROTYP$C_DGRAM,INET$C_AF_INET}; iosb netiosb; ILE2 lhst_adrs = {sizeof(struct sockaddr_in),0,home}; short sz = 32000; ILE2 sock_opt = {sizeof(int),INET$C_RCVBUF,&sz}; ILE2 itm_lst = {sizeof(ILE2),INET$C_SOCKOPT,&sock_opt}; *chan = 0; if ( !home->sin_addr.s_addr && !home->sin_port ) return SS$_NORMAL; /* ** Assign a channel to device */ if ( !(1 & (status = sys$assign( &dsc_ucxdev,chan,0,0))) ) { if ( status != SS$_NOSUCHDEV ) return status; if ( !(1 & (status = sys$assign( &dsc_tcpipdev,chan,0,0))) ) return status; } /* ** Bind a socket to the given local address, and set a receive buffer size */ status = sys$qiow (0,*chan,IO$_SETMODE,&netiosb, 0,0,&sck_parm,0,&lhst_adrs,0,&itm_lst,0); return (1 & status)?netiosb.iosb$w_status:status; } int netio_read ( short chan, char *buf, short buflen, short *retlen, struct sockaddr_in *remhost ) { int status,remhostlen = 0; iosb netiosb; ILE3 rsck_adrs = {sizeof(struct sockaddr_in),0,remhost,&remhostlen}; *retlen = 0; if ( !(1 & (status = sys$qiow (EFN$C_ENF,chan,IO$_READVBLK,&netiosb,0,0, buf,buflen,&rsck_adrs,0,0,0))) || !(netiosb.iosb$w_status & 1) ) return (1 & status)?netiosb.iosb$w_status:status; *retlen = netiosb.iosb$w_bcnt; return status; } int netio_write ( short chan, char *buf, short buflen, struct sockaddr_in *remhost, char *buf2, short buf2len ) { int status,remhostlen = 0; iosb netiosb; ILE3 rsck_adrs = {sizeof(struct sockaddr_in),0,remhost,&remhostlen}; struct {unsigned l; char *a;} bvec[] = { {buflen,buf},{buf2len,buf2}}; struct dsc$descriptor buf_d = { 0, DSC$K_CLASS_S, DSC$K_DTYPE_T, 0} ; /* ** Setup the buffer descriptor */ buf_d.dsc$a_pointer = (char *) &bvec; if ( buf2 && buflen ) buf_d.dsc$w_length = sizeof(bvec); else buf_d.dsc$w_length = sizeof(bvec[0]); status = sys$qiow (EFN$C_ENF,chan,IO$_WRITEVBLK,&netiosb,0,0, 0,0,&rsck_adrs,0,&buf_d,0); return (1 & status)?netiosb.iosb$w_status:status; }