当前位置: 首页>>代码示例>>C++>>正文


C++ sendpacket函数代码示例

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


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

示例1: netsendpacket

void netsendpacket(int ind, char *buf, int len)
{
	char bbuf[ sizeof(packbuf) + sizeof(PACKET_PROXY) ];
	PACKET_PROXYp prx = (PACKET_PROXYp)bbuf;
	int i;

	// send via master if in M/S mode and we are not the master, and the recipient is not the master and not ourselves
	if (!NetBroadcastMode && myconnectindex != connecthead && ind != myconnectindex && ind != connecthead) {
		if ((unsigned)len > sizeof(packbuf)) {
			initprintf("netsendpacket(): packet length > %d!\n",sizeof(packbuf));
			len = sizeof(packbuf);
		}

		initprintf("netsendpacket() sends proxy to %d\nPlayerIndex=%d Contents:",connecthead,ind);
		for (i=0; i<len; i++)
			initprintf(" %02x", buf[i]);
		initprintf("\n");
		
		prx->PacketType = PACKET_TYPE_PROXY;
		prx->PlayerIndex = (BYTE)ind;
		memcpy(&prx[1], buf, len);	// &prx[1] == (char*)prx + sizeof(PACKET_PROXY)
		len += sizeof(PACKET_PROXY);

		sendpacket(connecthead, bbuf, len);
		return;
	}

	sendpacket(ind, buf, len);

	initprintf("netsendpacket() sends normal to %d\nContents:",ind);
	for (i=0; i<len; i++)
		initprintf(" %02x", buf[i]);
	initprintf("\n");
}
开发者ID:JohnnyonFlame,项目名称:jfsw_old,代码行数:34,代码来源:net.c

示例2: send_LANdiscovery

int send_LANdiscovery(uint16_t port, DHT *dht)
{
    uint8_t data[CRYPTO_PUBLIC_KEY_SIZE + 1];
    data[0] = NET_PACKET_LAN_DISCOVERY;
    id_copy(data + 1, dht->self_public_key);

    send_broadcasts(dht->net, port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE);

    int res = -1;
    IP_Port ip_port;
    ip_port.port = port;

    /* IPv6 multicast */
    if (dht->net->family == AF_INET6) {
        ip_port.ip = broadcast_ip(AF_INET6, AF_INET6);

        if (ip_isset(&ip_port.ip)) {
            if (sendpacket(dht->net, ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE) > 0) {
                res = 1;
            }
        }
    }

    /* IPv4 broadcast (has to be IPv4-in-IPv6 mapping if socket is AF_INET6 */
    ip_port.ip = broadcast_ip(dht->net->family, AF_INET);

    if (ip_isset(&ip_port.ip)) {
        if (sendpacket(dht->net, ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE)) {
            res = 1;
        }
    }

    return res;
}
开发者ID:piling,项目名称:toxcore,代码行数:34,代码来源:LAN_discovery.c

示例3: main

int main(int argc,char* argv[])
{
    int s1,port,i,n,r,Sb,Sn,Rn,flag=0,w=5,EarliestMiss=-1;
    char buff[256];

    if(argc<2)
    {
        printf("Port? : ");
        scanf("%d",&port);
        gets(buff);
    }
    else
        port=atoi(argv[1]);
    s1=connectto("127.0.0.1",port);

    printf("Enter the total number of packets to be sent : ");
    scanf("%d",&n);
    printf("Enter the percentage packet lose rate : ");
    scanf("%d",&r);
    printf("Selective repeat with window size %d\n",w);
    Sb=0;
    Sn=w-1;

    while(1)
    {
        for(i=Sb; i<=Sn; i++)
        {
            if(i<n)
                sendpacket(s1,i,r);
            if(waittoread(s1)==1)
            {
                bzero(&buff,256);
                read(s1,buff,255);
                printf("Request for packet %s received \n",buff);
                Rn=atoi(buff);
                if(Rn>EarliestMiss)
                    EarliestMiss=Rn;
            }
        }
        while(EarliestMiss>=Sb && EarliestMiss<=sn)
        {
            sendpacket(s1,EarliestMiss,r);
            if(waittoread(s1)==1)
            {
                bzero(&buff,256);
                read(s1,buff,255);
                printf("Request for packet %s received\n",buff);
                Rn=atoi(buff);
                EarliestMiss=Rn;
            }
        }
        Sn=Sn+w;
        Sb=Sb+w;
        if(Sb>=n)
            break;
        printf("Moving window forward\n");
    }
    close(s1);
    printf("Client closed \n");
}
开发者ID:sidharthv96,项目名称:Engineering_Labs,代码行数:60,代码来源:client.c

示例4: lan_discovery_send

int lan_discovery_send(uint16_t port, DHT *dht)
{
    uint8_t data[CRYPTO_PUBLIC_KEY_SIZE + 1];
    data[0] = NET_PACKET_LAN_DISCOVERY;
    id_copy(data + 1, dht_get_self_public_key(dht));

    send_broadcasts(dht_get_net(dht), port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE);

    int res = -1;
    IP_Port ip_port;
    ip_port.port = port;

    /* IPv6 multicast */
    if (net_family(dht_get_net(dht)) == TOX_AF_INET6) {
        ip_port.ip = broadcast_ip(TOX_AF_INET6, TOX_AF_INET6);

        if (ip_isset(&ip_port.ip)) {
            if (sendpacket(dht_get_net(dht), ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE) > 0) {
                res = 1;
            }
        }
    }

    /* IPv4 broadcast (has to be IPv4-in-IPv6 mapping if socket is TOX_AF_INET6 */
    ip_port.ip = broadcast_ip(net_family(dht_get_net(dht)), TOX_AF_INET);

    if (ip_isset(&ip_port.ip)) {
        if (sendpacket(dht_get_net(dht), ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE)) {
            res = 1;
        }
    }

    return res;
}
开发者ID:ioasis,项目名称:c-toxcore,代码行数:34,代码来源:LAN_discovery.c

示例5: main

int main( int argc, char **argv)
{

    char buffer[8192];
    char dat[8192];
    int count;

    if(argc<4)
    {
         printf("Usage %s [host] [/folder/] [cmd]\n\nSimpleBBS <= v1.1 remote commands execution in c\ncoded by: unitedasia v.Dec.7.2005\ngreetz: iloveyouma\n",argv[0]);
         exit(1);
    }

    sprintf(dat, DATA);

    sprintf( buffer, "POST %sindex.php?v=newtopic&c=0 HTTP/1.0\nHost: %s\nContent-Type: application/x-www-form-urlencoded\nContent-Length: %d\n\n%s\n\n\n", argv[2], argv[1], strlen(dat), dat);

    sendpacket(buffer,0,argv[1]);

    sprintf( buffer, "GET %sdata/topics.php?cmd=%s HTTP/1.0\nHost: %s\n\n", argv[2], argv[3], argv[1]);

    sendpacket(buffer,1,argv[1]);

    return count;
}
开发者ID:0x24bin,项目名称:exploit-database,代码行数:25,代码来源:1361.c

示例6: send_LANdiscovery

int send_LANdiscovery(uint16_t port, DHT *dht)
{
    uint8_t data[crypto_box_PUBLICKEYBYTES + 1];
    data[0] = NET_PACKET_LAN_DISCOVERY;
    id_copy(data + 1, dht->self_public_key);

#ifdef __linux
    send_broadcasts(dht->net, port, data, 1 + crypto_box_PUBLICKEYBYTES);
#endif
    int res = -1;
    IP_Port ip_port;
    ip_port.port = port;

    /* IPv6 multicast */
    if (dht->net->family == AF_INET6) {
        ip_port.ip = broadcast_ip(AF_INET6, AF_INET6);

        if (ip_isset(&ip_port.ip))
            if (sendpacket(dht->net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES) > 0)
                res = 1;
    }

    /* IPv4 broadcast (has to be IPv4-in-IPv6 mapping if socket is AF_INET6 */
    ip_port.ip = broadcast_ip(dht->net->family, AF_INET);

    if (ip_isset(&ip_port.ip))
        if (sendpacket(dht->net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES))
            res = 1;

    return res;
}
开发者ID:9cat,项目名称:ProjectTox-Core,代码行数:31,代码来源:LAN_discovery.c

示例7: main

int main(int argc,char **argv)
{
    mutil_thread = 0;
    setup_signal_handler();
    init_clients();
    InitNetSystem();
    ENGINE engine = CreateEngine();
    int csize = atoi(argv[3]);
    int i = 0;
    for(; i < csize; ++i)
        EConnect(engine,argv[1],atoi(argv[2]),(void*)engine,on_connect,1000);
    uint32_t tick,now;
    tick = now = GetSystemMs();
    while(!stop) {
        EngineRun(engine,50);
        sendpacket();
        now = GetSystemMs();
        if(now - tick > 1000)
        {
            printf("ava_interval:%d\n",ava_interval);
            tick = now;
        }
    }
    CleanNetSystem();
    return 0;
}
开发者ID:java66liu,项目名称:luanet,代码行数:26,代码来源:tcpclient.c

示例8: send_ping_request

int send_ping_request(PING *ping, IP_Port ipp, size_t *client_id)
{
    size_t   pk[DHT_PING_SIZE];
    int       rc;
    size_t  ping_id;

    if (is_pinging(ping, ipp, 0) || id_equal(client_id, ping->dht->self_public_key))
        return 1;

    // Generate random ping_id.
    ping_id = add_ping(ping, ipp);

    pk[0] = NET_PACKET_PING_REQUEST;
    id_copy(pk + 1, ping->dht->self_public_key);     // Our pubkey
    new_nonce(pk + 1 + CLIENT_ID_SIZE); // Generate new nonce

    // Encrypt ping_id using recipient privkey
    rc = encrypt_data(client_id,
                      ping->dht->self_secret_key,
                      pk + 1 + CLIENT_ID_SIZE,
                      (size_t *) &ping_id, sizeof(ping_id),
                      pk + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES);

    if (rc != sizeof(ping_id) + crypto_box_MACBYTES)
        return 1;

    return sendpacket(ping->dht->net, ipp, pk, sizeof(pk));
}
开发者ID:zan33,项目名称:ProjectTox-Core,代码行数:28,代码来源:ping.c

示例9: function

static void function (struct channel * channel, void * memory, ssize_t extent)

{
	struct ether_header * frame = (struct ether_header *)(memory);
	unsigned length;
	while ((length = (unsigned)(hexload (memory, extent, stdin))) > 0)
	{
		if (length < (ETHER_MIN_LEN - ETHER_CRC_LEN))
		{
			error (1, ENOTSUP, "Frame size of %d is less than %d bytes", length, (ETHER_MIN_LEN - ETHER_CRC_LEN));
		}
		if (length > (ETHER_MAX_LEN - ETHER_CRC_LEN))
		{
			error (1, ENOTSUP, "Frame size of %d is more than %d bytes", length, (ETHER_MAX_LEN - ETHER_CRC_LEN));
		}
		if (_anyset (channel->flags, CHANNEL_UPDATE_TARGET))
		{
			memcpy (frame->ether_dhost, channel->peer, sizeof (frame->ether_dhost));
		}
		if (_anyset (channel->flags, CHANNEL_UPDATE_SOURCE))
		{
			memcpy (frame->ether_shost, channel->host, sizeof (frame->ether_shost));
		}
		sendpacket (channel, memory, length);
		if (_anyset (channel->flags, CHANNEL_LISTEN))
		{
			while (readpacket (channel, memory, extent) > 0);
		}
	}
	return;
}
开发者ID:LucaBongiorni,项目名称:open-plc-utils,代码行数:31,代码来源:efsu.c

示例10: c_brem

int c_brem(w_coord wcoord, b_coord bcoord) {

    server_socket *dst;

    n_coord ncoord;

    void *p;
    lt_packet out_packet;

    client_func_checks();

    ncoord = wcoord_to_ncoord(wcoord);

    dst = find_neighbor(ncoord);

    if (!dst) return 0;

    makepacket(&out_packet, T_BREM);
    p = &out_packet.payload;

    if (!put_wx(&p, wcoord.x, &PLength(&out_packet), &PArgc(&out_packet))) return 1;
    if (!put_wy(&p, wcoord.y, &PLength(&out_packet), &PArgc(&out_packet))) return 1;
    if (!put_wz(&p, wcoord.z, &PLength(&out_packet), &PArgc(&out_packet))) return 1;
    if (!put_bx(&p, bcoord.x, &PLength(&out_packet), &PArgc(&out_packet))) return 1;
    if (!put_by(&p, bcoord.y, &PLength(&out_packet), &PArgc(&out_packet))) return 1;
    if (!put_bz(&p, bcoord.z, &PLength(&out_packet), &PArgc(&out_packet))) return 1;

    return (sendpacket(dst, &out_packet));

}
开发者ID:fwsGonzo,项目名称:liblattice,代码行数:30,代码来源:client_commands.c

示例11: send_friendrequest

/* Try to send a friend request to peer with public_key.
 * data is the data in the request and length is the length.
 * return -1 if failure.
 * return  0 if it sent the friend request directly to the friend.
 * return the number of peers it was routed through if it did not send it directly.
 */
int send_friendrequest(DHT *dht, uint8_t *public_key, uint32_t nospam_num, uint8_t *data, uint32_t length)
{
    if (length + sizeof(nospam_num) > MAX_DATA_SIZE)
        return -1;

    uint8_t temp[MAX_DATA_SIZE];
    memcpy(temp, &nospam_num, sizeof(nospam_num));
    memcpy(temp + sizeof(nospam_num), data, length);
    uint8_t packet[MAX_DATA_SIZE];
    int len = create_request(dht->c->self_public_key, dht->c->self_secret_key, packet, public_key, temp,
                             length + sizeof(nospam_num),
                             CRYPTO_PACKET_FRIEND_REQ);

    if (len == -1)
        return -1;

    IP_Port ip_port = DHT_getfriendip(dht, public_key);

    if (ip_port.ip.uint32 == 1)
        return -1;

    if (ip_port.ip.uint32 != 0) {
        if (sendpacket(dht->c->lossless_udp->net->sock, ip_port, packet, len) != -1)
            return 0;

        return -1;
    }

    int num = route_tofriend(dht, public_key, packet, len);

    if (num == 0)
        return -1;

    return num;
}
开发者ID:HariKamath,项目名称:ProjectTox-Core,代码行数:41,代码来源:friend_requests.c

示例12: ppfs_chmod

int	ppfs_chmod (const char *path, mode_t mt){
  fprintf(stderr, "ppfs_chmod path : %s\n", path);

  ppacket *s = createpacket_s(4+strlen(path)+4, CLTOMD_CHMOD,-1);
  uint8_t* ptr = s->startptr+HEADER_LEN;

  put32bit(&ptr, strlen(path));
  memcpy(ptr, path, strlen(path));
  ptr+=strlen(path);
  put32bit(&ptr, mt);

  sendpacket(fd, s);
  free(s);

  s = receivepacket(fd);
  const uint8_t* ptr2 = s->startptr;
  int status = get32bit(&ptr2);

  if(status == 0){
    print_attr((const attr*)ptr2);

    attr_cache* ac;
    if(lookup_attr_cache(path,&ac) == 0){
      ac->a.mode = mt;
    }

  }
  free(s);

  return status;
}
开发者ID:twonly,项目名称:mis,代码行数:31,代码来源:client.c

示例13: send_announce_request

/* Create and send an onion announce request packet.
 *
 * path is the path the request will take before it is sent to dest.
 *
 * public_key and secret_key is the kepair which will be used to encrypt the request.
 * ping_id is the ping id that will be sent in the request.
 * client_id is the client id of the node we are searching for.
 * data_public_key is the public key we want others to encrypt their data packets with.
 * sendback_data is the data of ONION_ANNOUNCE_SENDBACK_DATA_LENGTH length that we expect to
 * receive back in the response.
 *
 * return -1 on failure.
 * return 0 on success.
 */
int send_announce_request(Networking_Core *net, const Onion_Path *path, Node_format dest, const uint8_t *public_key,
                          const uint8_t *secret_key, const uint8_t *ping_id, const uint8_t *client_id, const uint8_t *data_public_key,
                          uint64_t sendback_data)
{
    uint8_t request[ONION_ANNOUNCE_REQUEST_SIZE];
    int len = create_announce_request(request, sizeof(request), dest.public_key, public_key, secret_key, ping_id, client_id,
                                      data_public_key, sendback_data);

    if (len != sizeof(request)) {
        return -1;
    }

    uint8_t packet[ONION_MAX_PACKET_SIZE];
    len = create_onion_packet(packet, sizeof(packet), path, dest.ip_port, request, sizeof(request));

    if (len == -1) {
        return -1;
    }

    if (sendpacket(net, path->ip_port1, packet, len) != len) {
        return -1;
    }

    return 0;
}
开发者ID:piling,项目名称:toxcore,代码行数:39,代码来源:onion_announce.c

示例14: send_ping_request

int send_ping_request(IP_Port ipp, clientid_t* client_id)
{
    pingreq_t pk;
    int       rc;
    uint64_t  ping_id;

    if (is_pinging(ipp, 0) || id_eq(client_id, self_id))
        return 1;

    // Generate random ping_id
    ping_id = add_ping(ipp);

    pk.magic = PACKET_PING_REQ;
    id_cpy(&pk.client_id, self_id);     // Our pubkey
    random_nonce((uint8_t*) &pk.nonce); // Generate random nonce

    // Encrypt ping_id using recipient privkey
    rc = encrypt_data((uint8_t*) client_id,
                      self_secret_key,
                      (uint8_t*) &pk.nonce,
                      (uint8_t*) &ping_id, sizeof(ping_id),
                      (uint8_t*) &pk.ping_id);

    if (rc != sizeof(ping_id) + ENCRYPTION_PADDING)
        return 1;

    return sendpacket(ipp, (uint8_t*) &pk, sizeof(pk));
}
开发者ID:Katafalkas,项目名称:ProjectTox-Core,代码行数:28,代码来源:ping.c

示例15: send_friendrequest

/* Try to send a friendrequest to peer with public_key
   data is the data in the request and length is the length.
   return -1 if failure.
   return  0 if it sent the friend request directly to the friend.
   return the number of peers it was routed through if it did not send it directly.*/
int send_friendrequest(uint8_t * public_key, uint8_t * data, uint32_t length)
{
    uint8_t packet[MAX_DATA_SIZE];
    int len = create_request(packet, public_key, data, length, 32); /* 32 is friend request packet id */

    if (len == -1)
        return -1;

    IP_Port ip_port = DHT_getfriendip(public_key);

    if (ip_port.ip.i == 1)
        return -1;

    if (ip_port.ip.i != 0) {
        if (sendpacket(ip_port, packet, len) != -1)
            return 0;
        return -1;
    }

    int num = route_tofriend(public_key, packet, len);

    if (num == 0)
        return -1;

    return num;
}
开发者ID:1h6,项目名称:ProjectTox-Core,代码行数:31,代码来源:friend_requests.c


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