• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ sock_send函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中sock_send函数的典型用法代码示例。如果您正苦于以下问题:C++ sock_send函数的具体用法?C++ sock_send怎么用?C++ sock_send使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了sock_send函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: daemon_getstats

int daemon_getstats(pcap_t *fp)
{
char sendbuf[RPCAP_NETBUF_SIZE];	// temporary buffer in which data to be sent is buffered
int sendbufidx= 0;					// index which keeps the number of bytes currently buffered
struct pcap_stat stats;				// local statistics
struct rpcap_stats *netstats;		// statistics sent on the network

	if ( sock_bufferize(NULL, sizeof(struct rpcap_header), NULL, &sendbufidx, RPCAP_NETBUF_SIZE, SOCKBUF_CHECKONLY, fp->errbuf) == -1)
		goto error;

	rpcap_createhdr( (struct rpcap_header *) sendbuf, RPCAP_MSG_STATS_REPLY, 0, (uint16) sizeof(struct rpcap_stats));

	netstats= (struct rpcap_stats *) &sendbuf[sendbufidx];

	if ( sock_bufferize(NULL, sizeof(struct rpcap_stats), NULL, &sendbufidx, RPCAP_NETBUF_SIZE, SOCKBUF_CHECKONLY, fp->errbuf) == -1)
		goto error;

	if (pcap_stats(fp, &stats) )
		goto error;

	netstats->ifdrop= htonl(stats.ps_ifdrop);
	netstats->ifrecv= htonl(stats.ps_recv);
	netstats->krnldrop= htonl(stats.ps_drop);
	netstats->svrcapt= htonl(fp->md.TotCapt);

	// Send the packet
	if ( sock_send(fp->rmt_sockctrl, sendbuf, sendbufidx, fp->errbuf) == -1)
		goto error;

	return 0;

error:
	rpcap_senderror(fp->rmt_sockctrl, fp->errbuf, PCAP_ERR_GETSTATS, fakeerrbuf);
	return -1;
}
开发者ID:kubuqi,项目名称:802.1x-supplicant,代码行数:35,代码来源:daemon.c


示例2: daemon_updatefilter

int daemon_updatefilter(pcap_t *fp, uint32 plen)
{
struct rpcap_header header;			// keeps the answer to the updatefilter command
unsigned int nread;

	if ( daemon_unpackapplyfilter(fp, &nread, &plen, fp->errbuf) )
		goto error;

	// Check if all the data has been read; if not, discard the data in excess
	if (nread != plen)
	{
		if (sock_discard(fp->rmt_sockctrl, plen - nread, fakeerrbuf) )
		{
			nread= plen;		// just to avoid to call discard again in the 'error' section
			goto error;
		}
	}

	// A response is needed, otherwise the other host does not know that everything went well
	rpcap_createhdr( &header, RPCAP_MSG_UPDATEFILTER_REPLY, 0, 0);

	if ( sock_send(fp->rmt_sockctrl, (char *) &header, sizeof (struct rpcap_header), fp->errbuf) )
		goto error;

	return 0;


error:
	if (nread != plen)
		sock_discard(fp->rmt_sockctrl, plen - nread, fakeerrbuf);

	rpcap_senderror(fp->rmt_sockctrl, fp->errbuf, PCAP_ERR_UPDATEFILTER, fakeerrbuf);

	return -1;
}
开发者ID:kubuqi,项目名称:802.1x-supplicant,代码行数:35,代码来源:daemon.c


示例3: send_ssl_chunk

static BOOL send_ssl_chunk(netconn_t *conn, const void *msg, size_t size)
{
    SecBuffer bufs[4] = {
        {conn->ssl_sizes.cbHeader, SECBUFFER_STREAM_HEADER, conn->ssl_buf},
        {size,  SECBUFFER_DATA, conn->ssl_buf+conn->ssl_sizes.cbHeader},
        {conn->ssl_sizes.cbTrailer, SECBUFFER_STREAM_TRAILER, conn->ssl_buf+conn->ssl_sizes.cbHeader+size},
        {0, SECBUFFER_EMPTY, NULL}
    };
    SecBufferDesc buf_desc = {SECBUFFER_VERSION, sizeof(bufs)/sizeof(*bufs), bufs};
    SECURITY_STATUS res;

    memcpy(bufs[1].pvBuffer, msg, size);
    res = EncryptMessage(&conn->ssl_ctx, 0, &buf_desc, 0);
    if(res != SEC_E_OK) {
        WARN("EncryptMessage failed\n");
        return FALSE;
    }

    if(sock_send(conn->socket, conn->ssl_buf, bufs[0].cbBuffer+bufs[1].cbBuffer+bufs[2].cbBuffer, 0) < 1) {
        WARN("send failed\n");
        return FALSE;
    }

    return TRUE;
}
开发者ID:Moteesh,项目名称:reactos,代码行数:25,代码来源:net.c


示例4: daemon_endcapture

int daemon_endcapture(pcap_t *fp, pthread_t *threaddata, char *errbuf)
{
struct rpcap_header header;
SOCKET sockctrl;

	if (threaddata)
	{
		pthread_cancel(*threaddata);
		threaddata= 0;
	}
	if (fp->rmt_sockdata)
	{
		sock_close(fp->rmt_sockdata, NULL, 0);
		fp->rmt_sockdata= 0;
	}

	sockctrl= fp->rmt_sockctrl;

	pcap_close(fp);
	fp= NULL;

	rpcap_createhdr( &header, RPCAP_MSG_ENDCAP_REPLY, 0, 0);

	if ( sock_send(sockctrl, (char *) &header, sizeof(struct rpcap_header), errbuf, PCAP_ERRBUF_SIZE) == -1)
		return -1;
	
	return 0;
}
开发者ID:frgtn,项目名称:rpcapd-linux,代码行数:28,代码来源:daemon.c


示例5: received_contacts_request

static void received_contacts_request(gint fd)
{
	g_print("Sending contacts\n");
	addrindex_load_person_ds(addrbook_entry_send);
	sock_send(answer_sock, ":done:\n");
	g_print("Sending of contacts done: %d\n",	g_hash_table_size(contact_hash));
}
开发者ID:hb,项目名称:claws_mail_opensync_plugin,代码行数:7,代码来源:opensync.c


示例6: received_events_request

static void received_events_request(gint fd)
{
	g_print("Sending events\n");
	vcal_foreach_event(event_send_cb);
	sock_send(fd, ":done:\n");
	g_print("Sending of events done\n");
}
开发者ID:hb,项目名称:claws_mail_opensync_plugin,代码行数:7,代码来源:opensync.c


示例7: daemon_getstatsnopcap

int daemon_getstatsnopcap(SOCKET sockctrl, unsigned int ifdrops, unsigned int ifrecv, 
						  unsigned int krnldrop, unsigned int svrcapt, char *errbuf)
{
char sendbuf[RPCAP_NETBUF_SIZE];	// temporary buffer in which data to be sent is buffered
int sendbufidx= 0;					// index which keeps the number of bytes currently buffered
struct rpcap_stats *netstats;		// statistics sent on the network

	if ( sock_bufferize(NULL, sizeof(struct rpcap_header), NULL,
		&sendbufidx, RPCAP_NETBUF_SIZE, SOCKBUF_CHECKONLY, errbuf, PCAP_ERRBUF_SIZE) == -1)
		goto error;

	rpcap_createhdr( (struct rpcap_header *) sendbuf, RPCAP_MSG_STATS_REPLY, 0, (uint16) sizeof(struct rpcap_stats));

	netstats= (struct rpcap_stats *) &sendbuf[sendbufidx];

	if ( sock_bufferize(NULL, sizeof(struct rpcap_stats), NULL,
		&sendbufidx, RPCAP_NETBUF_SIZE, SOCKBUF_CHECKONLY, errbuf, PCAP_ERRBUF_SIZE) == -1)
		goto error;

	netstats->ifdrop= htonl(ifdrops);
	netstats->ifrecv= htonl(ifrecv);
	netstats->krnldrop= htonl(krnldrop);
	netstats->svrcapt= htonl(svrcapt);

	// Send the packet
	if ( sock_send(sockctrl, sendbuf, sendbufidx, errbuf, PCAP_ERRBUF_SIZE) == -1)
		goto error;

	return 0;

error:
	rpcap_senderror(sockctrl, errbuf, PCAP_ERR_GETSTATS, NULL);
	return -1;
}
开发者ID:frgtn,项目名称:rpcapd-linux,代码行数:34,代码来源:daemon.c


示例8: sock_send_all

// 参考sock_recv
// 我们认为,所有的pending队列都在sock_send里面设置
// sock_send_all不设置任何的sock的pengding队列
// XXX:
// 如果第一次sock_send_all分多次send
// 任何一次send失败,都当做失败
ssize_t sock_send_all(int fd, char *buf, size_t size)
{
    coro_sock *sock = find_sock_by_fd(fd);
    if ( !sock ) {
        return -1;
    }
    ssize_t cnt = 0;
    ssize_t status = 0;
    uthread_t cur = coro_current_uthread();
    while ( (size_t)cnt < size ) {
        if ( status < 0 ) {
            cnt = -1;
            break;
        }
        ssize_t send_cnt = sock_send(sock->sock, buf + cnt, size);
        // 如果某次send_all过程中出错,认定为全部send失败
        if ( send_cnt < 0 ) {
            return -1;
        }
        cnt += send_cnt;
        if ( (size_t)cnt < size ) {
            set_pending_status(sock, set_wait_write_status, cur, set_wait_write_status);
            status = coro_schedule_uthread(cur, 0);
        }
    }
    clear_pending_status(sock, cur);
    return cnt;
}
开发者ID:littletiny,项目名称:corotouine,代码行数:34,代码来源:sock.cpp


示例9: netconn_send

BOOL netconn_send( netconn_t *conn, const void *msg, size_t len, int *sent )
{
    if (conn->secure)
    {
        const BYTE *ptr = msg;
        size_t chunk_size;

        *sent = 0;

        while(len) {
            chunk_size = min(len, conn->ssl_sizes.cbMaximumMessage);
            if(!send_ssl_chunk(conn, ptr, chunk_size))
                return FALSE;

            *sent += chunk_size;
            ptr += chunk_size;
            len -= chunk_size;
        }

        return TRUE;
    }
    if ((*sent = sock_send( conn->socket, msg, len, 0 )) == -1)
    {
        set_last_error( sock_get_error( errno ) );
        return FALSE;
    }
    return TRUE;
}
开发者ID:Moteesh,项目名称:reactos,代码行数:28,代码来源:net.c


示例10: rpcap_senderror

/*
 * This function sends a RPCAP error to our peer.
 *
 * It has to be called when the main program detects an error.
 * It will send to our peer the 'buffer' specified by the user.
 * This function *does not* request a RPCAP CLOSE connection. A CLOSE
 * command must be sent explicitly by the program, since we do not know
 * whether the error can be recovered in some way or if it is a
 * non-recoverable one.
 *
 * \param sock: the socket we are currently using.
 *
 * \param ver: the protocol version we want to put in the reply.
 *
 * \param errcode: a integer which tells the other party the type of error
 * we had.
 *
 * \param error: an user-allocated (and '0' terminated) buffer that contains
 * the error description that has to be transmitted to our peer. The
 * error message cannot be longer than PCAP_ERRBUF_SIZE.
 *
 * \param errbuf: a pointer to a user-allocated buffer (of size
 * PCAP_ERRBUF_SIZE) that will contain the error message (in case there
 * is one). It could be network problem.
 *
 * \return '0' if everything is fine, '-1' if some errors occurred. The
 * error message is returned in the 'errbuf' variable.
 */
int
rpcap_senderror(SOCKET sock, uint8 ver, unsigned short errcode, const char *error, char *errbuf)
{
	char sendbuf[RPCAP_NETBUF_SIZE];	/* temporary buffer in which data to be sent is buffered */
	int sendbufidx = 0;			/* index which keeps the number of bytes currently buffered */
	uint16 length;

	length = (uint16)strlen(error);

	if (length > PCAP_ERRBUF_SIZE)
		length = PCAP_ERRBUF_SIZE;

	rpcap_createhdr((struct rpcap_header *) sendbuf, ver, RPCAP_MSG_ERROR, errcode, length);

	if (sock_bufferize(NULL, sizeof(struct rpcap_header), NULL, &sendbufidx,
		RPCAP_NETBUF_SIZE, SOCKBUF_CHECKONLY, errbuf, PCAP_ERRBUF_SIZE))
		return -1;

	if (sock_bufferize(error, length, sendbuf, &sendbufidx,
		RPCAP_NETBUF_SIZE, SOCKBUF_BUFFERIZE, errbuf, PCAP_ERRBUF_SIZE))
		return -1;

	if (sock_send(sock, sendbuf, sendbufidx, errbuf, PCAP_ERRBUF_SIZE) < 0)
		return -1;

	return 0;
}
开发者ID:0mp,项目名称:freebsd,代码行数:55,代码来源:rpcap-protocol.c


示例11: xi_sock_send

errno_t xi_sock_send(xi_socket_t so, void *buf, size_t *len, int flags) {
	
#ifdef __KPI_SOCKET__
	struct iovec aio;
	struct msghdr msg;
	
	size_t sentLen = *len;
	errno_t	error;
	
	aio.iov_base = buf;
	aio.iov_len = sentLen;
	bzero(&msg, sizeof(msg));
	msg.msg_iov = (struct iovec *) &aio;
	msg.msg_iovlen = 1;
	
	error = sock_send(so, &msg, flags, &sentLen);
	
#if 1
    if(error)
		DebugPrint(1, false, "xi_sock_send: so = %p, buf_len = %d error = %d\n", so, (int)*len, error);
#endif /* if 0 */     
	
	*len = sentLen;
	
	return error;
#else
	struct iovec aiov;
    struct uio auio = { 0 };
    register struct proc *p = current_proc();
    register int error = 0;
    
    aiov.iov_base = buf;
    aiov.iov_len = *len;
    
    auio.uio_iov = &aiov;
    auio.uio_iovcnt = 1;
    auio.uio_segflg = UIO_SYSSPACE;
    auio.uio_rw = UIO_WRITE;
    auio.uio_procp = p;
    auio.uio_offset = 0;                    /* XXX */
    auio.uio_resid = *len;

//    IOLog("Before: so = %p, buf_len = %d, aiov.iov_len = %d, error = %d, auio.uio_resid = %d\n", so, (int)len, (int)aiov.iov_len, error,auio.uio_resid);
    thread_funnel_set(network_flock, TRUE);

    error = sosend(so, NULL, &auio, NULL, 0, flags);
    
	(void) thread_funnel_set(network_flock, FALSE);

#if 0
    if(error)
        IOLog("After: so = %p, buf_len = %d, aiov.iov_len = %d, error = %d, auio.uio_resid = %d\n", so, (int)*len, (int)aiov.iov_len, error, auio.uio_resid);
#endif /* if 0 */     
   
	*len = *len - auio.uio_resid;
	
	return error;
	
#endif
}
开发者ID:dansdrivers,项目名称:ndas4mac,代码行数:60,代码来源:LanScsiSocket.c


示例12: novanet_read

static int
novanet_read (char *host, void *start, void *dst)
{
  fd_set r_fds;
  struct timeval tv;
  int fd, n;
  char buf[NOVANET_PKT_SZ], rbuf[NOVANET_PKT_SZ];

  novanet_read_pkt_init (buf);
  start = (void *) NOVANET_CALC_INT (start);

  fd = sockami (host, NOVANET_TCP_PORT);
  if (fd == -1)
    {
      fprintf (stderr, "novanet_read: sockami failed\n");
      exit (EXIT_FAILURE);
    }

  NOVANET_SET_INT (buf, (unsigned int) start);
  if ((n = sock_send (fd, buf, sizeof buf)) != NOVANET_PKT_SZ)
    {
      fprintf (stderr, "novanet_read: sock_send returned %d (!= %d)\n",
               n, NOVANET_PKT_SZ);
      return (0);
    }

  FD_ZERO (&r_fds);
  FD_SET (fd, &r_fds);
  tv.tv_sec = 4;        /* wait 4 seconds */
  tv.tv_usec = 0;

  n = select (fd + 1, &r_fds, NULL, NULL, &tv);
  if (n == -1)
    {
      fprintf (stderr, "novanet_read: select() - %s\n", strerror (errno));
      exit (EXIT_FAILURE);
    }
  else if (n)
    {
      if ((n = sock_recv (fd, rbuf, sizeof rbuf)) != NOVANET_PKT_SZ)
        {
          fprintf (stderr, "novanet_read: sock_recv returned %d (!= %d)\n",
                   n, NOVANET_PKT_SZ);
          return (0);
        }
    }
  else
    {
      fprintf (stderr, "novanet_read: select timeout, we may have crashed NovaNET :(\n");
      exit (EXIT_FAILURE);
    }

  memcpy (dst, &rbuf[NOVANET_INT_IDX], sizeof (void *));
  usleep (USLEEP_TIME);
  close (fd);

  return (1);
}
开发者ID:offensive-security,项目名称:exploit-database,代码行数:58,代码来源:33878.c


示例13: _assert_

static void
_assert_(int a) {
#define __MSG "ASSERT!!!"
	if (!a) {
		sock_send(_s,(unsigned char*)__MSG, sizeof(__MSG));
		assert(0);
	}
#undef __MSG
}
开发者ID:yhcting,项目名称:ylisp,代码行数:9,代码来源:main.c


示例14: ping_server

static void ping_server(server_t *server) {
    sock_connect(&server->sock, server->address, server->port);

    msg_t *msg = sock_init_send(&server->sock, qfalse);
    write_string(msg, "info %d full empty", PROTOCOL);
    sock_send(&server->sock);
    server->ping_start = millis();
    server->ping_retries--;
}
开发者ID:hettoo,项目名称:chatsow,代码行数:9,代码来源:serverlist.c


示例15: Client

void Client(char *Address, char *Port, int AddressFamily, int TransportProtocol)
{
char ErrBuf[1024];
char DataBuffer[1024];
int ClientSocket;				// keeps the socket ID for this connection
struct addrinfo Hints;			// temporary struct to keep settings needed to open the new socket
struct addrinfo *AddrInfo;		// keeps the addrinfo chain; required to open a new socket
int WrittenBytes;				// Number of bytes written on the socket

	// Prepare to open a new server socket
	memset(&Hints, 0, sizeof(struct addrinfo));

	Hints.ai_family= AddressFamily;
	Hints.ai_socktype= TransportProtocol;	// Open a TCP or UDP connection

	if (sock_initaddress (Address, Port, &Hints, &AddrInfo, ErrBuf, sizeof(ErrBuf)) == sockFAILURE)
	{
		printf("Error resolving given address/port: %s\n\n", ErrBuf);
		return;
	}

	printf("Trying to connect to server on address %s, port %s, using protocol %s\n", 
		Address ? Address : "all local addresses", Port, (AddrInfo->ai_family == AF_INET) ? "IPv4" : "IPv6");

	if ( (ClientSocket= sock_open(AddrInfo, 0, 0,  ErrBuf, sizeof(ErrBuf))) == sockFAILURE)
	{
		// AddrInfo is no longer required
		sock_freeaddrinfo(AddrInfo);
		printf("Cannot opening the socket: %s\n\n", ErrBuf);
		return;
	}

	// AddrInfo is no longer required
	sock_freeaddrinfo(AddrInfo);

	printf("Connection established.\n");
	printf("Type the string you want to send to the server: ");
	
	// Warning: possible buffer overflow here
	fgets(DataBuffer, sizeof(DataBuffer), stdin);

	// fgets reads also the newline character, so we have to reset it
	DataBuffer[strlen(DataBuffer) - 1]= 0;

	printf("\n\n");

	WrittenBytes= sock_send(ClientSocket, DataBuffer, strlen(DataBuffer), ErrBuf, sizeof(ErrBuf));
	if (WrittenBytes == sockFAILURE)
	{
		printf("Error sending data: %s\n\n", ErrBuf);
		return;
	}

	printf("String '%s' sent. Press ENTER to terminate the program\n", DataBuffer);
	fgets(DataBuffer, sizeof(DataBuffer), stdin);
}
开发者ID:AshleyPeterson,项目名称:netbee-lite,代码行数:56,代码来源:sockutilstest.cpp


示例16: sc_send

int sc_send(char *buf, int buf_len)
{
    int ret;
    ret = sock_send(&stream_socket, buf, buf_len, SEND_TIMEOUT);

    if(ret == SOCK_TIMEOUT)
        ret = -1;

    return ret;
}
开发者ID:atmos,项目名称:butt,代码行数:10,代码来源:shoutcast.cpp


示例17: shellami

static void
shellami (int fd)
{
  int n;
  fd_set rset;
  char rbuf[1024], *cmd = "id; uname -a; uptime\n";

  sock_send (fd, cmd, strlen (cmd));

  while (1)
    {
      FD_ZERO (&rset);
      FD_SET (fd, &rset);
      FD_SET (STDIN_FILENO, &rset);

      if (select (fd + 1, &rset, NULL, NULL, NULL) < 0)
        {
          fprintf (stderr, "shellami: select() - %s\n", strerror (errno));
          exit (EXIT_FAILURE);
        }

      if (FD_ISSET (fd, &rset))
        {
          if ((n = sock_recv (fd, rbuf, sizeof (rbuf) - 1)) <= 0)
            {
              fprintf (stderr, "shellami: connection closed by foreign host.\n");
              exit (EXIT_SUCCESS);
            }
          rbuf[n] = '\0';
          printf ("%s", rbuf);
          fflush (stdout);
        }
      if (FD_ISSET (STDIN_FILENO, &rset))
        {
          if ((n = read (STDIN_FILENO, rbuf, sizeof (rbuf) - 1)) > 0)
            {
              rbuf[n] = '\0';
              sock_send (fd, rbuf, n);
            }
        }
    }
}
开发者ID:B-Rich,项目名称:osf_db,代码行数:42,代码来源:novanet-own-lnx.c


示例18: send_resp

/* return >0 ok */
int send_resp(int socket,const char *code,char *msg,int seqnum,char *type)
{
	int ret = 0;
	char strnum[32] = {0};
	sprintf(strnum,"%d",seqnum);
	
	char *ptr = create_json_msg_rsp(code,msg,strnum,type);
	ret = sock_send(socket,ptr,strlen(ptr));
	free(ptr);
	return ret;
}
开发者ID:wind0419,项目名称:wind_code,代码行数:12,代码来源:main2.c


示例19: sock_cmd

int sock_cmd(int sock, char *fmt, ... )
{
	char buf[1024];
	va_list va;
	va_start( va, fmt );
	vsnprintf(buf, sizeof(buf) - 1 , fmt, va );
	va_end( va );

	strcat(buf, "\r\n");
	return sock_send(sock, buf, strlen(buf));
}
开发者ID:simon-rock,项目名称:workspace_other,代码行数:11,代码来源:common.cpp


示例20: client_send_tcp_data_back

int client_send_tcp_data_back(client_t *client,char *data,int len)
{
	int ret ;
	ret = sock_send(client->tcp_sock,data,len);
	if(ret < 0)
		return -1;
	else if(ret == 0)
		return -2;
	else
		return 0;
}
开发者ID:LiTianjue,项目名称:work-proj,代码行数:11,代码来源:client.c



注:本文中的sock_send函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ sock_sndtimeo函数代码示例发布时间:2022-05-30
下一篇:
C++ sock_reset_flag函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap