Ejemplo n.º 1
0
int
udp_send_an_echo(UDPCLIENT udpclient)
{
   int   e;

   if ( udpclient->ticks > cticks )  
      return UDPE_TIME_NOT_RIPE ;

   udpclient->ticks += udpclient->delay;  /* Set time for sending next packet*/

   ns_printf(udpclient->pio,"sending UDP echo %ld to %s\n",
    udpclient->send_cnt,print_ipad(udpclient->rhost));

   sprintf(echodata + 17, "%-9lu", udpclient->send_cnt );
   e = t_send(udpclient->sock, echodata, udpclient->len, 0);
   if (e != udpclient->len)
   {
      e = t_errno(udpclient->sock);
      ns_printf(udpclient->pio,"error %d sending UDP echo number %ld\n", e, 
       udpclient->send_cnt );
      ns_printf(udpclient->pio,"UDP Echo Server at %s is possibly shut down\n",
         print_ipad(udpclient->rhost));
      udp_client_del(udpclient);
      return UDPE_ERR_SENDING_ECHO ;
   }

   udpclient->send_cnt ++;
   udpclient->tot_sent ++;

   return SUCCESS;
}
Ejemplo n.º 2
0
    kii_socket_code_t
socket_send_cb(
        kii_socket_context_t* socket_context,
        const char* buffer,
        size_t length)
{
    int ret;
    context_t* ctx = (context_t*)socket_context->app_context;
    char* buff = CUSTOM_ALLOC(length);

    memcpy(buff, buffer, length);
#if CONNECT_SSL
    ret = SSL_write(ctx->ssl, buff, length);
#else
    ret = t_send(handle, ctx->sock, (uint_8 *)buff, length, 0);
#endif

    CUSTOM_FREE(buff);

    if (ret > 0) {
        return KII_SOCKETC_OK;
    } else {
        printf("failed to send\n");
        socket_close_cb(socket_context);
        return KII_SOCKETC_FAIL;
    }
}
Ejemplo n.º 3
0
static void dump_stab()
{
    int i, j, c;
    stab_t *tstab;
    char buf[100];

    for (i=0; i<MAX_STAB; i++) {
       for (tstab=stab[i]; tstab; tstab=tstab->next) {
          for (j=0; j<tstab->len; j++) {
             c = tstab->str[j];
             if (c < 0x20 || c > 0x7F) {
                sprintf(buf, " 0x%x ", c);
                t_send(buf);
             } else {
                buf[0] = c;
                buf[1] = 0;
                t_sendl(buf, 1);
             }
          }
          sprintf(buf, " func=%d len=%d\n\r", tstab->func, tstab->len);
          t_send(buf);
       }
    }
}
Ejemplo n.º 4
0
/* ASCLRL() -- Clear to end of line from current position */
static void asclrl(int pos, int width)
{
   int i;

   if (t_cl) {
       t_send(t_cl);                 /* use clear to eol function */
       return;
   }
   if (pos==1 && linsdel_ok) {
       t_delete_line();              /* delete line */
       t_insert_line();              /* reinsert it */
       return;
   }
   for (i=1; i<=width-pos+1; i++)
       t_char(' ');                  /* last resort, blank it out */
   for (i=1; i<=width-pos+1; i++)    /* backspace to original position */
       t_char(0x8);
   return;

}
Ejemplo n.º 5
0
BOOL tcp_ipv6_send(HTCPCONN p_conn, const unsigned char *p_pucData, int p_nLen)
{
	if(p_conn==NULL)
	{
		C_NLOG_ERR("Iniche:tcp_ipv6_send: error, null connection");
		return FALSE;
	}
	if(((TSockEl*)p_conn)->sock == INVALID_SOCKET)
	{
		C_NLOG_ERR("Iniche:tcp_ipv6_send: error, invalid socket");
		return FALSE;
	}
	//C_NLOG_INFO("Iniche:tcp_ipv6_send: len = %d, buff=%s", p_nLen, (char*)p_pucData);
	if(t_send(((TSockEl*)p_conn)->sock, (char*)p_pucData,p_nLen,0) < 0)
	{
		C_NLOG_ERR("Iniche:tcp_ipv6_send: failed sending data,error %d",t_errno(((TSockEl*)p_conn)->sock));
		return FALSE;
	}
	return TRUE;
}
Ejemplo n.º 6
0
/* Honk horn on terminal */
static void
t_honk_horn()
{
   t_send(t_honk);
}
Ejemplo n.º 7
0
/* ASDELL -- Delete line at cursor */
static void asdell()
{
   t_send(t_dl);
}
Ejemplo n.º 8
0
/* ASINSL -- insert new line after cursor */
static void asinsl()
{
   t_clrline(0, t_width);
   t_send(t_il);                      /* insert before */
}
Ejemplo n.º 9
0
/* ASCLRS -- Clear whole screen */
static void asclrs()
{
   ascurs(0,0);
   t_send(t_cs);
}
Ejemplo n.º 10
0
/* ASCURS -- Set cursor position */
static void ascurs(int y, int x)
{
   t_send((char *)tgoto(t_cm, x, y));
}
Ejemplo n.º 11
0
int
t_sendto (long s, 
   char *   buf,
   int   len, 
   int   flags,
   struct sockaddr * to,
   int   tolen)
{
   struct socket *   so;
   int   sendlen;
   int   err;
   struct mbuf *     name;

   so = LONG2SO(s);
   SOC_CHECK(so);
   so->so_error = 0;

   switch (so->so_type)
   {
   case SOCK_STREAM:
      /* this is a stream socket, so pass this request through
       * t_send() for its large-send support.
       */
      return t_send(s, buf, len, flags);
      /*NOTREACHED*/
   case SOCK_DGRAM:
      /* datagram (UDP) socket -- prepare to check length */
      sendlen = udp_maxalloc();
      break;
#ifdef IP_RAW
   case SOCK_RAW:
      /* raw socket -- prepare to check length */
      sendlen = ip_raw_maxalloc(so->so_options & SO_HDRINCL);
      break;
#endif /* IP_RAW */
   default:
      /* socket has unknown type */
      dtrap();
      so->so_error = EFAULT;
      return SOCKET_ERROR;
      /*NOTREACHED*/
   }

   /* fall through for non-stream sockets: SOCK_DGRAM (UDP) and
    * SOCK_RAW (raw IP)
    */

   /* check length against underlying stack's maximum */
   if (len > sendlen)
   {
      so->so_error = EMSGSIZE;
      return SOCKET_ERROR;
   }

   /* if a sockaddr was passed, wrap it in an mbuf and pas it into the
    * bowels of the BSD code; else assume this is a bound UDP socket
    * and this call came from t_send() below.
    */

   if (to)  /* sockaddr was passed */
   {
      name = sockargs(to, tolen, MT_SONAME);
      if(name == NULL)
      {
         so->so_error = ENOMEM;
         return SOCKET_ERROR;
      }
   }
   else     /* hope user called bind() first... */
      name = NULL;
   
   sendlen = len;

   LOCK_NET_RESOURCE(NET_RESID);

   err = sosend (so, name, buf, &sendlen, flags);

   if (name)
      m_freem(name);

   UNLOCK_NET_RESOURCE(NET_RESID);

   if (err != 0)
   {
      so->so_error = err;
      return SOCKET_ERROR;
   }

   return (len - sendlen);
}