Esempio n. 1
0
int hex2bin (const char *phex, unsigned char *pbin, int size)
{
    int i;

    for (i = 0; i < size; i++, phex += 2, pbin++) {
    	*pbin = (unsigned char)(c2hex (phex[0]) * 16 + c2hex (phex[1]));
    }

    return i;
}
Esempio n. 2
0
void print_ip_steady(int line, int col)
{
	if (!line) {
		if (!col) {
			print_lim();
			fprintf(stderr, WC "|" FC "Ver: " VC "%c ", tok[0]);
			fprintf(stderr, WC "|" FC "IHL: " VC "%c ", tok[1]);

			ip.hlen = c2hex(tok[1]);
			/* if header length is > 5 (in 32bit words) then
			   we must take into account to view the additional 
			   options in the ip header */
			if (ip.hlen > 5) {
				ip.options++;
				ip.left = (ip.hlen - 5) << 1;
			}
			else 
				ip.options = 0;

			fprintf(stderr, WC "|" FC "   ToS: " VC "%s     ", &tok[2]);
		}
		else if (col == 1) {
			/* copy the next portion of XXXX inside buf 
			   take into account that there is a space between
			   each of the 4-char hex pairs that get formed */
			ip.total_len =	((((c2hex(tok[0]) & 0x0f) << 12) 
					| ((c2hex(tok[1]) & 0x0f) << 8)) 
					| ((c2hex(tok[2]) & 0x0f) << 4))
					| (c2hex(tok[3]) & 0x0f);

			fprintf(stderr, WC "|" FC "       Total Length: " VC "%s      " WC "|", tok);
			print_lim();
		}
		else if (col == 2) {
			fprintf(stderr, WC "|" FC "      Identification: " VC "%s     ",  tok);
		}
		else if (col == 3) {
			/* this (not really)obfu thing prints the 3bit flags of the ip header */
			char c = c2hex(tok[0]);
			fprintf(stderr, WC "|" FC "F: " VC "%x ", (c & 0x0e) >> 1);

			/* print the 13bit fragment offset */
			unsigned int t; 
			t = 	((((c & 0x01) << 12)
				| ((c2hex(tok[1]) & 0x0f) << 8)) 
				| ((c2hex(tok[2]) & 0x0f) << 4))
				| (c2hex(tok[3]) & 0x0f);
			fprintf(stderr, WC "|" FC "   Fragment Offset:" VC "%4x  " WC "|", t);
			print_lim();
		}
		else if (col == 4) {
Esempio n. 3
0
 void UUID::setUUID(const std::string & uuid_string) {
   //reset UUID to zero
   for (int i = 0; i < 4; ++i) {
     ((uint32_t *)(data + 8))[i] = 0;
   }
   //set the UUID from the string, char by char
   int i = 0;
   for (size_t j = 0; j < uuid_string.size(); ++j) {
     if (uuid_string[j] == '-') {
       continue;
     }
     data[8 + i / 2] |= (c2hex(uuid_string[j]) << ((~i & 1) << 2));
     ++i;
   }
 }