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


C++ packet_create函数代码示例

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


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

示例1: net_game_thread

void net_game_thread(net_client_descr_t *clients) {
    Field *net_field = malloc(sizeof(Field));
    char* field_buffer = malloc(512);

    game_init(net_field);

    for(int i = 0; i < MAX_CONNECTIONS; i++) {
        // sending packet 2 (game start)
        Packet *p = (Packet*) packet_create(2, 1, "1");
        queue_push(clients[i].send, p);
        clients[i].field = net_field;
    }
    
    while(net_server_status != SHUTDOWN) {
        game_update(net_field);

        int game_over = 1;
        for(int i = 0; i < MAX_CONNECTIONS; i++) {
            if (!net_field->players[i].is_dead) game_over = 0;
        }
        if (game_over) {
            Packet* p = (Packet *) packet_create(8, 1, "1");
            for(int i = 0; i < MAX_CONNECTIONS; i++) queue_push(clients[i].send, p);
            net_server_status = SHUTDOWN;
            break;
        }

        packer_pack_field(field_buffer, net_field);
        Packet* p = (Packet*) packet_create(3, strlen(field_buffer), field_buffer);
        for(int i = 0; i < MAX_CONNECTIONS; i++) queue_push(clients[i].send, p);
        usleep(30000);
    }
}
开发者ID:dekamaru,项目名称:space_invaders,代码行数:33,代码来源:net.c

示例2: irc_send_ping

extern int irc_send_ping(t_connection * conn)
{
    t_packet * p;
    char data[MAX_IRC_MESSAGE_LEN];
    
    if (!conn) {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
	return -1;
    }
    if (!(p = packet_create(packet_class_raw))) {
	eventlog(eventlog_level_error,__FUNCTION__,"could not create packet");
	return -1;
    }

    if((conn_get_wol(conn) == 1))
        return 0;

    conn_set_ircping(conn,get_ticks());
    if (conn_get_state(conn)==conn_state_bot_username)
    	sprintf(data,"PING :%u\r\n",conn_get_ircping(conn)); /* Undernet doesn't reveal the servername yet ... neither do we */
    else if ((6+strlen(server_get_hostname())+2+1)<=MAX_IRC_MESSAGE_LEN)
    	sprintf(data,"PING :%s\r\n",server_get_hostname());
    else
    	eventlog(eventlog_level_error,__FUNCTION__,"maximum message length exceeded");
    eventlog(eventlog_level_debug,__FUNCTION__,"[%d] sent \"%s\"",conn_get_socket(conn),data);
    packet_set_size(p,0);
    packet_append_data(p,data,strlen(data));
    conn_push_outqueue(conn,p);
    packet_del_ref(p);
    return 0;
}
开发者ID:91D2,项目名称:pvpgn,代码行数:31,代码来源:irc.c

示例3: send_d2cs_gameinforeq

extern int send_d2cs_gameinforeq(t_connection * c)
{
	t_packet	* packet;
	t_game		* game;
	t_realm		* realm;

	if (!(c))
	{
		eventlog(eventlog_level_error,__FUNCTION__,"got NULL conn");
		return -1;
	}
	
	if (!(game = conn_get_game(c)))
	{
		eventlog(eventlog_level_error,__FUNCTION__,"conn had NULL game");
		return -1;
	}

	if (!(realm = conn_get_realm(c)))
	{
		eventlog(eventlog_level_error,__FUNCTION__,"conn had NULL realm");
		return -1;
	}


	if ((packet=packet_create(packet_class_d2cs_bnetd))) {
		packet_set_size(packet,sizeof(t_bnetd_d2cs_gameinforeq));
		packet_set_type(packet,BNETD_D2CS_GAMEINFOREQ);
		bn_int_set(&packet->u.bnetd_d2cs_gameinforeq.h.seqno,0);
		packet_append_string(packet,game_get_name(game));
		conn_push_outqueue(realm_get_conn(realm),packet);
		packet_del_ref(packet);
	}
	return 0;
}
开发者ID:BackupTheBerlios,项目名称:pvpgn,代码行数:35,代码来源:handle_d2cs.c

示例4: cyberspace_transmit

/**
 *  \brief Cyberspace data transmission.
 *
 *         This function sends data between the cyberspace server and
 *         clients.
 *
 * @param fd            communication socket to use
 * @param tag           tag for data
 * @param data          data to transmit
 * @param len           length of data to transmit
 * @return              the result of the packet_send() function
 */
int cyberspace_transmit(int fd, int tag, unsigned char * data, int len)
{
        unsigned char packet[MAX_PACKET_SIZE] = {0};

        packet_create(tag, data, len, packet);
        return packet_send(fd, packet);
}
开发者ID:tnemeth,项目名称:Cyberspace-cybercomms,代码行数:19,代码来源:cybercomms.c

示例5: rx_source_adv

void rx_source_adv(call_t *c, packet_t *packet) {
    struct nodedata *nodedata = get_node_private_data(c);
    struct source_adv_p *source = (struct source_adv_p *) (packet->data + nodedata->overhead);
    struct sensor_adv_p *sensor;
    packet_t *packet0;
    destination_t dst = {BROADCAST_ADDR, {-1, -1, -1}};
    call_t c0 = {get_entity_bindings_down(c)->elts[0], c->node, c->entity};

    /* check adv sequence */
    if (source->s_seq <= nodedata->s_seq[source->source]) {
        /* old request */
        packet_dealloc(packet);
        return;
    }
    nodedata->s_seq[source->source] = source->s_seq;
    
    /* reply */
    packet0 = packet_create(c, nodedata->overhead + sizeof(struct sensor_adv_p), -1);
    sensor = (struct sensor_adv_p *) (packet0->data + nodedata->overhead);
    if (SET_HEADER(&c0, packet0, &dst) == -1) {
        packet_dealloc(packet);
        packet_dealloc(packet0);
        return;
    }
    sensor->type = SENSOR_ADV_TYPE;
    sensor->sensor = c->node;
    sensor->source = source->source;
    sensor->s_seq = source->s_seq;
    TX(&c0, packet0);
    packet_dealloc(packet);

    return;
}
开发者ID:gabrielleLQX,项目名称:wsnet,代码行数:33,代码来源:gossip_sensor.c

示例6: probe_create

probe_t * probe_create()
{
    probe_t * probe;

    // We calloc probe to set *_time and caller members to 0
    if (!(probe = calloc(1, sizeof(probe_t))))   goto ERR_PROBE;
    if (!(probe->packet = packet_create())) {
        fprintf(stderr, "Cannot create packet\n");
        goto ERR_PACKET;
    }
    if (!(probe->layers = dynarray_create()))    goto ERR_LAYERS;
//    if (!(probe->bitfield = bitfield_create(0))) goto ERR_BITFIELD;
    probe_set_left_to_send(probe, 1);
    return probe;

    /*
ERR_BITFIELD:
    probe_layers_free(probe);
    */
ERR_LAYERS:
    packet_free(probe->packet);
ERR_PACKET:
    free(probe);
ERR_PROBE:
    return NULL;
}
开发者ID:drt24,项目名称:libparistraceroute,代码行数:26,代码来源:probe.c

示例7: network_open_tcp_channel

/*
 * Open a TCP channel with the remote endpoint
 */
DWORD network_open_tcp_channel(Remote *remote, LPCSTR remoteHost, 
		USHORT remotePort, PacketRequestCompletion *complete)
{
	Packet *request = packet_create(PACKET_TLV_TYPE_REQUEST,
			"network_open_tcp_channel");
	DWORD res = ERROR_SUCCESS;

	do
	{
		// Verify that the packet was allocated
		if (!request)
		{
			res = ERROR_NOT_ENOUGH_MEMORY;
			break;
		}

		// Add the host/port combination
		packet_add_tlv_string(request, TLV_TYPE_NETWORK_GENERAL_REMOTE_HOST,
				remoteHost);
		packet_add_tlv_uint(request, TLV_TYPE_NETWORK_GENERAL_REMOTE_PORT,
				remotePort);

		// Transmit the request
		res = packet_transmit(remote, request, complete);

	} while (0);

	return res;
}
开发者ID:hdm,项目名称:framework2,代码行数:32,代码来源:util.c

示例8: send_bits_gamelist_del

extern int send_bits_gamelist_del(t_connection * c, t_game const * game)
{
    t_packet * p;

    if (!game) {
        eventlog(eventlog_level_error,"send_bits_gamelist_del","got NULL game");
        return -1;
    }
    p = packet_create(packet_class_bits);
    if (!p) {
        eventlog(eventlog_level_error,"send_bits_gamelist_del","could not create packet");
        return -1;
    }
    packet_set_size(p,sizeof(t_bits_gamelist_del));
    packet_set_type(p,BITS_GAMELIST_DEL);
    /***/
    bn_int_set(&p->u.bits_gamelist_del.id,game_get_id(game));
    /***/
    if (c) {
        /* send the packet on the connection */
        bits_packet_generic(p,BITS_ADDR_PEER);
        send_bits_packet_on(p,c);
    } else {
        /* broadcast the packet */
        bits_packet_generic(p,BITS_ADDR_BCAST);
        handle_bits_packet(bits_loopback_connection,p); /* also remove the game from this server */
        send_bits_packet(p);
    }
    packet_del_ref(p);
    return 0;
}
开发者ID:cooljeanius,项目名称:bnetd,代码行数:31,代码来源:bits_game.c

示例9: irc_send_pong

extern int irc_send_pong(t_connection * conn, char const * params)
{
    t_packet * p;
    char data[MAX_IRC_MESSAGE_LEN];
    
    if (!conn) {
	eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
	return -1;
    }
    if ((1+strlen(server_get_hostname())+1+4+1+strlen(server_get_hostname())+((params)?(2+strlen(params)):(0))+2+1) > MAX_IRC_MESSAGE_LEN) {
	eventlog(eventlog_level_error,__FUNCTION__,"max message length exceeded");
	return -1;
    }
    if (!(p = packet_create(packet_class_raw))) {
	eventlog(eventlog_level_error,__FUNCTION__,"could not create packet");
	return -1;
    }
    
    if (params)
    	sprintf(data,":%s PONG %s :%s\r\n",server_get_hostname(),server_get_hostname(),params);
    else
    	sprintf(data,":%s PONG %s\r\n",server_get_hostname(),server_get_hostname());
    eventlog(eventlog_level_debug,__FUNCTION__,"[%d] sent \"%s\"",conn_get_socket(conn),data);
    packet_set_size(p,0);
    packet_append_data(p,data,strlen(data));
    conn_push_outqueue(conn,p);
    packet_del_ref(p);
    return 0;
}
开发者ID:91D2,项目名称:pvpgn,代码行数:29,代码来源:irc.c

示例10: on_d2cs_authreply

static int on_d2cs_authreply(t_connection * c, t_packet const * packet)
{
	t_packet	* rpacket;
	unsigned int	version;
	unsigned int	try_version;
	unsigned int	reply;
	char const	* realmname;
	t_realm		* realm;

	if (packet_get_size(packet)<sizeof(t_d2cs_bnetd_authreply)) {
		eventlog(eventlog_level_error,__FUNCTION__,"got bad packet size");
		return -1;
	}
	if (!(realmname=packet_get_str_const(packet,sizeof(t_d2cs_bnetd_authreply),REALM_NAME_LEN))) {
		eventlog(eventlog_level_error,__FUNCTION__,"got bad realmname");
		return -1;
	}
        if (!(realm=realmlist_find_realm(realmname))) {
		realm=realmlist_find_realm_by_ip(conn_get_addr(c)); /* should not fail - checked in handle_init_packet() handle_init.c */
		eventlog(eventlog_level_warn,__FUNCTION__, "warn: realm name mismatch %s %s", realm_get_name(realm), realmname);
		if (!(prefs_allow_d2cs_setname())) { /* fail if allow_d2cs_setname = false */
			eventlog(eventlog_level_error,__FUNCTION__, "d2cs not allowed to set realm name");
			return -1;
		}
		if (realm_get_active(realm)) { /* fail if realm already active */
			eventlog(eventlog_level_error,__FUNCTION__, "cannot set realm name to %s (realm already active)",realmname);
			return -1;
		}
		realm_set_name(realm,realmname);
        }
	version=prefs_get_d2cs_version();
	try_version=bn_int_get(packet->u.d2cs_bnetd_authreply.version);
	if (version && version != try_version) {
		eventlog(eventlog_level_error,__FUNCTION__,"d2cs version mismatch 0x%X - 0x%X",
			try_version,version);
		reply=BNETD_D2CS_AUTHREPLY_BAD_VERSION;
	} else {
		reply=BNETD_D2CS_AUTHREPLY_SUCCEED;
	}

	if (reply==BNETD_D2CS_AUTHREPLY_SUCCEED) {
		eventlog(eventlog_level_info,__FUNCTION__,"d2cs %s authed",
			addr_num_to_ip_str(conn_get_addr(c)));
		conn_set_state(c,conn_state_loggedin);
		realm_active(realm,c);
	} else {
		eventlog(eventlog_level_error,__FUNCTION__,"failed to auth d2cs %s",
			addr_num_to_ip_str(conn_get_addr(c)));
	}
	if ((rpacket=packet_create(packet_class_d2cs_bnetd))) {
		packet_set_size(rpacket,sizeof(t_bnetd_d2cs_authreply));
		packet_set_type(rpacket,BNETD_D2CS_AUTHREPLY);
		bn_int_set(&rpacket->u.bnetd_d2cs_authreply.h.seqno,1);
		bn_int_set(&rpacket->u.bnetd_d2cs_authreply.reply,reply);
		conn_push_outqueue(c,rpacket);
		packet_del_ref(rpacket);
	}
	return 0;
}
开发者ID:BackupTheBerlios,项目名称:pvpgn,代码行数:59,代码来源:handle_d2cs.c

示例11: main

/**
 * Programma per generare codice C (array) di pacchetti di vari protocolli,
 * 	anche concatenati
 */
int main(int argc,  char *argv[])
{
	if(argc < 3)
	{
		printf("use:\n\t%s ... eth ip tcp data", argv[0]);
		return 0;
	}
	
	int i;
	packet_t *p = packet_create(argv[argc-1], strlen(argv[argc-1]));
	

	for(i = (argc - 2); i > 0; i--)
	{
		if(add_proto(p, argv[i]))
			printf("%s added\n", argv[i]);
		else
		{
			printf("unknow protocol %s\n", argv[i]);
			return 0;
		}
	}
	
	printf("%d\n\n", p->size);
	
	char *c_data = (char *) malloc(p->size * 6 + 30);
	
	strcpy(c_data, "char test_packet[] = {\t");
	
	for(i = 0; i < p->size; i++)
	{
		char t_data[8];
		sprintf(t_data, "0x%.2X", p->data[i]);
		strcat(c_data, t_data);
		
		if(i < p->size -1) 
		{
			if(((i % 7) == 0) && i > 3)
				strcat(c_data, ",\n\t\t\t\t\t\t");
			else
				strcat(c_data, ", ");
		}
	}
	
	strcat(c_data, " };\n");
	
	char t_data[8];
	sprintf(t_data, "%d", p->size);
	strcat(c_data, "packet_t *pack = packet_create(test_packet, ");
	strcat(c_data, t_data);
	strcat(c_data, ");\n\n");
	
	printf("\n%s\n", c_data);
	
	
	return 0;
}
开发者ID:dakk,项目名称:spiderpig-os,代码行数:61,代码来源:main.c

示例12: channel_write

/*
 * Write to the remote end of the channel
 */
DWORD channel_write(Channel *channel, Remote *remote, Tlv *addend,
                    DWORD addendLength, PUCHAR buffer, ULONG length,
                    ChannelCompletionRoutine *completionRoutine)
{
    PacketRequestCompletion requestCompletion, *realRequestCompletion = NULL;
    ChannelCompletionRoutine *dupe = NULL;
    DWORD res = ERROR_SUCCESS;
    LPCSTR method = "core_channel_write";
    Packet *request;
    Tlv methodTlv;

    do
    {
        // Allocate a request packet
        if (!(request = packet_create(PACKET_TLV_TYPE_REQUEST, NULL)))
        {
            res = ERROR_NOT_ENOUGH_MEMORY;
            break;
        }

        // Add the supplied TLVs
        packet_add_tlvs(request, addend, addendLength);

        // If no method TLV as added, add the default one.
        if (packet_get_tlv(request, TLV_TYPE_METHOD, &methodTlv) != ERROR_SUCCESS)
            packet_add_tlv_string(request, TLV_TYPE_METHOD, method);

        // Add the channel identifier and the length to write
        packet_add_tlv_uint(request, TLV_TYPE_CHANNEL_ID, channel_get_id(channel));

        // if the channel data is ment to be compressed, compress it!
        if( channel_is_flag( channel, CHANNEL_FLAG_COMPRESS ) )
            packet_add_tlv_raw(request, TLV_TYPE_CHANNEL_DATA|TLV_META_TYPE_COMPRESSED, buffer, length);
        else
            packet_add_tlv_raw(request, TLV_TYPE_CHANNEL_DATA, buffer, length);

        packet_add_tlv_uint(request, TLV_TYPE_LENGTH, channel_get_id(channel));

        // Initialize the packet completion routine
        if (completionRoutine)
        {
            // Duplicate the completion routine
            dupe = channel_duplicate_completion_routine(completionRoutine);

            requestCompletion.context = dupe;
            requestCompletion.routine = _channel_packet_completion_routine;
            realRequestCompletion     = &requestCompletion;
        }

        // Transmit the packet with the supplied completion routine, if any.
        res = packet_transmit(remote, request, realRequestCompletion);

    } while (0);

    return res;
}
开发者ID:C40,项目名称:metasploit-framework,代码行数:59,代码来源:channel.c

示例13: packet_create

packet_t *packet_new(enum packet_id type, ...)
{
	packet_constructor_t pc = packet_create(type);

	/* build the fields */

	va_list ap;
	va_start(ap, type);

	unsigned nfields = packet_format[type].nfields;
	for (unsigned field = 0; field < nfields; field++)
	{
		switch (packet_format[type].ftype[field])
		{
		case FIELD_BYTE:
			packet_add_jbyte(&pc, va_arg(ap, int));
			break;

		case FIELD_UBYTE:
			packet_add_jubyte(&pc, va_arg(ap, int));
			break;

		case FIELD_SHORT:
			packet_add_jshort(&pc, va_arg(ap, int));
			break;

		case FIELD_INT:
			packet_add_jint(&pc, va_arg(ap, long));
			break;

		case FIELD_LONG:		
			packet_add_jlong(&pc, va_arg(ap, long long));
			break;

		case FIELD_FLOAT:
			packet_add_jfloat(&pc, va_arg(ap, double));
			break;

		case FIELD_DOUBLE:
			packet_add_jdouble(&pc, va_arg(ap, double));
			break;

		case FIELD_STRING:
			packet_add_string(&pc, va_arg(ap, unsigned char *));
			break;

		default:
			dief("unhandled field type %d (packet 0x%02x, field %u)",
			     packet_format[type].ftype[field], type, field);
		}
	}

	va_end(ap);

	return packet_construct(&pc);
}
开发者ID:fis,项目名称:mcmap,代码行数:56,代码来源:protocol.c

示例14: on_d2cs_authreply

static int on_d2cs_authreply(t_connection * c, t_packet const * packet)
{
	t_packet	* rpacket;
	unsigned int	version;
	unsigned int	try_version;
	unsigned int	reply;
	char const	* realmname;
	t_realm		* realm;

	if (packet_get_size(packet)<sizeof(t_d2cs_bnetd_authreply)) {
		eventlog(eventlog_level_error,"on_d2cs_authreply","got bad packet size");
		return -1;
	}
	if (!(realmname=packet_get_str_const(packet,sizeof(t_d2cs_bnetd_authreply),REALM_NAME_LEN))) {
		eventlog(eventlog_level_error,"on_d2cs_authreply","got bad realmname");
		return -1;
	}
        if (!(realm=realmlist_find_realm_by_ip(conn_get_addr(c)))) {
                eventlog(eventlog_level_error,"handle_init_packet", "realm not found");
                return -1;
        }
	if (realm_get_name(realm) && strcasecmp(realmname,realm_get_name(realm))) {
                eventlog(eventlog_level_error,"handle_init_packet", "warn: realm name mismatch %s %s",
			realm_get_name(realm),realmname);
	}

	version=prefs_get_d2cs_version();
	try_version=bn_int_get(packet->u.d2cs_bnetd_authreply.version);
	if (version && version != try_version) {
		eventlog(eventlog_level_error,"on_d2cs_authreply","d2cs version mismatch 0x%X - 0x%X",
			try_version,version);
		reply=BNETD_D2CS_AUTHREPLY_BAD_VERSION;
	} else {
		reply=BNETD_D2CS_AUTHREPLY_SUCCEED;
	}

	if (reply==BNETD_D2CS_AUTHREPLY_SUCCEED) {
		eventlog(eventlog_level_error,"on_d2cs_authreply","d2cs %s authed",
			addr_num_to_ip_str(conn_get_addr(c)));
		conn_set_state(c,conn_state_loggedin);
		if (prefs_allow_d2cs_setname()) realm_set_name(realm,realmname);
		realm_active(realm,c);
	} else {
		eventlog(eventlog_level_error,"on_d2cs_authreply","failed to auth d2cs %s",
			addr_num_to_ip_str(conn_get_addr(c)));
	}
	if ((rpacket=packet_create(packet_class_d2cs_bnetd))) {
		packet_set_size(rpacket,sizeof(t_bnetd_d2cs_authreply));
		packet_set_type(rpacket,BNETD_D2CS_AUTHREPLY);
		bn_int_set(&rpacket->u.bnetd_d2cs_authreply.reply,reply);
		queue_push_packet(conn_get_out_queue(c),rpacket);
		packet_del_ref(rpacket);
	}
	return 0;
}
开发者ID:Danteoriginal,项目名称:bnetd,代码行数:55,代码来源:handle_d2cs.c

示例15: channel_interact

/*
 * Interact with a given channel such that data on the remote end is
 * forwarded in real time rather than being polled.
 */
DWORD channel_interact(Channel *channel, Remote *remote, Tlv *addend,
                       DWORD addendLength, BOOL enable,
                       ChannelCompletionRoutine *completionRoutine)
{
    PacketRequestCompletion requestCompletion, *realRequestCompletion = NULL;
    ChannelCompletionRoutine *dupe = NULL;
    LPCSTR method = "core_channel_interact";
    DWORD res = ERROR_SUCCESS;
    Packet *request;
    Tlv methodTlv;

    do
    {
        if (!(request = packet_create(PACKET_TLV_TYPE_REQUEST,
                                      NULL)))
        {
            res = ERROR_NOT_ENOUGH_MEMORY;
            break;
        }

        // Add the supplied TLVs
        packet_add_tlvs(request, addend, addendLength);

        // If no method TLV as added, add the default one.
        if (packet_get_tlv(request, TLV_TYPE_METHOD,
                           &methodTlv) != ERROR_SUCCESS)
            packet_add_tlv_string(request, TLV_TYPE_METHOD,
                                  method);

        // Add the channel identifier
        packet_add_tlv_uint(request, TLV_TYPE_CHANNEL_ID,
                            channel_get_id(channel));

        // Add the enable/disable boolean
        packet_add_tlv_bool(request, TLV_TYPE_BOOL, enable);

        // Initialize the packet completion routine
        if (completionRoutine)
        {
            // Duplicate the completion routine
            dupe = channel_duplicate_completion_routine(completionRoutine);

            requestCompletion.context = dupe;
            requestCompletion.routine = _channel_packet_completion_routine;
            realRequestCompletion     = &requestCompletion;
        }

        // Transmit the packet with the supplied completion routine, if any.
        res = packet_transmit(remote, request, realRequestCompletion);

    } while (0);

    return res;
}
开发者ID:C40,项目名称:metasploit-framework,代码行数:58,代码来源:channel.c


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