您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ BPTR函数代码示例

51自学网 2021-06-01 19:52:48
  C++
这篇教程C++ BPTR函数代码示例写得很实用,希望能帮到您。

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

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

示例1: is_ipv4

/* * If raw tunnel packet is IPv4, return true and increment * buffer offset to start of IP header. */boolis_ipv4 (int tunnel_type, struct buffer *buf){  int offset;  const struct openvpn_iphdr *ih;  verify_align_4 (buf);  if (tunnel_type == DEV_TYPE_TUN)    {      if (BLEN (buf) < (int) sizeof (struct openvpn_iphdr))	return false;      offset = 0;    }  else if (tunnel_type == DEV_TYPE_TAP)    {      const struct openvpn_ethhdr *eh;      if (BLEN (buf) < (int)(sizeof (struct openvpn_ethhdr)	  + sizeof (struct openvpn_iphdr)))	return false;      eh = (const struct openvpn_ethhdr *) BPTR (buf);      if (ntohs (eh->proto) != OPENVPN_ETH_P_IPV4)	return false;      offset = sizeof (struct openvpn_ethhdr);    }  else    return false;  ih = (const struct openvpn_iphdr *) (BPTR (buf) + offset);  if (OPENVPN_IPH_GET_VER (ih->version_len) == 4)    return buf_advance (buf, offset);  else    return false;}
开发者ID:angelol,项目名称:iOpenVPN,代码行数:38,


示例2: stub_decompress

static voidstub_decompress(struct buffer *buf, struct buffer work,                struct compress_context *compctx,                const struct frame *frame){    uint8_t c;    if (buf->len <= 0)    {        return;    }    if (compctx->flags & COMP_F_SWAP)    {        uint8_t *head = BPTR(buf);        c = *head;        --buf->len;        *head = *BEND(buf);        if (c != NO_COMPRESS_BYTE_SWAP)        {            dmsg(D_COMP_ERRORS, "Bad compression stub (swap) decompression header byte: %d", c);            buf->len = 0;        }    }    else    {        c = *BPTR(buf);        ASSERT(buf_advance(buf, 1));        if (c != NO_COMPRESS_BYTE)        {            dmsg(D_COMP_ERRORS, "Bad compression stub decompression header byte: %d", c);            buf->len = 0;        }    }}
开发者ID:OpenVPN,项目名称:openvpn,代码行数:33,


示例3: do_lz4_decompress

voiddo_lz4_decompress(size_t zlen_max,                  struct buffer *work,                  struct buffer *buf,                  struct compress_context *compctx){    int uncomp_len;    ASSERT(buf_safe(work, zlen_max));    uncomp_len = LZ4_decompress_safe((const char *)BPTR(buf), (char *)BPTR(work), (size_t)BLEN(buf), zlen_max);    if (uncomp_len <= 0)    {        dmsg(D_COMP_ERRORS, "LZ4 decompression error: %d", uncomp_len);        buf->len = 0;        return;    }    ASSERT(buf_safe(work, uncomp_len));    work->len = uncomp_len;    dmsg(D_COMP, "LZ4 decompress %d -> %d", buf->len, work->len);    compctx->pre_decompress += buf->len;    compctx->post_decompress += work->len;    *buf = *work;}
开发者ID:benjdag,项目名称:openvpn,代码行数:25,


示例4: mss_fixup

/* * Lower MSS on TCP SYN packets to fix MTU * problems which arise from protocol * encapsulation. */voidmss_fixup (struct buffer *buf, int maxmss){  const struct openvpn_iphdr *pip;  int hlen;  if (BLEN (buf) < (int) sizeof (struct openvpn_iphdr))    return;    verify_align_4 (buf);  pip = (struct openvpn_iphdr *) BPTR (buf);  hlen = OPENVPN_IPH_GET_LEN (pip->version_len);  if (pip->protocol == OPENVPN_IPPROTO_TCP      && ntohs (pip->tot_len) == BLEN (buf)      && (ntohs (pip->frag_off) & OPENVPN_IP_OFFMASK) == 0      && hlen <= BLEN (buf)      && BLEN (buf) - hlen         >= (int) sizeof (struct openvpn_tcphdr))    {      struct buffer newbuf = *buf;      if (buf_advance (&newbuf, hlen))	{	  struct openvpn_tcphdr *tc = (struct openvpn_tcphdr *) BPTR (&newbuf);	  if (tc->flags & OPENVPN_TCPH_SYN_MASK)	    mss_fixup_dowork (&newbuf, (uint16_t) maxmss);	}    }}
开发者ID:angelol,项目名称:iOpenVPN,代码行数:35,


示例5: buf_write_string_file

/* NOTE: requires that string be null terminated */voidbuf_write_string_file (const struct buffer *buf, const char *filename, int fd){  const int len = strlen ((char *) BPTR (buf));  const int size = write (fd, BPTR (buf), len);  if (size != len)    msg (M_ERR, "Write error on file '%s'", filename);}
开发者ID:51isoft,项目名称:openvpn-ipv6,代码行数:9,


示例6: mroute_extract_addr_ipv4

unsigned intmroute_extract_addr_ipv4 (struct mroute_addr *src,			  struct mroute_addr *dest,			  const struct buffer *buf){  unsigned int ret = 0;  if (BLEN (buf) >= 1)    {      switch (OPENVPN_IPH_GET_VER (*BPTR(buf)))	{	case 4:	  if (BLEN (buf) >= (int) sizeof (struct openvpn_iphdr))	    {	      const struct openvpn_iphdr *ip = (const struct openvpn_iphdr *) BPTR (buf);	      mroute_get_in_addr_t (src, ip->saddr, 0);	      mroute_get_in_addr_t (dest, ip->daddr, 0);	      /* multicast packet? */	      if (mroute_is_mcast (ip->daddr))		ret |= MROUTE_EXTRACT_MCAST;	      /* IGMP message? */	      if (ip->protocol == OPENVPN_IPPROTO_IGMP)		ret |= MROUTE_EXTRACT_IGMP;	      ret |= MROUTE_EXTRACT_SUCCEEDED;	    }	  break;	case 6:	  if (BLEN (buf) >= (int) sizeof (struct openvpn_ipv6hdr))	    {	      const struct openvpn_ipv6hdr *ipv6 = (const struct openvpn_ipv6hdr *) BPTR (buf);#if 0				/* very basic debug */	      struct gc_arena gc = gc_new ();	      msg( M_INFO, "IPv6 packet! src=%s, dst=%s",			print_in6_addr( ipv6->saddr, 0, &gc ),			print_in6_addr( ipv6->daddr, 0, &gc ));	      gc_free (&gc);#endif	      mroute_get_in6_addr (src, ipv6->saddr, 0);	      mroute_get_in6_addr (dest, ipv6->daddr, 0);	      if (mroute_is_mcast_ipv6 (ipv6->daddr))		ret |= MROUTE_EXTRACT_MCAST;	      ret |= MROUTE_EXTRACT_SUCCEEDED;	    }	  break;	default:	    msg (M_WARN, "IP packet with unknown IP version=%d seen",	                 OPENVPN_IPH_GET_VER (*BPTR(buf)));	}    }  return ret;}
开发者ID:andj,项目名称:openvpn-ssl-refactoring,代码行数:57,


示例7: bio_read

/* * Read from an OpenSSL BIO in non-blocking mode. */static intbio_read (BIO *bio, struct buffer *buf, int maxlen, const char *desc){  int i;  int ret = 0;  ASSERT (buf->len >= 0);  if (buf->len)    {      ;    }  else    {      int len = buf_forward_capacity (buf);      if (maxlen < len)	len = maxlen;      /*       * BIO_read brackets most of the serious RSA       * key negotiation number crunching.       */      i = BIO_read (bio, BPTR (buf), len);      VALGRIND_MAKE_READABLE ((void *) &i, sizeof (i));#ifdef BIO_DEBUG      bio_debug_data ("read", bio, BPTR (buf), i, desc);#endif      if (i < 0)	{	  if (BIO_should_retry (bio))	    {	      ;	    }	  else	    {	      msg (D_TLS_ERRORS | M_SSL, "TLS_ERROR: BIO read %s error",		   desc);	      buf->len = 0;	      ret = -1;	      ERR_clear_error ();	    }	}      else if (!i)	{	  buf->len = 0;	}      else	{			/* successful read */	  dmsg (D_HANDSHAKE_VERBOSE, "BIO read %s %d bytes", desc, i);	  buf->len = i;	  ret = 1;	  VALGRIND_MAKE_READABLE ((void *) BPTR (buf), BLEN (buf));	}    }  return ret;}
开发者ID:LordZEDith,项目名称:russia_vpn,代码行数:59,


示例8: tls_crypt_v2_wrap_client_key

static booltls_crypt_v2_wrap_client_key(struct buffer *wkc,                             const struct key2 *src_key,                             const struct buffer *src_metadata,                             struct key_ctx *server_key, struct gc_arena *gc){    cipher_ctx_t *cipher_ctx = server_key->cipher;    struct buffer work = alloc_buf_gc(TLS_CRYPT_V2_MAX_WKC_LEN                                      + cipher_ctx_block_size(cipher_ctx), gc);    /* Calculate auth tag and synthetic IV */    uint8_t *tag = buf_write_alloc(&work, TLS_CRYPT_TAG_SIZE);    if (!tag)    {        msg(M_WARN, "ERROR: could not write tag");        return false;    }    uint16_t net_len = htons(sizeof(src_key->keys) + BLEN(src_metadata)                             + TLS_CRYPT_V2_TAG_SIZE + sizeof(uint16_t));    hmac_ctx_t *hmac_ctx = server_key->hmac;    hmac_ctx_reset(hmac_ctx);    hmac_ctx_update(hmac_ctx, (void *)&net_len, sizeof(net_len));    hmac_ctx_update(hmac_ctx, (void *)src_key->keys, sizeof(src_key->keys));    hmac_ctx_update(hmac_ctx, BPTR(src_metadata), BLEN(src_metadata));    hmac_ctx_final(hmac_ctx, tag);    dmsg(D_CRYPTO_DEBUG, "TLS-CRYPT WRAP TAG: %s",         format_hex(tag, TLS_CRYPT_TAG_SIZE, 0, gc));    /* Use the 128 most significant bits of the tag as IV */    ASSERT(cipher_ctx_reset(cipher_ctx, tag));    /* Overflow check (OpenSSL requires an extra block in the dst buffer) */    if (buf_forward_capacity(&work) < (sizeof(src_key->keys)                                       + BLEN(src_metadata)                                       + sizeof(net_len)                                       + cipher_ctx_block_size(cipher_ctx)))    {        msg(M_WARN, "ERROR: could not crypt: insufficient space in dst");        return false;    }    /* Encrypt */    int outlen = 0;    ASSERT(cipher_ctx_update(cipher_ctx, BEND(&work), &outlen,                             (void *)src_key->keys, sizeof(src_key->keys)));    ASSERT(buf_inc_len(&work, outlen));    ASSERT(cipher_ctx_update(cipher_ctx, BEND(&work), &outlen,                             BPTR(src_metadata), BLEN(src_metadata)));    ASSERT(buf_inc_len(&work, outlen));    ASSERT(cipher_ctx_final(cipher_ctx, BEND(&work), &outlen));    ASSERT(buf_inc_len(&work, outlen));    ASSERT(buf_write(&work, &net_len, sizeof(net_len)));    return buf_copy(wkc, &work);}
开发者ID:OpenVPN,项目名称:openvpn,代码行数:56,


示例9: is_ipv_X

/* * If raw tunnel packet is IPv<X>, return true and increment * buffer offset to start of IP header. */staticboolis_ipv_X( int tunnel_type, struct buffer *buf, int ip_ver ){    int offset;    const struct openvpn_iphdr *ih;    verify_align_4(buf);    if (tunnel_type == DEV_TYPE_TUN)    {    	//tun类型,不包含以太头        if (BLEN(buf) < (int) sizeof(struct openvpn_iphdr))        {            return false;        }        offset = 0;    }    else if (tunnel_type == DEV_TYPE_TAP)    {    	//tap类型,包含以太头        const struct openvpn_ethhdr *eh;        if (BLEN(buf) < (int)(sizeof(struct openvpn_ethhdr)                              + sizeof(struct openvpn_iphdr)))        {            return false;        }        eh = (const struct openvpn_ethhdr *) BPTR(buf);        if (ntohs(eh->proto) != (ip_ver == 6 ? OPENVPN_ETH_P_IPV6 : OPENVPN_ETH_P_IPV4))        {        	//非指定协议,返回false            return false;        }        offset = sizeof(struct openvpn_ethhdr);    }    else    {        return false;    }    //指向ip头部    ih = (const struct openvpn_iphdr *) (BPTR(buf) + offset);    /* IP version is stored in the same bits for IPv4 or IPv6 header */    if (OPENVPN_IPH_GET_VER(ih->version_len) == ip_ver)    {    	//为对应ip协议,使buf指向对应的ip头部        return buf_advance(buf, offset);    }    else    {    	//非对应的ip协议,返回false        return false;    }}
开发者ID:anlaneg,项目名称:openvpn,代码行数:58,


示例10: test_crypto

voidtest_crypto (const struct crypto_options *co, struct frame* frame){  int i, j;  struct gc_arena gc = gc_new ();  struct buffer src = alloc_buf_gc (TUN_MTU_SIZE (frame), &gc);  struct buffer work = alloc_buf_gc (BUF_SIZE (frame), &gc);  struct buffer encrypt_workspace = alloc_buf_gc (BUF_SIZE (frame), &gc);  struct buffer decrypt_workspace = alloc_buf_gc (BUF_SIZE (frame), &gc);  struct buffer buf = clear_buf();  /* init work */  ASSERT (buf_init (&work, FRAME_HEADROOM (frame)));  msg (M_INFO, "Entering " PACKAGE_NAME " crypto self-test mode.");  for (i = 1; i <= TUN_MTU_SIZE (frame); ++i)    {      update_time ();      msg (M_INFO, "TESTING ENCRYPT/DECRYPT of packet length=%d", i);      /*       * Load src with random data.       */      ASSERT (buf_init (&src, 0));      ASSERT (i <= src.capacity);      src.len = i;      ASSERT (rand_bytes (BPTR (&src), BLEN (&src)));      /* copy source to input buf */      buf = work;      memcpy (buf_write_alloc (&buf, BLEN (&src)), BPTR (&src), BLEN (&src));      /* encrypt */      openvpn_encrypt (&buf, encrypt_workspace, co, frame);      /* decrypt */      openvpn_decrypt (&buf, decrypt_workspace, co, frame);      /* compare */      if (buf.len != src.len)	msg (M_FATAL, "SELF TEST FAILED, src.len=%d buf.len=%d", src.len, buf.len);      for (j = 0; j < i; ++j)	{	  const uint8_t in = *(BPTR (&src) + j);	  const uint8_t out = *(BPTR (&buf) + j);	  if (in != out)	    msg (M_FATAL, "SELF TEST FAILED, pos=%d in=%d out=%d", j, in, out);	}    }  msg (M_INFO, PACKAGE_NAME " crypto self-test mode SUCCEEDED.");  gc_free (&gc);}
开发者ID:KatekovAnton,项目名称:iOS-OpenVPN-Sample,代码行数:53,


示例11: corrupt_gremlin

/* * Possibly corrupt a packet. */voidcorrupt_gremlin(struct buffer *buf, int flags){    const int corrupt_level = GREMLIN_CORRUPT_LEVEL(flags);    if (corrupt_level)    {        if (flip(corrupt_freq[corrupt_level-1]))        {            do            {                if (buf->len > 0)                {                    uint8_t r = roll(0, 255);                    int method = roll(0, 5);                    switch (method)                    {                        case 0: /* corrupt the first byte */                            *BPTR(buf) = r;                            break;                        case 1: /* corrupt the last byte */                            *(BPTR(buf) + buf->len - 1) = r;                            break;                        case 2: /* corrupt a random byte */                            *(BPTR(buf) + roll(0, buf->len - 1)) = r;                            break;                        case 3: /* append a random byte */                            buf_write(buf, &r, 1);                            break;                        case 4: /* reduce length by 1 */                            --buf->len;                            break;                        case 5: /* reduce length by a random amount */                            buf->len -= roll(0, buf->len - 1);                            break;                    }                    dmsg(D_GREMLIN_VERBOSE, "GREMLIN: Packet Corruption, method=%d", method);                }                else                {                    break;                }            } while (flip(2));  /* a 50% chance we will corrupt again */        }    }}
开发者ID:OpenVPN,项目名称:openvpn,代码行数:54,


示例12: read_incoming_tun

voidread_incoming_tun (struct context *c){  /*   * Setup for read() call on TUN/TAP device.   */  /*ASSERT (!c->c2.to_link.len);*/  perf_push (PERF_READ_IN_TUN);  c->c2.buf = c->c2.buffers->read_tun_buf;#ifdef TUN_PASS_BUFFER  read_tun_buffered (c->c1.tuntap, &c->c2.buf, MAX_RW_SIZE_TUN (&c->c2.frame));#else  ASSERT (buf_init (&c->c2.buf, FRAME_HEADROOM (&c->c2.frame)));  ASSERT (buf_safe (&c->c2.buf, MAX_RW_SIZE_TUN (&c->c2.frame)));  c->c2.buf.len = read_tun (c->c1.tuntap, BPTR (&c->c2.buf), MAX_RW_SIZE_TUN (&c->c2.frame));#endif#ifdef PACKET_TRUNCATION_CHECK  ipv4_packet_size_verify (BPTR (&c->c2.buf),			   BLEN (&c->c2.buf),			   TUNNEL_TYPE (c->c1.tuntap),			   "READ_TUN",			   &c->c2.n_trunc_tun_read);#endif  /* Was TUN/TAP interface stopped? */  if (tuntap_stop (c->c2.buf.len))    {      register_signal (c, SIGTERM, "tun-stop");      msg (M_INFO, "TUN/TAP interface has been stopped, exiting");      perf_pop ();      return;		      }  /* Was TUN/TAP I/O operation aborted? */  if (tuntap_abort(c->c2.buf.len))  {     register_signal(c, SIGHUP, "tun-abort");     c->persist.restart_sleep_seconds = 10;     msg(M_INFO, "TUN/TAP I/O operation aborted, restarting");     perf_pop();     return;  }  /* Check the status return from read() */  check_status (c->c2.buf.len, "read from TUN/TAP", NULL, c->c1.tuntap);  perf_pop ();}
开发者ID:nirmoy,项目名称:openvpn,代码行数:51,


示例13: compv2_escape_data_ifneeded

/* In the v2 compression schemes, an uncompressed packet has * has no opcode in front, unless the first byte is 0x50. In this * case the packet needs to be escaped */voidcompv2_escape_data_ifneeded (struct buffer *buf){    uint8_t *head = BPTR (buf);    if (head[0] != COMP_ALGV2_INDICATOR_BYTE)	return;    /* Header is 0x50 */    ASSERT(buf_prepend(buf, 2));    head = BPTR (buf);    head[0] = COMP_ALGV2_INDICATOR_BYTE;    head[1] = COMP_ALGV2_UNCOMPRESSED;}
开发者ID:xnuxer,项目名称:vpnconnect,代码行数:17,


示例14: lzo_decompress

static voidlzo_decompress(struct buffer *buf, struct buffer work,               struct compress_context *compctx,               const struct frame *frame){    lzo_uint zlen = EXPANDED_SIZE(frame);    int err;    uint8_t c;          /* flag indicating whether or not our peer compressed */    if (buf->len <= 0)    {        return;    }    ASSERT(buf_init(&work, FRAME_HEADROOM(frame)));    c = *BPTR(buf);    ASSERT(buf_advance(buf, 1));    if (c == LZO_COMPRESS_BYTE) /* packet was compressed */    {        ASSERT(buf_safe(&work, zlen));        err = LZO_DECOMPRESS(BPTR(buf), BLEN(buf), BPTR(&work), &zlen,                             compctx->wu.lzo.wmem);        if (err != LZO_E_OK)        {            dmsg(D_COMP_ERRORS, "LZO decompression error: %d", err);            buf->len = 0;            return;        }        ASSERT(buf_safe(&work, zlen));        work.len = zlen;        dmsg(D_COMP, "LZO decompress %d -> %d", buf->len, work.len);        compctx->pre_decompress += buf->len;        compctx->post_decompress += work.len;        *buf = work;    }    else if (c == NO_COMPRESS_BYTE)     /* packet was not compressed */    {    }    else    {        dmsg(D_COMP_ERRORS, "Bad LZO decompression header byte: %d", c);        buf->len = 0;    }}
开发者ID:OpenVPN,项目名称:openvpn,代码行数:49,


示例15: rand_ctx_get

/* * Initialise the given ctr_drbg context, using a personalisation string and an * entropy gathering function. */ctr_drbg_context * rand_ctx_get(){  static entropy_context ec = {0};  static ctr_drbg_context cd_ctx = {0};  static bool rand_initialised = false;  if (!rand_initialised)    {      struct gc_arena gc = gc_new();      struct buffer pers_string = alloc_buf_gc(100, &gc);      /*       * Personalisation string, should be as unique as possible (see NIST       * 800-90 section 8.7.1). We have very little information at this stage.       * Include Program Name, memory address of the context and PID.       */      buf_printf(&pers_string, "OpenVPN %0u %p %s", platform_getpid(), &cd_ctx, time_string(0, 0, 0, &gc));      /* Initialise PolarSSL RNG, and built-in entropy sources */      entropy_init(&ec);      if (0 != ctr_drbg_init(&cd_ctx, entropy_func, &ec, BPTR(&pers_string), BLEN(&pers_string)))        msg (M_FATAL, "Failed to initialize random generator");      gc_free(&gc);      rand_initialised = true;  }  return &cd_ctx;}
开发者ID:DenisMishin,项目名称:openvpn,代码行数:34,


示例16: clone_buf

clone_buf (const struct buffer* buf)#endif{  struct buffer ret;  ret.capacity = buf->capacity;  ret.offset = buf->offset;  ret.len = buf->len;#ifdef DMALLOC  ret.data = (uint8_t *) openvpn_dmalloc (file, line, buf->capacity);#else  ret.data = (uint8_t *) malloc (buf->capacity);#endif  check_malloc_return (ret.data);  memcpy (BPTR (&ret), BPTR (buf), BLEN (buf));  return ret;}
开发者ID:51isoft,项目名称:openvpn-ipv6,代码行数:16,


示例17: buf_assign

boolbuf_assign (struct buffer *dest, const struct buffer *src){  if (!buf_init (dest, src->offset))    return false;  return buf_write (dest, BPTR (src), BLEN (src));}
开发者ID:51isoft,项目名称:openvpn-ipv6,代码行数:7,


示例18: mroute_extract_addr_arp

static unsigned intmroute_extract_addr_arp (struct mroute_addr *src,			 struct mroute_addr *dest,			 const struct buffer *buf){  unsigned int ret = 0;  if (BLEN (buf) >= (int) sizeof (struct openvpn_arp))    {      const struct openvpn_arp *arp = (const struct openvpn_arp *) BPTR (buf);      if (arp->mac_addr_type == htons(0x0001)	  && arp->proto_addr_type == htons(0x0800)	  && arp->mac_addr_size == 0x06	  && arp->proto_addr_size == 0x04)	{	  mroute_get_in_addr_t (src, arp->ip_src, MR_ARP);	  mroute_get_in_addr_t (dest, arp->ip_dest, MR_ARP);	  /* multicast packet? */	  if (mroute_is_mcast (arp->ip_dest))	    ret |= MROUTE_EXTRACT_MCAST;	  ret |= MROUTE_EXTRACT_SUCCEEDED;	}    }  return ret;}
开发者ID:andj,项目名称:openvpn-ssl-refactoring,代码行数:26,


示例19: crypto_pem_encode

boolcrypto_pem_encode(const char *name, struct buffer *dst,                  const struct buffer *src, struct gc_arena *gc){    bool ret = false;    BIO *bio = BIO_new(BIO_s_mem());    if (!bio || !PEM_write_bio(bio, name, "", BPTR(src), BLEN(src)))    {        ret = false;        goto cleanup;    }    BUF_MEM *bptr;    BIO_get_mem_ptr(bio, &bptr);    *dst = alloc_buf_gc(bptr->length, gc);    ASSERT(buf_write(dst, bptr->data, bptr->length));    ret = true;cleanup:    if (!BIO_free(bio))    {        ret = false;;    }    return ret;}
开发者ID:lstipakov,项目名称:openvpn,代码行数:27,


示例20: lz4v2_compress

static voidlz4v2_compress(struct buffer *buf, struct buffer work,               struct compress_context *compctx,               const struct frame *frame){    bool compressed;    if (buf->len <= 0)    {        return;    }    compressed = do_lz4_compress(buf, &work, compctx, frame);    /* On Error just return */    if (buf->len == 0)    {        return;    }    /* did compression save us anything?  Include 2 byte compression header     * in calculation */    if (compressed && work.len + 2 < buf->len)    {        ASSERT(buf_prepend(&work, 2));        uint8_t *head = BPTR(&work);        head[0] = COMP_ALGV2_INDICATOR_BYTE;        head[1] = COMP_ALGV2_LZ4_BYTE;        *buf = work;    }    else    {        compv2_escape_data_ifneeded(buf);    }}
开发者ID:benjdag,项目名称:openvpn,代码行数:34,


示例21: stub_compress

static voidstub_compress(struct buffer *buf, struct buffer work,              struct compress_context *compctx,              const struct frame *frame){    if (buf->len <= 0)    {        return;    }    if (compctx->flags & COMP_F_SWAP)    {        uint8_t *head = BPTR(buf);        uint8_t *tail  = BEND(buf);        ASSERT(buf_safe(buf, 1));        ++buf->len;        /* move head byte of payload to tail */        *tail = *head;        *head = NO_COMPRESS_BYTE_SWAP;    }    else    {        uint8_t *header = buf_prepend(buf, 1);        *header = NO_COMPRESS_BYTE;    }}
开发者ID:OpenVPN,项目名称:openvpn,代码行数:26,


示例22: full_clone_buf

/* *  This is exactly like clone_buf, but uses malloc to allocate the memory so that it can be cached *  properly */struct buffer*full_clone_buf(const struct buffer* buf){  struct buffer* ret = (struct buffer*) malloc(sizeof(struct buffer));  ret->capacity = buf->capacity;  ret->offset = buf->offset;  ret->len = buf->len;#ifdef DMALLOC  ret->data = (uint8_t *) openvpn_dmalloc (file, line, buf->capacity);#else  ret->data = (uint8_t *) malloc (buf->capacity);#endif  check_malloc_return (ret->data);  memcpy (BPTR (ret), BPTR (buf), BLEN (buf));  return ret;  }
开发者ID:alshalan,项目名称:Mobile-OpenVPN,代码行数:21,


示例23: buf_string_match_head_str

boolbuf_string_match_head_str (const struct buffer *src, const char *match){  const int size = strlen (match);  if (size < 0 || size > src->len)    return false;  return memcmp (BPTR (src), match, size) == 0;}
开发者ID:51isoft,项目名称:openvpn-ipv6,代码行数:8,


示例24: do_lz4_compress

static booldo_lz4_compress(struct buffer *buf,                struct buffer *work,                struct compress_context *compctx,                const struct frame *frame){    /*     * In order to attempt compression, length must be at least COMPRESS_THRESHOLD.     */    if (buf->len >= COMPRESS_THRESHOLD)    {        const size_t ps = PAYLOAD_SIZE(frame);        int zlen_max = ps + COMP_EXTRA_BUFFER(ps);        int zlen;        ASSERT(buf_init(work, FRAME_HEADROOM(frame)));        ASSERT(buf_safe(work, zlen_max));        if (buf->len > ps)        {            dmsg(D_COMP_ERRORS, "LZ4 compression buffer overflow");            buf->len = 0;            return false;        }        zlen = LZ4_compress_limitedOutput((const char *)BPTR(buf), (char *)BPTR(work), BLEN(buf), zlen_max );        if (zlen <= 0)        {            dmsg(D_COMP_ERRORS, "LZ4 compression error");            buf->len = 0;            return false;        }        ASSERT(buf_safe(work, zlen));        work->len = zlen;        dmsg(D_COMP, "LZ4 compress %d -> %d", buf->len, work->len);        compctx->pre_compress += buf->len;        compctx->post_compress += work->len;        return true;    }    return false;}
开发者ID:benjdag,项目名称:openvpn,代码行数:45,


示例25: bio_write_post

static voidbio_write_post (const int status, struct buffer *buf){  if (status == 1) /* success status return from bio_write? */    {      memset (BPTR (buf), 0, BLEN (buf)); /* erase data just written */      buf->len = 0;    }}
开发者ID:LordZEDith,项目名称:russia_vpn,代码行数:9,


示例26: Lcd_print

void Lcd_print(void){    uint8   length;    uint8 * buf;    length = (uint8)VM_PopW();              /* length */    buf    = BPTR(VM_UserRAM, VM_PopW());   /* buf[] */}
开发者ID:miaozhendaoren,项目名称:VM-2CB,代码行数:9,


示例27: mroute_extract_addr_ether

unsigned intmroute_extract_addr_ether(struct mroute_addr *src,                          struct mroute_addr *dest,                          struct mroute_addr *esrc,                          struct mroute_addr *edest,                          const struct buffer *buf){    unsigned int ret = 0;    if (BLEN(buf) >= (int) sizeof(struct openvpn_ethhdr))    {        const struct openvpn_ethhdr *eth = (const struct openvpn_ethhdr *) BPTR(buf);        if (src)        {            src->type = MR_ADDR_ETHER;            src->netbits = 0;            src->len = 6;            memcpy(src->eth_addr, eth->source, sizeof(dest->eth_addr));        }        if (dest)        {            dest->type = MR_ADDR_ETHER;            dest->netbits = 0;            dest->len = 6;            memcpy(dest->eth_addr, eth->dest, sizeof(dest->eth_addr));            /* ethernet broadcast/multicast packet? */            if (is_mac_mcast_addr(eth->dest))            {                ret |= MROUTE_EXTRACT_BCAST;            }        }        ret |= MROUTE_EXTRACT_SUCCEEDED;#ifdef ENABLE_PF        if (esrc || edest)        {            struct buffer b = *buf;            if (buf_advance(&b, sizeof(struct openvpn_ethhdr)))            {                switch (ntohs(eth->proto))                {                    case OPENVPN_ETH_P_IPV4:                        ret |= (mroute_extract_addr_ip(esrc, edest, &b) << MROUTE_SEC_SHIFT);                        break;                    case OPENVPN_ETH_P_ARP:                        ret |= (mroute_extract_addr_arp(esrc, edest, &b) << MROUTE_SEC_SHIFT);                        break;                }            }        }#endif    }    return ret;}
开发者ID:OpenVPN,项目名称:openvpn,代码行数:56,


示例28: mroute_extract_addr_ipv4

unsigned intmroute_extract_addr_ipv4 (struct mroute_addr *src,			  struct mroute_addr *dest,			  const struct buffer *buf){  unsigned int ret = 0;  static bool ipv6warned = false;  if (BLEN (buf) >= 1)    {      switch (OPENVPN_IPH_GET_VER (*BPTR(buf)))	{	case 4:	  if (BLEN (buf) >= (int) sizeof (struct openvpn_iphdr))	    {	      const struct openvpn_iphdr *ip = (const struct openvpn_iphdr *) BPTR (buf);	      mroute_get_in_addr_t (src, ip->saddr, 0);	      mroute_get_in_addr_t (dest, ip->daddr, 0);	      /* multicast packet? */	      if (mroute_is_mcast (ip->daddr))		ret |= MROUTE_EXTRACT_MCAST;	      /* IGMP message? */	      if (ip->protocol == OPENVPN_IPPROTO_IGMP)		ret |= MROUTE_EXTRACT_IGMP;	      ret |= MROUTE_EXTRACT_SUCCEEDED;	    }	  break;	case 6:	  {            if( !ipv6warned ) {              msg (M_WARN, "IPv6 in tun mode is not supported in OpenVPN 2.2");              ipv6warned = true;            }	    break;	  }	}    }  return ret;}
开发者ID:StephenMacras,项目名称:dsl-n55u-bender,代码行数:43,


示例29: is_ipv4

/* * If raw tunnel packet is IPv4, return true and increment * buffer offset to start of IP header. */boolis_ipv4 (int tunnel_type, struct buffer *buf){  int offset;  const struct openvpn_iphdr *ih;  verify_align_4 (buf);  if (tunnel_type == DEV_TYPE_TUN)    {      if (BLEN (buf) < (int) sizeof (struct openvpn_iphdr))	return false;      offset = 0;    }  else if (tunnel_type == DEV_TYPE_TAP)    {      const struct openvpn_ethhdr *eh;      if (BLEN (buf) < (int)(sizeof (struct openvpn_ethhdr)	  + sizeof (struct openvpn_iphdr)))	return false;      eh = (const struct openvpn_ethhdr *) BPTR (buf);      if (ntohs (eh->proto) != OPENVPN_ETH_P_IPV4)	return false;      offset = sizeof (struct openvpn_ethhdr);    }  else    return false;  ih = (const struct openvpn_iphdr *) (BPTR (buf) + offset);  if (OPENVPN_IPH_GET_VER (ih->version_len) == 4)  {		 /* struct	in_addr x,y;	  x.s_addr = ih->saddr;	  y.s_addr = ih->daddr;	      printf("/n src=%s,dest=%s", inet_ntoa(x),inet_ntoa(y));*/	  return buf_advance (buf, offset);  }    else    return false;}
开发者ID:jmadhav,项目名称:lib,代码行数:45,


示例30: convert_to_one_line

/* * convert a multi-line output to one line */voidconvert_to_one_line (struct buffer *buf){  uint8_t *cp = BPTR(buf);  int len = BLEN(buf);  while (len--)    {      if (*cp == '/n')	*cp = '|';      ++cp;    }}
开发者ID:51isoft,项目名称:openvpn-ipv6,代码行数:15,



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


C++ BP_IS_HOLE函数代码示例
C++ BPF_STMT函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。