示例#1
0
文件: result.c 项目: c42/downpour
VALUE downpour_include_result_module(drizzle_result_st *self_ptr, VALUE result)
{
  ResultExtraInfo *info = extra_info(self_ptr);
  set_extra_pointer(result, info, free_extra_info);
  rb_iv_set(result, "@columns", get_columns_in_array(self_ptr, result, info));
  return result;
}
示例#2
0
/* For a given BD_ADDR, print address, name and class */
void print_name_and_class(int dev_handle, int dev_id, bdaddr_t *bdaddr,
						  char* printable_addr, uint8_t extended)
{
    char name[248] = { 0 };

	if (hci_read_remote_name(dev_handle, bdaddr, sizeof(name), name, 0) < 0)
			strcpy(name, "[unknown]");

	printf("%s\t%s\n", printable_addr, name);
	if (extended)
		extra_info(dev_handle, dev_id, bdaddr);
}
示例#3
0
文件: udp.c 项目: dnivra/tcp-stack
/*
 * Send an UDP packet from port sport to host ``daddr''
 * and port ``dport''. The arguments are in host byte order.
 */
int
udp_send(port_t sport, ipaddr_t daddr, port_t dport, void *data, int len)
{
    static unsigned short ipid = 1;
    udphdr_t *up;
    char *msg;
    int rv, udplen;
    pseudohdr_t ph;
    extern ipaddr_t my_ipaddr;

    if (!my_ipaddr && !ip_init())
	return -1;

    if (extra_info())
    {
        printf("udp_send(%d, %s, %d, %p, %d)\n", sport, inet_ntoa(daddr), dport, data, len);
    }

    udplen = len + sizeof(udphdr_t);
    if ((msg = malloc(align(udplen))) == NULL) {
	printf("%s, %d: malloc failed\n", __LINE__, __FILE__);
	return -1;
    }
    up = (udphdr_t *) msg;
    up->uh_sport = htons(sport);
    up->uh_dport = htons(dport);
    up->uh_len = htons(udplen);
    up->uh_sum = 0;
    memcpy(msg + sizeof(udphdr_t), data, len);
    /* compute UDP checksum */
    ph.ph_src = my_ipaddr;
    ph.ph_dst = daddr;
    ph.ph_zero = 0;
    ph.ph_p = IP_PROTO_UDP;
    ph.ph_len = up->uh_len;
    up->uh_sum = ~inet_checksum(&ph, sizeof(ph));
    if (udplen & 1)
	msg[udplen] = '\0';
    up->uh_sum = inet_checksum(up, align(udplen));
    if (up->uh_sum == 0)
	up->uh_sum = 0xFFFF;
    rv = ip_send(daddr, IP_PROTO_UDP, ipid++, msg, udplen);
    free(msg);
    /* return rv; */
    return len;
}
示例#4
0
int main(int argc, char *argv[])
{
    inquiry_info *ii = NULL;
	int i, opt, dev_id, sock, len, flags, max_rsp, num_rsp, lap, timeout = 20;
	uint8_t extended = 0;
	uint8_t scan = 0;
	char ubertooth_device = -1;
	char *bt_dev = "hci0";
    char addr[19] = { 0 };
    char name[248] = { 0 };
	struct libusb_device_handle *devh = NULL;
	btbb_piconet *pn;
	bdaddr_t bdaddr;

	while ((opt=getopt(argc,argv,"ht:xsb:")) != EOF) {
		switch(opt) {
		case 'b':
			bt_dev = optarg;
			if (bt_dev == NULL) {
				perror(optarg);
				return 1;
			}
			break;
		case 't':
			timeout = atoi(optarg);
			break;
		case 'x':
			extended = 1;
			break;
		case 's':
			scan = 1;
			break;
		case 'h':
		default:
			usage();
			return 1;
		}
	}
	
    dev_id = hci_devid(bt_dev);
    sock = hci_open_dev( dev_id );
    if (dev_id < 0 || sock < 0) {
        perror("opening socket");
        return 1;
	}

	devh = ubertooth_start(ubertooth_device);
	if (devh == NULL) {
		usage();
		return 1;
	}
	/* Set sweep mode - otherwise AFH map is useless */
	cmd_set_channel(devh, 9999);

	if (scan) {
		len  = 8;
		max_rsp = 255;
		flags = IREQ_CACHE_FLUSH;
		ii = (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info));
		
		num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
		if( num_rsp < 0 )
			perror("hci_inquiry");
	
		/* Equivalent to "hcitool scan" */
		printf("HCI scan\n");
		for (i = 0; i < num_rsp; i++) {
			ba2str(&(ii+i)->bdaddr, addr);
			memset(name, 0, sizeof(name));
			if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name), 
			name, 0) < 0)
				strcpy(name, "[unknown]");
			printf("%s  %s\n", addr, name);
		}
		free(ii);
	}

	/* Now find hidden piconets with Ubertooth */
	printf("\nUbertooth scan\n");
	btbb_init_survey();
	rx_live(devh, NULL, timeout);
	ubertooth_stop(devh);

	while((pn=btbb_next_survey_result()) != NULL) {
		lap = btbb_piconet_get_lap(pn);
		if (btbb_piconet_get_flag(pn, BTBB_UAP_VALID)) {
			lap = btbb_piconet_get_lap(pn);
			sprintf(addr, "00:00:%02X:%02X:%02X:%02X", btbb_piconet_get_uap(pn),
					(lap >> 16) & 0xFF, (lap >> 8) & 0xFF, lap & 0xFF);
			str2ba(addr, &bdaddr);
			memset(name, 0, sizeof(name));
			if (hci_read_remote_name(sock, &bdaddr, sizeof(name), name, 0) < 0)
				strcpy(name, "[unknown]");
			printf("%s  %s\n", addr, name);
			if (extended)
				extra_info(sock, dev_id, &bdaddr);
		} else
			printf("00:00:00:%02X:%02X:%02X\n",
				   (lap >> 16) & 0xFF, (lap >> 8) & 0xFF, lap & 0xFF);
		btbb_print_afh_map(pn);
	}