Example #1
0
static int
find_boundary (struct MHD_PostProcessor *pp,
               const char *boundary,
               size_t blen,
               size_t *ioffptr,
               enum PP_State next_state, enum PP_State next_dash_state)
{
  char *buf = (char *) &pp[1];

  if (pp->buffer_pos < 2 + blen)
    {
      if (pp->buffer_pos == pp->buffer_size)
        pp->state = PP_Error;   /* out of memory */
      return MHD_NO;            /* not enough data */
    }
  if ((0 != memcmp ("--", buf, 2)) || (0 != memcmp (&buf[2], boundary, blen)))
    {
      if (pp->state != PP_Init)
        pp->state = PP_Error;
      return MHD_NO;            /* expected boundary */
    }
  /* remove boundary from buffer */
  (*ioffptr) += 2 + blen;
  /* next: start with headers */
  pp->skip_rn = RN_Dash;
  pp->state = next_state;
  pp->dash_state = next_dash_state;
  return MHD_YES;
}
Example #2
0
uae_s16 *decodewav (uae_u8 *s, int *lenp)
{
	uae_s16 *dst;
	uae_u8 *src = s;
	int len;

	if (memcmp (s, "RIFF", 4))
		return 0;
	if (memcmp (s + 8, "WAVE", 4))
		return 0;
	s += 12;
	len = *lenp;
	while (s < src + len) {
		if (!memcmp (s, "fmt ", 4))
			freq = s[8 + 4] | (s[8 + 5] << 8);
		if (!memcmp (s, "data", 4)) {
			s += 4;
			len = s[0] | (s[1] << 8) | (s[2] << 16) | (s[3] << 24);
			dst = xmalloc (uae_s16, len / 2);
#ifdef WORDS_BIGENDIAN
			int8_t *dst8 = (int8_t *) dst;
			for (int i = 0; i < len; i += 2) {
				dst8[i] = s[i + 1];
				dst8[i + 1] = s[i];
			}
#else
			memcpy (dst, s + 4, len);
#endif
			*lenp = len / 2;
			return dst;
		}
		s += 8 + (s[4] | (s[5] << 8) | (s[6] << 16) | (s[7] << 24));
	}
	return 0;
}
Example #3
0
void wpa_pmk_to_ptk(u8 * pmk, u8 * addr1, u8 * addr2,
		    u8 * nonce1, u8 * nonce2, u8 * ptk, size_t ptk_len)
{
	u8 data[2 * ETH_ALEN + 2 * 32];

	memset(&data, 0, sizeof(data));

	/* PTK = PRF-X(PMK, "Pairwise key expansion",
	 *             Min(AA, SA) || Max(AA, SA) ||
	 *             Min(ANonce, SNonce) || Max(ANonce, SNonce)) */

	if (memcmp(addr1, addr2, ETH_ALEN) < 0) {
		memcpy(data, addr1, ETH_ALEN);
		memcpy(data + ETH_ALEN, addr2, ETH_ALEN);
	} else {
		memcpy(data, addr2, ETH_ALEN);
		memcpy(data + ETH_ALEN, addr1, ETH_ALEN);
	}

	if (memcmp(nonce1, nonce2, 32) < 0) {
		memcpy(data + 2 * ETH_ALEN, nonce1, 32);
		memcpy(data + 2 * ETH_ALEN + 32, nonce2, 32);
	} else {
		memcpy(data + 2 * ETH_ALEN, nonce2, 32);
		memcpy(data + 2 * ETH_ALEN + 32, nonce1, 32);
	}

	sha1_prf(pmk, 32, "Pairwise key expansion", data, sizeof(data),
		 ptk, ptk_len);
}
Example #4
0
// Simple test to ensure that when we call textToGlyphs, we get the same
// result (for the same text) when using UTF8, UTF16, UTF32.
// TODO: make the text more complex (i.e. incorporate chars>7bits)
static void test_textencodings(skiatest::Reporter* reporter) {
    const char text8[] = "ABCDEFGabcdefg0123456789";
    uint16_t text16[sizeof(text8)];
    int32_t  text32[sizeof(text8)];
    size_t len8 = strlen(text8);
    size_t len16 = len8 * 2;
    size_t len32 = len8 * 4;

    // expand our 8bit chars to 16 and 32
    for (size_t i = 0; i < len8; ++i) {
        text32[i] = text16[i] = text8[i];
    }

    uint16_t glyphs8[sizeof(text8)];
    uint16_t glyphs16[sizeof(text8)];
    uint16_t glyphs32[sizeof(text8)];

    SkPaint paint;

    paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
    int count8  = paint.textToGlyphs(text8,  len8,  glyphs8);

    paint.setTextEncoding(SkPaint::kUTF16_TextEncoding);
    int count16 = paint.textToGlyphs(text16, len16, glyphs16);

    paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
    int count32 = paint.textToGlyphs(text32, len32, glyphs32);

    REPORTER_ASSERT(reporter, (int)len8 == count8);
    REPORTER_ASSERT(reporter, (int)len8 == count16);
    REPORTER_ASSERT(reporter, (int)len8 == count32);

    REPORTER_ASSERT(reporter, !memcmp(glyphs8, glyphs16, count8 * sizeof(uint16_t)));
    REPORTER_ASSERT(reporter, !memcmp(glyphs8, glyphs32, count8 * sizeof(uint16_t)));
}
/* what sort of file is this? */
static enum filetype
file_gettype(u_char *buf)
{

	if (buf[0] == GZIP_MAGIC0 &&
	    (buf[1] == GZIP_MAGIC1 || buf[1] == GZIP_OMAGIC1))
		return FT_GZIP;
	else
#ifndef NO_BZIP2_SUPPORT
	if (memcmp(buf, BZIP2_MAGIC, 3) == 0 &&
	    buf[3] >= '0' && buf[3] <= '9')
		return FT_BZIP2;
	else
#endif
#ifndef NO_COMPRESS_SUPPORT
	if (memcmp(buf, Z_MAGIC, 2) == 0)
		return FT_Z;
	else
#endif
#ifndef NO_PACK_SUPPORT
	if (memcmp(buf, PACK_MAGIC, 2) == 0)
		return FT_PACK;
	else
#endif
#ifndef NO_XZ_SUPPORT
	if (memcmp(buf, XZ_MAGIC, 4) == 0)	/* XXX: We only have 4 bytes */
		return FT_XZ;
	else
#endif
		return FT_UNKNOWN;
}
Example #6
0
static ssize_t eth_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
{
	unsigned char sa_bcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
	struct fs_eth *eth = DO_UPCAST(NICState, nc, nc)->opaque;
	int use_ma0 = eth->regs[RW_REC_CTRL] & 1;
	int use_ma1 = eth->regs[RW_REC_CTRL] & 2;
	int r_bcast = eth->regs[RW_REC_CTRL] & 8;

	if (size < 12)
		return -1;

	D(printf("%x.%x.%x.%x.%x.%x ma=%d %d bc=%d\n",
		 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
		 use_ma0, use_ma1, r_bcast));
	       
	/* Does the frame get through the address filters?  */
	if ((!use_ma0 || memcmp(buf, eth->macaddr[0], 6))
	    && (!use_ma1 || memcmp(buf, eth->macaddr[1], 6))
	    && (!r_bcast || memcmp(buf, sa_bcast, 6))
	    && !eth_match_groupaddr(eth, buf))
		return size;

	/* FIXME: Find another way to pass on the fake csum.  */
	etraxfs_dmac_input(eth->dma_in, (void *)buf, size + 4, 1);

        return size;
}
void KisMemoryWindowTest::testWindow()
{
    KisMemoryWindow memory(QString(), 1024);

    quint8 oddValue = 0xee;
    const quint8 chunkLength = 10;

    quint8 oddBuf[chunkLength];
    memset(oddBuf, oddValue, chunkLength);


    KisChunkData chunk1(0, chunkLength);
    KisChunkData chunk2(1025, chunkLength);

    quint8 *ptr;

    ptr = memory.getWriteChunkPtr(chunk1);
    memcpy(ptr, oddBuf, chunkLength);

    ptr = memory.getWriteChunkPtr(chunk2);
    memcpy(ptr, oddBuf, chunkLength);

    ptr = memory.getReadChunkPtr(chunk2);
    QVERIFY(!memcmp(ptr, oddBuf, chunkLength));

    ptr = memory.getWriteChunkPtr(chunk1);
    QVERIFY(!memcmp(ptr, oddBuf, chunkLength));
}
Example #8
0
static int read_chunk(chm_metadata_t *metadata)
{
	cli_dbgmsg("in read_chunk\n");

	if (metadata->itsp_hdr.block_len < 8 || metadata->itsp_hdr.block_len > 33554432) {
		return CL_EFORMAT;
	}

	if (metadata->chunk_offset > metadata->m_length) {
		return CL_EFORMAT;
	}
	if ((metadata->chunk_offset + metadata->itsp_hdr.block_len) > metadata->m_length) {
		return CL_EFORMAT;
	}
	metadata->chunk_data = fmap_need_off_once(metadata->map, metadata->chunk_offset, metadata->itsp_hdr.block_len);
	if(!metadata->chunk_data) return CL_EFORMAT;

	metadata->chunk_current = metadata->chunk_data + CHM_CHUNK_HDR_LEN;
	metadata->chunk_end = metadata->chunk_data + metadata->itsp_hdr.block_len;

	if (memcmp(metadata->chunk_data, "PMGL", 4) == 0) {
		metadata->chunk_entries = (uint16_t)((((uint8_t const *)(metadata->chunk_data))[metadata->itsp_hdr.block_len-2] << 0)
					| (((uint8_t const *)(metadata->chunk_data))[metadata->itsp_hdr.block_len-1] << 8));
	} else if (memcmp(metadata->chunk_data, "PMGI", 4) != 0) {
		return CL_BREAK;
	}

	return CL_SUCCESS;
}
Example #9
0
static int check_ref(const char *name, int len, unsigned int flags)
{
    if (!flags)
        return 1;

    if (len < 5 || memcmp(name, "refs/", 5))
        return 0;

    /* Skip the "refs/" part */
    name += 5;
    len -= 5;

    /* REF_NORMAL means that we don't want the magic fake tag refs */
    if ((flags & REF_NORMAL) && check_ref_format(name) < 0)
        return 0;

    /* REF_HEADS means that we want regular branch heads */
    if ((flags & REF_HEADS) && !memcmp(name, "heads/", 6))
        return 1;

    /* REF_TAGS means that we want tags */
    if ((flags & REF_TAGS) && !memcmp(name, "tags/", 5))
        return 1;

    /* All type bits clear means that we are ok with anything */
    return !(flags & ~REF_NORMAL);
}
Example #10
0
/**
 * Read the signature type of the certificate. We only support RSA-MD5 and
 * RSA-SHA1 signature types.
 */
int asn1_signature_type(const uint8_t *cert, 
                                int *offset, X509_CTX *x509_ctx)
{
    int ret = X509_NOT_OK, len;

    if (cert[(*offset)++] != ASN1_OID)
        goto end_check_sig;

    len = get_asn1_length(cert, offset);

    if (len == sizeof(sig_sha1WithRSAEncrypt) && 
            memcmp(sig_sha1WithRSAEncrypt, &cert[*offset], 
                                    sizeof(sig_sha1WithRSAEncrypt)) == 0)
    {
        x509_ctx->sig_type = SIG_TYPE_SHA1;
    }
    else if (len == sizeof(sig_sha256) && 
            memcmp(sig_sha256, &cert[*offset], 
                                    sizeof(sig_sha256)) == 0)
    {
        x509_ctx->sig_type = SIG_TYPE_SHA256;
    }
    else if (len == sizeof(sig_sha384) && 
            memcmp(sig_sha384, &cert[*offset], 
                                    sizeof(sig_sha384)) == 0)
    {
        x509_ctx->sig_type = SIG_TYPE_SHA384;
    }
    else if (len == sizeof(sig_sha512) && 
            memcmp(sig_sha512, &cert[*offset], 
                                    sizeof(sig_sha512)) == 0)
    {
        x509_ctx->sig_type = SIG_TYPE_SHA512;
    }
    else
    {
        if (memcmp(sig_oid_prefix, &cert[*offset], sizeof(sig_oid_prefix)))
        {
#ifdef CONFIG_SSL_FULL_MODE
            int i;
            printf("invalid digest: ");

            for (i = 0; i < len; i++)
                printf("%02x ", cert[*offset + i]);

            printf("\n");
#endif
            goto end_check_sig;     /* unrecognised cert type */
        }

        x509_ctx->sig_type = cert[*offset + sizeof(sig_oid_prefix)];
    }

    *offset += len;
    asn1_skip_obj(cert, offset, ASN1_NULL); /* if it's there */
    ret = X509_OK;

end_check_sig:
    return ret;
}
Example #11
0
/**  Funcao de captura de pacotes [eh passada como parametro para a pcap ]
u_char *foo --> ???
const struct pcap_pkthdr *header --> Cabecalho contendo informacoes sobre o pacote capturado
				fields:
					ts : uma "struct timeval" contendo o tempo onde o pacote foi capturado
					caplen : um "bpf_u_int32" contendo o numero de bytes da captura disponivel
					len : um "bpf_u_int32" contendo o numero total de bytes obtidos na captura [que pode ser superior ao numero de bytes disponiveis] 
const unsigned char *data --> campo de dados do pacote capturado [No caso o pacote ipv6]
*/
void check_packets(u_char * foo, const struct pcap_pkthdr *header, const unsigned char *data) {
  int i, ok = 1;
  unsigned char *ptr = (unsigned char *) data + 14;     // pulando para o campo de src addr

  // Funcao de debug, realiza o dump do pacote capturado na tela
  if (debug) {
    thc_dump_data(ptr, header->caplen - 14, "Received Packet");
  }
  // Verificacao caso o IP[Host] ja tenha sido dado como "alive" 
  i = 0;
  while (ok && i < alive_no) {
    if ((memcmp(alive[i], ptr + 8, 16) == 0)
        && (memcmp(aliveMac[i], ptr - 8, 6) == 0))
      ok = 0;
    i++;
  }

  // Se passou em todas as verificacoes, o endereco de origem eh armazenado em memoria
  if (ok && ((alive[alive_no] = malloc(16)) != NULL)
      && ((aliveMac[alive_no] = malloc(6)) != NULL)) {
    printf(".");
    memcpy(alive[alive_no], (ptr + 8), 16);
    memcpy(aliveMac[alive_no], (ptr - 8), 6);
    alive_no++;
  }
}
Example #12
0
static int
decodeBitCometClient( char * buf, size_t buflen, const uint8_t * id )
{
    int is_bitlord;
    int major, minor;
    const char * name;
    const char * mod = NULL;

    if( !memcmp( id, "exbc", 4 ) ) mod = "";
    else if( !memcmp( id, "FUTB", 4 )) mod = "(Solidox Mod) ";
    else if( !memcmp( id, "xUTB", 4 )) mod = "(Mod 2) ";
    else return FALSE;

    is_bitlord = !memcmp( id+6, "LORD", 4 );
    name = (is_bitlord) ? "BitLord " : "BitComet ";
    major = id[4];
    minor = id[5];

    /**
     * Bitcomet, and older versions of BitLord, are of the form x.yy.
     * Bitcoment 1.0 and onwards are of the form x.y.
     */
    if( is_bitlord && major>0 )
        tr_snprintf( buf, buflen, "%s%s%d.%d", name, mod, major, minor );
    else
        tr_snprintf( buf, buflen, "%s%s%d.%02d", name, mod, major, minor );

    return TRUE;
}
Example #13
0
int
sockaddr_cmp_addr(struct sockaddr_storage *addr1,
                  struct sockaddr_storage *addr2, socklen_t len)
{
    struct sockaddr_in *p1_in   = (struct sockaddr_in *)addr1;
    struct sockaddr_in *p2_in   = (struct sockaddr_in *)addr2;
    struct sockaddr_in6 *p1_in6 = (struct sockaddr_in6 *)addr1;
    struct sockaddr_in6 *p2_in6 = (struct sockaddr_in6 *)addr2;
    if (p1_in->sin_family < p2_in->sin_family)
        return -1;
    if (p1_in->sin_family > p2_in->sin_family)
        return 1;
    if (verbose) {
        LOGI("sockaddr_cmp_addr: sin_family equal? %d", p1_in->sin_family == p2_in->sin_family);
    }
    /* compare ip4 */
    if (p1_in->sin_family == AF_INET) {
        return memcmp(&p1_in->sin_addr, &p2_in->sin_addr, INET_SIZE);
    } else if (p1_in6->sin6_family == AF_INET6) {
        return memcmp(&p1_in6->sin6_addr, &p2_in6->sin6_addr,
                      INET6_SIZE);
    } else {
        /* eek unknown type, perform this comparison for sanity. */
        return memcmp(addr1, addr2, len);
    }
}
Example #14
0
/**
 * psb_intel_init_bios - initialize VBIOS settings & find VBT
 * @dev: DRM device
 *
 * Loads the Video BIOS and checks that the VBT exists.  Sets scratch registers
 * to appropriate values.
 *
 * VBT existence is a sanity check that is relied on by other i830_bios.c code.
 * Note that it would be better to use a BIOS call to get the VBT, as BIOSes may
 * feed an updated VBT back through that, compared to what we'll fetch using
 * this method of groping around in the BIOS data.
 *
 * Returns 0 on success, nonzero on failure.
 */
int psb_intel_init_bios(struct drm_device *dev)
{
	struct drm_psb_private *dev_priv = dev->dev_private;
	struct pci_dev *pdev = dev->pdev;
	struct vbt_header *vbt = NULL;
	struct bdb_header *bdb = NULL;
	u8 __iomem *bios = NULL;
	size_t size;
	int i;


	dev_priv->panel_type = 0xff;

	/* XXX Should this validation be moved to intel_opregion.c? */
	if (dev_priv->opregion.vbt) {
		struct vbt_header *vbt = dev_priv->opregion.vbt;
		if (memcmp(vbt->signature, "$VBT", 4) == 0) {
			DRM_DEBUG_KMS("Using VBT from OpRegion: %20s\n",
					 vbt->signature);
			bdb = (struct bdb_header *)((char *)vbt + vbt->bdb_offset);
		} else
			dev_priv->opregion.vbt = NULL;
	}

	if (bdb == NULL) {
		bios = pci_map_rom(pdev, &size);
		if (!bios)
			return -1;

		/* Scour memory looking for the VBT signature */
		for (i = 0; i + 4 < size; i++) {
			if (!memcmp(bios + i, "$VBT", 4)) {
				vbt = (struct vbt_header *)(bios + i);
				break;
			}
		}

		if (!vbt) {
			dev_err(dev->dev, "VBT signature missing\n");
			pci_unmap_rom(pdev, bios);
			return -1;
		}
		bdb = (struct bdb_header *)(bios + i + vbt->bdb_offset);
	}

	/* Grab useful general dxefinitions */
	parse_general_features(dev_priv, bdb);
	parse_driver_features(dev_priv, bdb);
	parse_lfp_panel_data(dev_priv, bdb);
	parse_sdvo_panel_data(dev_priv, bdb);
	parse_sdvo_device_mapping(dev_priv, bdb);
	parse_device_mapping(dev_priv, bdb);
	parse_backlight_data(dev_priv, bdb);
	parse_edp(dev_priv, bdb);

	if (bios)
		pci_unmap_rom(pdev, bios);

	return 0;
}
Example #15
0
static int
source_compare(const unsigned char *id,
               const unsigned char *prefix, unsigned char plen,
               const unsigned char *src_prefix, unsigned char src_plen,
               const struct source *src)
{
    int rc;

    rc = memcmp(id, src->id, 8);
    if(rc != 0)
        return rc;

    if(plen < src->plen)
        return -1;
    if(plen > src->plen)
        return 1;

    rc = memcmp(prefix, src->prefix, 16);
    if(rc != 0)
        return rc;

    if(src_plen < src->src_plen)
        return -1;
    if(src_plen > src->src_plen)
        return 1;

    rc = memcmp(src_prefix, src->src_prefix, 16);
    if(rc != 0)
        return rc;

    return 0;
}
void check_DC_DC(int dip)
{
    unsigned char zero_array[16];

    memset(zero_array, 0, 16); 

    if(dip < 96)
    { 
        if(memcmp (zero_array, survstatbuf, 12) == 0)
            MainDC_DC = false;
        else 
            MainDC_DC = true;

        if(memcmp (zero_array, survstatbuf2, 12) == 0) 
            StdbyDC_DC = false;
         else 
            StdbyDC_DC = true;
    } 
    else 
    { 
         if(memcmp(&zero_array[12], &survstatbuf[12], 4) == 0)
           MainDC_DC = false; 
         else 
           MainDC_DC = true; 

         if(memcmp(&zero_array[12], &survstatbuf2[12], 4) == 0) 
            StdbyDC_DC = false;
         else 
            StdbyDC_DC = true;
    } 

}
Example #17
0
File: network.c Project: hgn/ospfd
/* return true if both addresses are equal - otherwise false */
int list_cmp_struct_ip_addr(const void *a, const void *b)
{
	const struct ip_addr *aa = (struct ip_addr *) a;
	const struct ip_addr *bb = (struct ip_addr *) b;

	if (aa->family != bb->family)
		return 0;

	switch (aa->family) {

		case AF_INET:
			if (aa->ipv4.addr.s_addr      == bb->ipv4.addr.s_addr    &&
			    aa->ipv4.netmask.s_addr   == bb->ipv4.netmask.s_addr &&
			    aa->ipv4.broadcast.s_addr == bb->ipv4.broadcast.s_addr)
				return 1;
			else
				return 0;
			break;

		case AF_INET6:
			if (!(memcmp(&aa->ipv6.addr, &bb->ipv6.addr, sizeof(struct in6_addr)))       &&
			    !(memcmp(&aa->ipv6.netmask, &bb->ipv6.netmask, sizeof(struct in6_addr))) &&
			     (aa->ipv6.scope == bb->ipv6.scope))
				return 1;
			else
				return 0;
		default:
			/* dont know how to compare */
			abort();
	}
}
Example #18
0
int plist_data_compare(const void *a, const void *b)
{
    plist_data_t val_a = NULL;
    plist_data_t val_b = NULL;

    if (!a || !b)
        return FALSE;

    if (!((node_t*) a)->data || !((node_t*) b)->data)
        return FALSE;

    val_a = plist_get_data((plist_t) a);
    val_b = plist_get_data((plist_t) b);

    if (val_a->type != val_b->type)
        return FALSE;

    switch (val_a->type)
    {
    case PLIST_BOOLEAN:
    case PLIST_UINT:
    case PLIST_REAL:
    case PLIST_UID:
        if (val_a->intval == val_b->intval)	//it is an union so this is sufficient
            return TRUE;
        else
            return FALSE;

    case PLIST_KEY:
    case PLIST_STRING:
        if (!strcmp(val_a->strval, val_b->strval))
            return TRUE;
        else
            return FALSE;

    case PLIST_DATA:
        if (val_a->length != val_b->length)
            return FALSE;
        if (!memcmp(val_a->buff, val_b->buff, val_a->length))
            return TRUE;
        else
            return FALSE;
    case PLIST_ARRAY:
    case PLIST_DICT:
        //compare pointer
        if (a == b)
            return TRUE;
        else
            return FALSE;
        break;
    case PLIST_DATE:
        if (!memcmp(&(val_a->timeval), &(val_b->timeval), sizeof(timeval_t)))
            return TRUE;
        else
            return FALSE;
    default:
        break;
    }
    return FALSE;
}
Example #19
0
//set:sxxx.x#
void ds_ascii_command_parser(char* scmd)
{
    int16_t temp;

    //set:sxxx.x#
    if(memcmp(scmd, "set:",4)!=NULL)
    {
        temp = parse_temperature(tmp+4);
        printf("Teplota nastavena na %d",temp);
    }
    else if(memcmp(scmd, "ramp:",5)!=NULL)
    {
      //ramp:sxxx.x#

    }
    else if(strstr (scmd, "lookup:",7)!=NULL)
    {

    }
    else
    {
        // error
    }

}
bool CSymbolEngineMemorySymbols::EvaluateSymbol(const char *name, double *result, bool log /* = false */) {
  // memory-commands
  // "name" = query
  FAST_EXIT_ON_OPENPPL_SYMBOLS(name);
  if (memcmp(name, "me_", 3) == 0) {
    write_log(preferences.debug_memorysymbols(), 
      "[CSymbolEngineMemorySymbols] EvaluateSymbol(%s)\n", name);
    if (memcmp(name, "me_st_", 6) == 0) {  
      Store(name);
      *result = kUndefinedZero;
      return true;
    } else if (memcmp(name, "me_re_", 6) == 0) {
      *result = Recall(name);
      return true;
    } else if (memcmp(name, "me_inc_", 7) == 0) {
      Increment(name);
      *result = kUndefinedZero;
      return true;
    } else {
    // Looks like a memory-command, but is invalid
    return false;
    }
  }
  // Not a memory symbol
  return false;
}
Example #21
0
int
main (void)
{
  char target[50];
  size_t targsize = sizeof (target);
  int len;

  len = gsasl_base64_encode ("foobar", 6, target, targsize);
  printf ("base64_encode(foobar, 6) = %d, %.*s\n", len, len, target);
  if (len != 8 || memcmp (target, "Zm9vYmFy", len) != 0)
    {
      printf ("base64_encode failure\n");
      return EXIT_FAILURE;
    }

  len = gsasl_base64_decode ("Zm9vYmFy", target, targsize);
  printf ("base64_decode(Zm9vYmFy, 8) = %d, %.*s\n", len, len, target);
  if (len != 6 || memcmp (target, "foobar", len) != 0)
    {
      printf ("base64_decode failure\n");
      return EXIT_FAILURE;
    }

  return EXIT_SUCCESS;
}
Example #22
0
static void test_sms_migrate(void)
{
	struct gsm_subscriber *rcv_subscr;
	struct gsm_sms *sms;
	static const uint8_t user_data_1[] = {
		0x41, 0xf1, 0xd8, 0x05, 0x22, 0x96, 0xcd, 0x2e,
		0x90, 0xf1, 0xfd, 0x06, 0x00 };
	static const uint8_t user_data_2[] = {
		0x41, 0xf1, 0xd8, 0x05, 0x22, 0x96, 0xcd, 0x2e,
		0xd0, 0xf1, 0xfd, 0x06, 0x00 };

	rcv_subscr = db_get_subscriber(GSM_SUBSCRIBER_IMSI, "901010000001111");
	rcv_subscr->group = &dummy_sgrp;

	sms = db_sms_get(&dummy_net, 1);
	OSMO_ASSERT(sms->id == 1);
	OSMO_ASSERT(sms->receiver == rcv_subscr);
	OSMO_ASSERT(strcmp(sms->text, "Abc. Def. Foo") == 0);
	OSMO_ASSERT(sms->user_data_len == ARRAY_SIZE(user_data_1));
	OSMO_ASSERT(memcmp(sms->user_data, user_data_1, ARRAY_SIZE(user_data_1)) == 0);
	sms_free(sms);

	sms = db_sms_get(&dummy_net, 2);
	OSMO_ASSERT(sms->id == 2);
	OSMO_ASSERT(sms->receiver == rcv_subscr);
	OSMO_ASSERT(strcmp(sms->text, "Abc. Def. Goo") == 0);
	OSMO_ASSERT(sms->user_data_len == ARRAY_SIZE(user_data_2));
	OSMO_ASSERT(memcmp(sms->user_data, user_data_2, ARRAY_SIZE(user_data_2)) == 0);
	sms_free(sms);

	subscr_put(rcv_subscr);
}
Example #23
0
/* Returns 1 if the data packet is for us and 0 otherwise. */
static int is_data_packet_for_us(struct ieee80211_device *ieee,
	                         struct ieee80211_hdr_4addr *hdr)
{
	struct net_device *netdev = ieee->dev;
	u16 fc = le16_to_cpu(hdr->frame_ctl);

	ZD_ASSERT(WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA);

	switch (ieee->iw_mode) {
	case IW_MODE_ADHOC:
		if ((fc & (IEEE80211_FCTL_TODS|IEEE80211_FCTL_FROMDS)) != 0 ||
		    memcmp(hdr->addr3, ieee->bssid, ETH_ALEN) != 0)
			return 0;
		break;
	case IW_MODE_AUTO:
	case IW_MODE_INFRA:
		if ((fc & (IEEE80211_FCTL_TODS|IEEE80211_FCTL_FROMDS)) !=
		    IEEE80211_FCTL_FROMDS ||
		    memcmp(hdr->addr2, ieee->bssid, ETH_ALEN) != 0)
			return 0;
		break;
	default:
		ZD_ASSERT(ieee->iw_mode != IW_MODE_MONITOR);
		return 0;
	}

	return memcmp(hdr->addr1, netdev->dev_addr, ETH_ALEN) == 0 ||
	       (is_multicast_ether_addr(hdr->addr1) &&
		memcmp(hdr->addr3, netdev->dev_addr, ETH_ALEN) != 0) ||
	       (netdev->flags & IFF_PROMISC);
}
Example #24
0
/**
 * Returns 0 if the the normal form of the two unit
 * structures are the same or > 0 if they are different.  It returns
 * \c #XLAL_FAILURE and \c ::xlalErrno is set to \c #XLAL_EFAULT if
 * one of the input pointers is \c NULL.
 *
 * Example:
 * \code
 * if(XLALUnitCompare(&unit1, &unit2)) {
 *   units_are_not_equal();
 * }
 * \endcode
 */
int XLALUnitCompare( const LALUnit *unit1, const LALUnit *unit2 )
{
  LALUnit  unitOne, unitTwo;

  if ( ! unit1 || ! unit2 )
    XLAL_ERROR( XLAL_EFAULT );

  unitOne = *unit1;
  unitTwo = *unit2;

  /* normalize the units */
  if ( XLALUnitNormalize( &unitOne ) )
    XLAL_ERROR( XLAL_EFUNC );
  if ( XLALUnitNormalize( &unitTwo ) )
    XLAL_ERROR( XLAL_EFUNC );

  /* factors of 10 disagree? */
  if ( unitOne.powerOfTen != unitTwo.powerOfTen )
    return 1;

  /* powers of dimensions disagree? use memcmp() to compare the arrays */
  if ( memcmp( unitOne.unitNumerator, unitTwo.unitNumerator, LALNumUnits * sizeof( *unitOne.unitNumerator ) ) )
    return 1;
  if ( memcmp( unitOne.unitDenominatorMinusOne, unitTwo.unitDenominatorMinusOne, LALNumUnits * sizeof( *unitOne.unitDenominatorMinusOne ) ) )
    return 1;

  /* agree in all possible ways */
  return 0;
}
Example #25
0
/* Status callback for the SCD GENKEY command. */
static gpg_error_t
scd_genkey_cb (void *opaque, const char *line)
{
    struct agent_card_genkey_s *parm = opaque;
    const char *keyword = line;
    int keywordlen;

    for (keywordlen=0; *line && !spacep (line); line++, keywordlen++)
        ;
    while (spacep (line))
        line++;

    if (keywordlen == 7 && !memcmp (keyword, "KEY-FPR", keywordlen))
    {
        parm->fprvalid = unhexify_fpr (line, parm->fpr);
    }
    else if (keywordlen == 14 && !memcmp (keyword,"KEY-CREATED-AT", keywordlen))
    {
        parm->created_at = (u32)strtoul (line, NULL, 10);
    }
    else if (keywordlen == 8 && !memcmp (keyword, "PROGRESS", keywordlen))
    {
        write_status_text (STATUS_PROGRESS, line);
    }

    return 0;
}
Example #26
0
static void *
find_entry (char *signature)
{
	struct rsdt *p;
	struct description_header *q;
	int i, n, len;
	u32 entry;

	if (!rsdp_found)
		return NULL;
	p = acpi_mapmem (rsdp_copy.rsdt_address, sizeof *p);
	if (memcmp (p->header.signature, RSDT_SIGNATURE, SIGNATURE_LEN))
		return NULL;
	len = p->header.length;
	p = acpi_mapmem (rsdp_copy.rsdt_address, len);
	if (acpi_checksum (p, len))
		return NULL;
	n = (p->header.length - sizeof p->header) / sizeof entry;
	for (i = 0; i < n; i++) {
		p = acpi_mapmem (rsdp_copy.rsdt_address, len);
		entry = p->entry[i];
		q = acpi_mapmem (entry, sizeof *q);
		if (memcmp (q->signature, signature, SIGNATURE_LEN))
			continue;
		q = acpi_mapmem (entry, q->length);
		if (acpi_checksum (q, q->length))
			continue;
		return q;
	}
	return NULL;
}
Example #27
0
void unbound_stat_free_lite(void *ptr, const char* file, int line,
        const char* func)
{
	void* real;
	size_t orig = 0;
	if(!ptr) return;
	real = ptr-lite_pad-sizeof(size_t);
	if(memcmp(real, lite_pre, lite_pad) != 0) {
		log_err("free(): prefix failed %s:%d %s", file, line, func);
		log_hex("prefix here", real, lite_pad);
		log_hex("  should be", lite_pre, lite_pad);
		fatal_exit("alloc assertion failed");
	}
	memmove(&orig, real+lite_pad, sizeof(size_t));
	if(memcmp(real+lite_pad+orig+sizeof(size_t), lite_post, lite_pad)!=0){
		log_err("free(): suffix failed %s:%d %s", file, line, func);
		log_err("alloc size is %d", (int)orig);
		log_hex("suffix here", real+lite_pad+orig+sizeof(size_t), 
			lite_pad);
		log_hex("  should be", lite_post, lite_pad);
		fatal_exit("alloc assertion failed");
	}
	memset(real, 0xdd, orig+lite_pad*2+sizeof(size_t)); /* mark it */
	free(real);
}
Example #28
0
static int
read_binary_header(const uint8_t *bin, size_t *bin_size, uint16_t *crc, uint8_t *flags)
{
  const struct rite_binary_header *header = (const struct rite_binary_header *)bin;

  if (memcmp(header->binary_ident, RITE_BINARY_IDENT, sizeof(header->binary_ident)) == 0) {
    if (bigendian_p())
      *flags |= FLAG_BYTEORDER_NATIVE;
    else
      *flags |= FLAG_BYTEORDER_BIG;
  }
  else if (memcmp(header->binary_ident, RITE_BINARY_IDENT_LIL, sizeof(header->binary_ident)) == 0) {
    if (bigendian_p())
      *flags |= FLAG_BYTEORDER_LIL;
    else
      *flags |= FLAG_BYTEORDER_NATIVE;
  }
  else {
    return MRB_DUMP_INVALID_FILE_HEADER;
  }

  if (crc) {
    *crc = bin_to_uint16(header->binary_crc);
  }
  *bin_size = (size_t)bin_to_uint32(header->binary_size);

  return MRB_DUMP_OK;
}
Example #29
0
static void gdb_handle_set_thread()
{
  if (memcmp(cmd_bfr, "Hg0", 3) == 0 || memcmp(cmd_bfr, "Hc-1", 4) == 0 ||
      memcmp(cmd_bfr, "Hc0", 4) == 0 || memcmp(cmd_bfr, "Hc1", 4) == 0)
    return gdb_reply("OK");
  gdb_reply("E01");
}
Example #30
0
static EcBool ustring_compare( EC_OBJ obj1, EC_OBJ obj2, EcInt *res )
{
	EcInt l1;
	EcInt l2;
	int t;

	if (! EC_USTRINGP(obj2))
		return FALSE;

	l1 = EC_USTRLEN(obj1);
	l2 = EC_USTRLEN(obj2);

	if (l1 < l2)
	{
		t = memcmp( EC_USTRDATA(obj1), EC_USTRDATA(obj2), l1 );
		if (t <= 0)
			*res = -1;
		else
			*res = 1;
	}
	else if (l1 > l2)
	{
		t = memcmp( EC_USTRDATA(obj1), EC_USTRDATA(obj2), l2 );
		if (t >= 0)
			*res = 1;
		else
			*res = -1;
	}
	else
		*res = uni_strcmp( EC_USTRDATA(obj1), EC_USTRDATA(obj2) );

	return TRUE;
}