Esempio n. 1
0
File: mjd.c Progetto: q-bits/Antares
double tfdt_to_year(struct tf_datetime * dt)
{
    int mjd = get_u16(&dt->mjd);

    return ((mjd - 15078.2) / 365.25);
       
}
Esempio n. 2
0
static Sophon_Result
get_str (Sophon_VM *vm, Sophon_IOFunc func, Sophon_Ptr data,
			Sophon_Bool can_be_empty, Sophon_String **pstr)
{
	Sophon_U32 len;
	Sophon_U16 ch;
	Sophon_String *str;
	Sophon_Char *ptr;
	Sophon_Result r;

	if ((r = get_u32(func, data, &len)) != SOPHON_OK)
		return r;

	if (!len && can_be_empty) {
		*pstr = NULL;
		return SOPHON_OK;
	}

	str = sophon_string_from_chars(vm, NULL, len);
	ptr = sophon_string_chars(vm, str);
	while (len--) {
		if ((r = get_u16(func, data, &ch)) != SOPHON_OK)
			return r;
		*ptr++ = ch;
	}

	*pstr = str;
	return SOPHON_OK;
}
Esempio n. 3
0
/*
 * Retrieves a BIGNUM from the buffer.
 */
int
buffer_get_bignum_ret(Buffer *buffer, BIGNUM *value)
{
	u_int bits, bytes;
	u_char buf[2], *bin;

	/* Get the number of bits. */
	if (buffer_get_ret(buffer, (char *) buf, 2) == -1) {
		error("buffer_get_bignum_ret: invalid length");
		return (-1);
	}
	bits = get_u16(buf);
	/* Compute the number of binary bytes that follow. */
	bytes = (bits + 7) / 8;
	if (bytes > 8 * 1024) {
		error("buffer_get_bignum_ret: cannot handle BN of size %d", bytes);
		return (-1);
	}
	if (buffer_len(buffer) < bytes) {
		error("buffer_get_bignum_ret: input buffer too small");
		return (-1);
	}
	bin = buffer_ptr(buffer);
	if (BN_bin2bn(bin, bytes, value) == NULL) {
		error("buffer_get_bignum_ret: BN_bin2bn failed");
		return (-1);
	}
	if (buffer_consume_ret(buffer, bytes) == -1) {
		error("buffer_get_bignum_ret: buffer_consume failed");
		return (-1);
	}
	return (0);
}
Esempio n. 4
0
static void handle_write_req(ble_service_t *svc, const ble_evt_gatts_write_req_t *evt)
{
        dlgdebug_service_t *dbgs = (dlgdebug_service_t *) svc;
        att_error_t status = ATT_ERROR_WRITE_NOT_PERMITTED;

        if (evt->handle == dbgs->cp_ccc_h) {
                uint16_t ccc_val;

                if (evt->offset) {
                        status = ATT_ERROR_ATTRIBUTE_NOT_LONG;
                        goto done;
                }

                if (evt->length != sizeof(uint16_t)) {
                        status = ATT_ERROR_APPLICATION_ERROR;
                        goto done;
                }

                ccc_val = get_u16(evt->value);

                ble_storage_put_u32(evt->conn_idx, dbgs->cp_ccc_h, ccc_val, true);

                status = ATT_ERROR_OK;

                goto done;
        }

        if (evt->handle == dbgs->cp_val_h) {
                status = handle_cp_val_write(dbgs, evt);
        }

done:
        ble_gatts_write_cfm(evt->conn_idx, evt->handle, status);
}
static int
hfsc_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
{
	struct tc_hfsc_qopt qopt;

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

	while (argc > 0) {
		if (matches(*argv, "default") == 0) {
			NEXT_ARG();
			if (qopt.defcls != 0) {
				fprintf(stderr, "HFSC: Double \"default\"\n");
				return -1;
			}
			if (get_u16(&qopt.defcls, *argv, 16) < 0) {
				explain1("default");
				return -1;
			}
		} else if (matches(*argv, "help") == 0) {
			explain_qdisc();
			return -1;
		} else {
			fprintf(stderr, "HFSC: What is \"%s\" ?\n", *argv);
			explain_qdisc();
			return -1;
		}
		argc--, argv++;
	}

	addattr_l(n, 1024, TCA_OPTIONS, &qopt, sizeof(qopt));
	return 0;
}
Esempio n. 6
0
File: mjd.c Progetto: q-bits/Antares
/* Convert Topfield MJD date and time structure to time_t */
time_t tfdt_to_time(struct tf_datetime * dt)
{
    int mjd = get_u16(&dt->mjd);
    int y, m, d, k;
    struct tm tm;
    time_t result;

    y = (int) ((mjd - 15078.2) / 365.25);
    m = (int) ((mjd - 14956.1 - ((int) (y * 365.25))) / 30.6001);
    d = mjd - 14956 - ((int) (y * 365.25)) - ((int) (m * 30.6001));
    if((m == 14) || (m == 15))
    {
        k = 1;
    }
    else
    {
        k = 0;
    }
    y += k;
    m = m - 1 - k * 12;

    tm.tm_sec = dt->second;
    tm.tm_min = dt->minute;
    tm.tm_hour = dt->hour;
    tm.tm_mday = d;
    tm.tm_mon = m - 1;
    tm.tm_year = y;
    tm.tm_wday = 0;
    tm.tm_yday = 0;
    tm.tm_isdst = -1;

    result = mktime(&tm);
    return result;
}
Esempio n. 7
0
static void DmpLocList( uint_32 start, uint addr_size )
/*****************************************************/
{
    uint_32         low;
    uint_32         high;
    int             len;
    uint_8 const    *p;
    uint_8 const    *stop;

    p = Sections[ DW_DEBUG_LOC ].data;
    stop = p + Sections[ DW_DEBUG_LOC ].max_offset;
    if( p == NULL ) {
        Wdputslc( "Error: No location list section\n" );
        return;
    }
    p += start;
    while( p < stop ) {
        p = GetInt( p, &low, addr_size );
        p = GetInt( p, &high, addr_size );
        if( low == high && low == 0 ) {
            Wdputslc( "        <end>\n" );
            return;
        }
        len = get_u16( (uint_16 *)p );
        p+= sizeof( uint_16 );
        Wdputslc( "\n         Range: " );
        Puthex( low, addr_size * 2 );
        Wdputs( ":" );
        Puthex( high, addr_size * 2 );
        Wdputslc( "\n" );
        DmpLoc( p, len, addr_size );
        p += len;
    }
}
Esempio n. 8
0
void decode_dir(struct tf_packet *p)
{
    __u16 count =
        (get_u16(&p->length) - PACKET_HEAD_SIZE) / sizeof(struct typefile);
    struct typefile *entries = (struct typefile *) p->data;
    int i;
    time_t timestamp;
    if (xml) {
      printf("<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>\r\n\r\n");
      printf("<contents>\n");
    }
    for(i = 0; (i < count); i++)
    {
        /* This makes the assumption that the timezone of the Toppy and the system
         * that puppy runs on are the same. Given the limitations on the length of
         * USB cables, this condition is likely to be satisfied. */
      struct tm tm;
        timestamp = tfdt_to_time(&entries[i].stamp);
        tm = *localtime(&timestamp);
        if (xml) {
          int ft = entries[i].filetype;
          printf("<file type=\"%s\" size=\"%llu\" time=\"%04d-%02d-%02d %d:%02d:%02d\" name=\"%W\"/>\n",
                 ft == 1 ? "dir" :
                 ft == 2 ? "file" :
                           "unknown",
                 get_u64(&entries[i].size),
                 tm.tm_year + 1900,
                 tm.tm_mon + 1,
                 tm.tm_mday,
                 tm.tm_hour,
                 tm.tm_min,
                 tm.tm_sec,
                 entries[i].name);
        } else {
          char type;

          switch (entries[i].filetype)
          {
          case 1:
            type = 'd';
            break;

          case 2:
            type = 'f';
            break;

          default:
            type = '?';
          }

          printf("%c %20llu %24.24s %s\n", type, get_u64(&entries[i].size),
                 ctime(&timestamp), entries[i].name);
        }
    }
    if (xml) {
      printf("</contents>\n");
    }
}
Esempio n. 9
0
static int vlan_parse_opt(struct link_util *lu, int argc, char **argv,
			  struct nlmsghdr *n)
{
	struct ifla_vlan_flags flags = { 0 };
	__u16 id;

	while (argc > 0) {
		if (matches(*argv, "id") == 0) {
			NEXT_ARG();
			if (get_u16(&id, *argv, 0))
				invarg("id is invalid", *argv);
			addattr_l(n, 1024, IFLA_VLAN_ID, &id, 2);
		} else if (matches(*argv, "reorder_hdr") == 0) {
			NEXT_ARG();
			flags.mask |= VLAN_FLAG_REORDER_HDR;
			if (strcmp(*argv, "on") == 0)
				flags.flags |= VLAN_FLAG_REORDER_HDR;
			else if (strcmp(*argv, "off") == 0)
				flags.flags &= ~VLAN_FLAG_REORDER_HDR;
			else
				return on_off("reorder_hdr");
		} else if (matches(*argv, "gvrp") == 0) {
			NEXT_ARG();
			flags.mask |= VLAN_FLAG_GVRP;
			if (strcmp(*argv, "on") == 0)
				flags.flags |= VLAN_FLAG_GVRP;
			else if (strcmp(*argv, "off") == 0)
				flags.flags &= ~VLAN_FLAG_GVRP;
			else
				return on_off("gvrp");
		} else if (matches(*argv, "ingress-qos-map") == 0) {
			NEXT_ARG();
			if (vlan_parse_qos_map(&argc, &argv, n,
					       IFLA_VLAN_INGRESS_QOS))
				invarg("invalid ingress-qos-map", *argv);
			continue;
		} else if (matches(*argv, "egress-qos-map") == 0) {
			NEXT_ARG();
			if (vlan_parse_qos_map(&argc, &argv, n,
					       IFLA_VLAN_EGRESS_QOS))
				invarg("invalid egress-qos-map", *argv);
			continue;
		} else if (matches(*argv, "help") == 0) {
			explain();
			return -1;
		} else {
			fprintf(stderr, "vlan: what is \"%s\"?\n", *argv);
			explain();
			return -1;
		}
		argc--, argv++;
	}

	if (flags.mask)
		addattr_l(n, 1024, IFLA_VLAN_FLAGS, &flags, sizeof(flags));

	return 0;
}
Esempio n. 10
0
void
street_name_get(struct street_name *name, unsigned char **p)
{
	unsigned char *start=*p;
	name->len=get_u16(p);
	name->country=get_u16(p);
	name->townassoc=get_u32(p);
	name->name1=get_string(p);
	name->name2=get_string(p);
	name->segment_count=get_u32(p);
	name->segments=(struct street_name_segment *)(*p);
	(*p)+=(sizeof (struct street_name_segment))*name->segment_count;
	name->aux_len=name->len-(*p-start);
	name->aux_data=*p;
	name->tmp_len=name->aux_len;
	name->tmp_data=name->aux_data;
	(*p)+=name->aux_len;
}
Esempio n. 11
0
/*Search for WinMX commands*/
int
search_winmx (const unsigned char *payload, const u16 plen)
{
//#define IPP2P_DEBUG_WINMX
    if (((plen) == 4) && (memcmp(payload, "SEND", 4) == 0))  return ((IPP2P_WINMX * 100) + 1);
    if (((plen) == 3) && (memcmp(payload, "GET", 3) == 0))  return ((IPP2P_WINMX * 100) + 2);
    //if (packet_len < (head_len + 10)) return 0;
    if (plen < 10) return 0;

    if ((memcmp(payload, "SEND", 4) == 0) || (memcmp(payload, "GET", 3) == 0)) {
        u16 c=4;
        const u16 end=plen-2;
        u8 count=0;
        while (c < end)
        {
            if (payload[c]== 0x20 && payload[c+1] == 0x22)
            {
                c++;
                count++;
                if (count>=2) return ((IPP2P_WINMX * 100) + 3);
            }
            c++;
        }
    }

    if ( plen == 149 && payload[0] == '8' )
    {
#ifdef IPP2P_DEBUG_WINMX
        printk(KERN_INFO "maybe WinMX\n");
#endif
        if (get_u32(payload,17) == 0 && get_u32(payload,21) == 0 && get_u32(payload,25) == 0 &&
//    	    get_u32(payload,33) == __constant_htonl(0x71182b1a) && get_u32(payload,37) == __constant_htonl(0x05050000) &&
//    	    get_u32(payload,133) == __constant_htonl(0x31097edf) && get_u32(payload,145) == __constant_htonl(0xdcb8f792))
                get_u16(payload,39) == 0 && get_u16(payload,135) == __constant_htons(0x7edf) && get_u16(payload,147) == __constant_htons(0xf792))

        {
#ifdef IPP2P_DEBUG_WINMX
            printk(KERN_INFO "got WinMX\n");
#endif
            return ((IPP2P_WINMX * 100) + 4);
        }
    }
    return 0;
} /*search_winmx*/
Esempio n. 12
0
static void dump_aranges( const uint_8 *p, uint length )
/******************************************************/
{
    const uint_8    *end;
    const uint_8    *unit_end;
    uint_32         unit_length;
    uint_32         dbg_offset;
    uint_32         addr;
    uint_32         seg;
    uint_32         len;
    int             addr_size;
    int             seg_size;

    end = &p[length];
    addr_size = 0;
    while( p  < end ) {
        unit_length = get_u32( (uint_32 *)p );
        unit_end = &p[unit_length + sizeof( uint_32 )];
        Wdputs( "Length: " );
        Puthex( unit_length, 8 );
        Wdputslc( "\nVersion: " );
        Puthex( get_u16( (uint_16 *)(p + 4) ), 4 );
        Wdputslc( "\nDbg Info: " );
        dbg_offset = get_u32( (uint_32 *)(p + 6) );
        Puthex( dbg_offset, 8 );
        addr_size = *(p + 10);
        Wdputslc( "\nAddress Size " );
        Puthex( addr_size, 2 );
        seg_size = *(p + 11);
        Wdputslc( "\nSegment Size " );
        Puthex( seg_size, 2 );
        Wdputslc( "\n" );
        p += 12;
        Wdputslc( "    Address       Length\n" );
        while( p < unit_end ) {
            p = GetInt( p, &addr, addr_size );
            p = GetInt( p, &seg, seg_size );
            p = GetInt( p, &len, addr_size );
            if( addr == 0 && seg == 0 && len == 0 )
                break;
            Wdputs( "    " );
            if( seg_size != 0 ) {
                Puthex( seg, seg_size * 2 );
                Wdputs( ":" );
                Puthex( addr, addr_size * 2 );
            } else {
                Puthex( addr, addr_size * 2 );
                Wdputs( "     " );
            }
            Wdputs( " " );
            Puthex( len, addr_size * 2 );
            Wdputslc( "\n" );
        }
        p = unit_end;
    }
}
Esempio n. 13
0
static void att_read_multi_req_dump(int level, struct frame *frm)
{
	p_indent(level, frm);
	printf("Handles\n");

	while (frm->len > 0) {
		p_indent(level, frm);
		printf("handle 0x%4.4x\n", btohs(htons(get_u16(frm))));
	}
}
Esempio n. 14
0
/* check for xunlei */
int
search_xunlei (const unsigned char *payload, const u16 plen)
{
	if ( memcmp(payload,"POST / HTTP/1.1",15) ==0 )
	{
		unsigned char *t = strstr((payload+93), "Connection: Keep-Alive"); //min length of Connection
		if (t)
		{
			t += 26;
			if ( (*t < 0x40) && (*(t+1) == 0x00) && get_u16(t,2) == __constant_htons(0x0000) && get_u16(t,5) == __constant_htons(0x0000) && (*(t+7) == 0x00) && (*(t+8) == (payload+plen-t-12)) ) return (IPP2P_XUNLEI *100 + 1);
		}
	}
	//QQ cyclone
	if ( plen < 400 )
	{
		if ( get_u16(payload,0) == __constant_htons(0x0200) && ( *(payload+3) == 0x01 || *(payload+3) == 0x00 ) && *(payload+5) == 0x00 && ( *(payload+6) == 0x01 || *(payload+6) == 0x77 ) && get_u16(payload,21) == __constant_htons(0x0038) ) return (IPP2P_XUNLEI *100 + 2);
	}
	return 0;
}
Esempio n. 15
0
int
buffer_get_short_ret(u_short *ret, Buffer *buffer)
{
	u_char buf[2];

	if (buffer_get_ret(buffer, (char *) buf, 2) == -1)
		return (-1);
	*ret = get_u16(buf);
	return (0);
}
Esempio n. 16
0
File: utils.c Progetto: dtaht/tc-adv
int get_be16(__be16 *val, const char *arg, int base)
{
	__u16 v;
	int ret = get_u16(&v, arg, base);

	if (!ret)
		*val = htons(v);

	return ret;
}
Esempio n. 17
0
/*
 * This parses an exported name, extracting the mechanism specific portion
 * to use for ACL checking. It verifies that the name belongs the mechanism
 * originally selected.
 */
static OM_uint32
ssh_gssapi_parse_ename(Gssctxt *ctx, gss_buffer_t ename, gss_buffer_t name)
{
	u_char *tok;
	OM_uint32 offset;
	OM_uint32 oidl;

	tok = ename->value;

	/*
	 * Check that ename is long enough for all of the fixed length
	 * header, and that the initial ID bytes are correct
	 */

	if (ename->length < 6 || memcmp(tok, "\x04\x01", 2) != 0)
		return GSS_S_FAILURE;

	/*
	 * Extract the OID, and check it. Here GSSAPI breaks with tradition
	 * and does use the OID type and length bytes. To confuse things
	 * there are two lengths - the first including these, and the
	 * second without.
	 */

	oidl = get_u16(tok+2); /* length including next two bytes */
	oidl = oidl-2; /* turn it into the _real_ length of the variable OID */

	/*
	 * Check the BER encoding for correct type and length, that the
	 * string is long enough and that the OID matches that in our context
	 */
	if (tok[4] != 0x06 || tok[5] != oidl ||
	    ename->length < oidl+6 ||
	    !ssh_gssapi_check_oid(ctx, tok+6, oidl))
		return GSS_S_FAILURE;

	offset = oidl+6;

	if (ename->length < offset+4)
		return GSS_S_FAILURE;

	name->length = get_u32(tok+offset);
	offset += 4;

	if (UINT_MAX - offset < name->length)
		return GSS_S_FAILURE;
	if (ename->length < offset+name->length)
		return GSS_S_FAILURE;

	name->value = xmalloc(name->length+1);
	memcpy(name->value, tok+offset, name->length);
	((char *)name->value)[name->length] = 0;

	return GSS_S_COMPLETE;
}
Esempio n. 18
0
/*check for KaZaA download commands and other typical data*/
int
search_all_kazaa (const unsigned char *payload, const u16 plen)
{
    if (get_u16(payload,(plen-2)) == __constant_htons(0x0d0a))
    {

	if (memcmp(payload, "GIVE ", 5) == 0) return ((IPP2P_KAZAA * 100) + 1);

    	if (memcmp(payload, "GET /", 5) == 0) {
		u16 c = 8;
		const u16 end=plen-22;
		while (c < end) {
			if ( get_u16(payload,c) == __constant_htons(0x0a0d) && ((memcmp((payload+c+2), "X-Kazaa-Username: "******"User-Agent: PeerEnabler/", 24) == 0)))
				return ((IPP2P_KAZAA * 100) + 2);
			c++;
		}
	}
    }
    return 0;
}
Esempio n. 19
0
static void att_write_req_dump(int level, struct frame *frm)
{
	uint16_t handle = btohs(htons(get_u16(frm)));

	p_indent(level, frm);
	printf("handle 0x%4.4x value ", handle);

	while (frm->len > 0)
		printf(" 0x%2.2x", get_u8(frm));
	printf("\n");
}
Esempio n. 20
0
int get_sauce(FILE *fp, sauce_t *out) 
{
    long cur_pos;

    cur_pos = ftell(fp);  
    if (fseek(fp, -128, SEEK_END) == -1)
        return -1;

    /* 
     * can't count on Sauce structure to be char aligned, 
     * so this bit reads it piecemeal.  Hate to add all these 
     * numbers without #defines, but they're in sauce.h if it 
     * really is confusing.
     */ 
    fread(out->id, 1, 5, fp);
    fread(out->version, 1, 2, fp);
    fread(out->title, 1, 35, fp);
    fread(out->author, 1, 20, fp);
    fread(out->group, 1, 20, fp);
    fread(out->date, 1, 8, fp);

    get_u32(&out->file_size, fp);

    fread(&out->data_type, 1, 1, fp);
    fread(&out->file_type, 1, 1, fp);

    get_u16(&out->t_info1, fp);
    get_u16(&out->t_info2, fp);
    get_u16(&out->t_info3, fp);
    get_u16(&out->t_info4, fp);

    fread(&out->comments, 1, 1, fp);
    fread(&out->flags, 1, 1, fp);

    fseek(fp, cur_pos, SEEK_SET);

    if (strncmp(out->id, "SAUCE", 5) == 0) 
        return 0;

    return -1;
}
Esempio n. 21
0
static void att_read_by_type_req_dump(int level, struct frame *frm)
{
	uint16_t start = btohs(htons(get_u16(frm)));
	uint16_t end = btohs(htons(get_u16(frm)));

	p_indent(level, frm);
	printf("start 0x%4.4x, end 0x%4.4x\n", start, end);

	p_indent(level, frm);
	if (frm->len == 2) {
		printf("type-uuid 0x%4.4x\n", btohs(htons(get_u16(frm))));
	} else if (frm->len == 16) {
		printf("type-uuid ");
		print_uuid128(frm);
		printf("\n");
	} else {
		printf("malformed uuid (expected 2 or 16 octets)\n");
		p_indent(level, frm);
		raw_dump(level, frm);
	}
}
Esempio n. 22
0
static void att_error_dump(int level, struct frame *frm)
{
	uint8_t op = get_u8(frm);
	uint16_t handle = btohs(htons(get_u16(frm)));
	uint8_t err = get_u8(frm);

	p_indent(level, frm);
	printf("Error: %s (%d)\n", atterror2str(err), err);

	p_indent(level, frm);
	printf("%s (0x%.2x) on handle 0x%4.4x\n", attop2str(op), op, handle);
}
Esempio n. 23
0
File: usb_io.c Progetto: nben/puppy
/* Given a Topfield protocol packet, this function will calculate the required
 * CRC and send the packet out over a bulk pipe. */
ssize_t send_tf_packet(int fd, struct tf_packet *packet)
{
    unsigned int pl = get_u16(&packet->length);
    ssize_t byte_count = (pl + 1) & ~1;

    trace(3, fprintf(stderr, "%s\n", __func__));
    put_u16(&packet->crc, get_crc(packet));
    print_packet(packet, "OUT>");
    swap_out_packet(packet);
    return usb_bulk_write(fd, 0x01, (__u8 *) packet, byte_count,
                          TF_PROTOCOL_TIMEOUT);
}
Esempio n. 24
0
/*Search for SoulSeek commands*/
int
search_soul (unsigned char *haystack, int packet_len, int head_len)
{
    unsigned char *t = haystack;
    t += head_len;

    if (get_u16(t, 0) == (packet_len - head_len - 4)){
	    /* xx xx 00 00 yy zz 00 00 .. | xx = sizeof(payload) - 4 */
	if ((get_u16(t,2) == 0x0000) &&(t[4] != 0x00) && (get_u16(t,6) == 0x0000))
	    return ((IPP2P_SOUL * 100) + 1);
    } else {
	    /* 00 00 00 00 00 00 00 00 + sizeof(payload) == 8*/
	if (((packet_len - head_len) == 8) && (get_u32(t, 0) == 0x00000000) && (get_u32(t, 4) == 0x00000000))
	    return ((IPP2P_SOUL * 100) + 2);
    }
    
    /* 01 xx 00 00 00 yy .. zz 00 00 00 .. | xx == sizeof(nick) | yy .. zz == nick */
    if ((t[0] == 0x01) && (t[2] == 0x00) && (get_u16(t,3) == 0x0000) && ((packet_len - head_len) > ((get_u8(t,1))+6)) && 
	(t[(get_u8(t,1))+4] != 0x00) && (t[(get_u8(t,1))+5] == 0x01) && (t[(get_u8(t,1))+6] == 0x00))
	    return ((IPP2P_SOUL * 100) + 3);
    return 0;
}
Esempio n. 25
0
static void smp_cmd_master_ident_dump(int level, struct frame *frm)
{
	uint16_t ediv = btohs(htons(get_u16(frm)));
	int i;

	p_indent(level, frm);
	printf("EDIV 0x%4.4x ", ediv);

	printf("Rand 0x");
	for (i = 0; i < 8; i++)
		printf("%2.2x", get_u8(frm));
	printf("\n");
}
Esempio n. 26
0
static void att_read_by_group_resp_dump(int level, struct frame *frm)
{
	uint8_t length = get_u8(frm);

	while (frm->len > 0) {
		uint16_t attr_handle = btohs(htons(get_u16(frm)));
		uint16_t end_grp_handle = btohs(htons(get_u16(frm)));
		uint8_t remaining = length - 4;

		p_indent(level, frm);
		printf("attr handle 0x%4.4x, end group handle 0x%4.4x\n",
						attr_handle, end_grp_handle);

		p_indent(level, frm);
		printf("value");
		while (remaining > 0) {
			printf(" 0x%2.2x", get_u8(frm));
			remaining--;
		}
		printf("\n");
	}
}
Esempio n. 27
0
void print_packet(struct tf_packet *packet, char *prefix)
{
    int i;
#if 1
    __u8 *d = (__u8 *) packet;
    __u16 pl = get_u16(&packet->length);

    switch (packet_trace)
    {
        case 0:
            /* Do nothing */
            break;

        case 1:
            fprintf(stdout, "%s", prefix);
            for(i = 0; i < 8; ++i)
            {
                fprintf(stdout, " %02x", d[i]);
            }
            fprintf(stdout, "\n");
            break;

        default:
			print_time(); printf("\n");
            fprintf(stdout, "%s", prefix);
            for(i = 0; i < pl; ++i)
            {
                fprintf(stdout, " %02x", d[i]);
				if(23 == (i % 24))
					fprintf(stdout, "\n%s", prefix);
			}
			fprintf(stdout, "\n");

			if (packet_trace>2)
			{
				fprintf(stdout, "%s", prefix);
				for(i = 0; i < pl; ++i)
				{
					if(isalnum(d[i]) || ispunct(d[i]))
						fprintf(stdout, "%c", d[i]);
					else
						fprintf(stdout, ".");
					if(74 == (i % 75))
						fprintf(stdout, "\n%s", prefix);
				}
				fprintf(stdout, "\n");
			}
            break;
    }
#endif
}
Esempio n. 28
0
static int ipoib_parse_opt(struct link_util *lu, int argc, char **argv,
			  struct nlmsghdr *n)
{
	__u16 pkey, mode, umcast;

	while (argc > 0) {
		if (matches(*argv, "pkey") == 0) {
			NEXT_ARG();
			if (get_u16(&pkey, *argv, 0))
				invarg("pkey is invalid", *argv);
			addattr_l(n, 1024, IFLA_IPOIB_PKEY, &pkey, 2);
		} else if (matches(*argv, "mode") == 0) {
			NEXT_ARG();
			if (strcmp(*argv, "datagram") == 0)
				mode = IPOIB_MODE_DATAGRAM;
			else if (strcmp(*argv, "connected") == 0)
				mode = IPOIB_MODE_CONNECTED;
			else
				return mode_arg();
			addattr_l(n, 1024, IFLA_IPOIB_MODE, &mode, 2);
		} else if (matches(*argv, "umcast") == 0) {
			NEXT_ARG();
			if (get_u16(&umcast, *argv, 0))
				invarg("umcast is invalid", *argv);
			addattr_l(n, 1024, IFLA_IPOIB_UMCAST, &umcast, 2);
		} else if (matches(*argv, "help") == 0) {
			explain();
			return -1;
		} else {
			fprintf(stderr, "ipoib: unknown option \"%s\"?\n", *argv);
			explain();
			return -1;
		}
		argc--, argv++;
	}

	return 0;
}
Esempio n. 29
0
static int parse_offset(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
{
	int argc = *argc_p;
	char **argv = *argv_p;

	while (argc > 0) {
		if (matches(*argv, "plus") == 0) {
			int off;
			NEXT_ARG();
			if (get_integer(&off, *argv, 0))
				return -1;
			sel->off = off;
			sel->flags |= TC_U32_OFFSET;
		} else if (matches(*argv, "at") == 0) {
			int off;
			NEXT_ARG();
			if (get_integer(&off, *argv, 0))
				return -1;
			sel->offoff = off;
			if (off%2) {
				fprintf(stderr, "offset \"at\" must be even\n");
				return -1;
			}
			sel->flags |= TC_U32_VAROFFSET;
		} else if (matches(*argv, "mask") == 0) {
			__u16 mask;
			NEXT_ARG();
			if (get_u16(&mask, *argv, 16))
				return -1;
			sel->offmask = htons(mask);
			sel->flags |= TC_U32_VAROFFSET;
		} else if (matches(*argv, "shift") == 0) {
			int shift;
			NEXT_ARG();
			if (get_integer(&shift, *argv, 0))
				return -1;
			sel->offshift = shift;
			sel->flags |= TC_U32_VAROFFSET;
		} else if (matches(*argv, "eat") == 0) {
			sel->flags |= TC_U32_EAT;
		} else {
			break;
		}
		argc--; argv++;
	}

	*argc_p = argc;
	*argv_p = argv;
	return 0;
}
Esempio n. 30
0
int ll_proto_a2n(unsigned short *id, char *buf)
{
        int i;
        for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
                 if (strcasecmp(llproto_names[i].name, buf) == 0) {
			 *id = htons(llproto_names[i].id);
			 return 0;
		 }
	}
	if (get_u16(id, buf, 0))
		return -1;
	*id = htons(*id);
	return 0;
}