Example #1
0
/* ECMA-262 3rd Edition    15.4.4.5 */
static HRESULT Array_join(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv,
        jsval_t *r)
{
    jsdisp_t *jsthis;
    DWORD length;
    HRESULT hres;

    TRACE("\n");

    hres = get_length(ctx, vthis, &jsthis, &length);
    if(FAILED(hres))
        return hres;

    if(argc) {
        const WCHAR *sep;
        jsstr_t *sep_str;

        hres = to_flat_string(ctx, argv[0], &sep_str, &sep);
        if(FAILED(hres))
            return hres;

        hres = array_join(ctx, jsthis, length, sep, r);

        jsstr_release(sep_str);
    }else {
        hres = array_join(ctx, jsthis, length, default_separatorW, r);
    }

    return hres;
}
Example #2
0
/* ECMA-262 3rd Edition    15.4.4.5 */
static HRESULT Array_join(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPARAMS *dp,
        VARIANT *retv, jsexcept_t *ei)
{
    jsdisp_t *jsthis;
    DWORD length;
    HRESULT hres;

    TRACE("\n");

    hres = get_length(ctx, vthis, ei, &jsthis, &length);
    if(FAILED(hres))
        return hres;

    if(arg_cnt(dp)) {
        BSTR sep;

        hres = to_string(ctx, get_arg(dp,0), ei, &sep);
        if(FAILED(hres))
            return hres;

        hres = array_join(ctx, jsthis, length, sep, retv, ei);

        SysFreeString(sep);
    }else {
        hres = array_join(ctx, jsthis, length, default_separatorW, retv, ei);
    }

    return hres;
}
Example #3
0
static HRESULT Array_get_value(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
{
    ArrayInstance *array = array_from_jsdisp(jsthis);

    TRACE("\n");

    return array_join(ctx, &array->dispex, array->length, default_separatorW, r);
}
Example #4
0
/*
 * ncurses_binding_set()
 *
 * it sets some sequence to the given key
 */
void ncurses_binding_set(int quiet, const char *key, const char *sequence)
{
    struct binding *d;
    binding_added_t *b;
    struct binding *binding_orginal = NULL;
    char *joined = NULL;
    int count = 0;

    for (d = bindings; d; d = d->next) {
        if (!xstrcasecmp(key, d->key)) {
            binding_orginal = d;
            break;
        }
    }

    if (!binding_orginal) {
        printq("bind_doesnt_exist", key);
        return;
    }

    if (!sequence) {
        char **chars = NULL;
        char ch;
        printq("bind_press_key");
        nodelay(input, FALSE);
        while ((ch = wgetch(input)) != ERR) {
            array_add(&chars, xstrdup(itoa(ch)));
            nodelay(input, TRUE);
            count++;
        }
        joined = array_join(chars, (" "));
        array_free(chars);
    } else
        joined = xstrdup(sequence);

    for (b = bindings_added; b; b = b->next) {
        if (!xstrcasecmp(b->sequence, joined)) {
            b->binding = binding_orginal;
            xfree(joined);
            goto end;
        }
    }

    b = xmalloc(sizeof(binding_added_t));
    b->sequence = joined;
    b->binding = binding_orginal;
    LIST_ADD2(&bindings_added, b);
end:
    if (!in_autoexec)
        config_changed = 1;
    printq("bind_added");
    if (count > bindings_added_max)
        bindings_added_max = count;
}
Example #5
0
/* ECMA-262 3rd Edition    15.4.4.2 */
static HRESULT Array_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
        VARIANT *retv, jsexcept_t *ei)
{
    ArrayInstance *array;

    TRACE("\n");

    array = array_this(jsthis);
    if(!array)
        return throw_type_error(ctx, ei, JS_E_ARRAY_EXPECTED, NULL);

    return array_join(ctx, &array->dispex, array->length, default_separatorW, retv, ei);
}
Example #6
0
/* ECMA-262 3rd Edition    15.4.4.2 */
static HRESULT Array_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
        jsval_t *r)
{
    ArrayInstance *array;

    TRACE("\n");

    array = array_this(jsthis);
    if(!array)
        return throw_type_error(ctx, JS_E_ARRAY_EXPECTED, NULL);

    return array_join(ctx, &array->dispex, array->length, default_separatorW, r);
}
Example #7
0
static HRESULT Array_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
        VARIANT *retv, jsexcept_t *ei)
{
    TRACE("\n");

    switch(flags) {
    case INVOKE_FUNC:
        return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
    case INVOKE_PROPERTYGET:
        return array_join(ctx, jsthis->u.jsdisp, array_from_vdisp(jsthis)->length, default_separatorW, retv, ei);
    default:
        FIXME("unimplemented flags %x\n", flags);
        return E_NOTIMPL;
    }

    return S_OK;
}
Example #8
0
static HRESULT Array_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
        jsval_t *r)
{
    TRACE("\n");

    switch(flags) {
    case INVOKE_FUNC:
        return throw_type_error(ctx, JS_E_FUNCTION_EXPECTED, NULL);
    case INVOKE_PROPERTYGET:
        return array_join(ctx, jsthis->u.jsdisp, array_from_vdisp(jsthis)->length, default_separatorW, r);
    default:
        FIXME("unimplemented flags %x\n", flags);
        return E_NOTIMPL;
    }

    return S_OK;
}
Example #9
0
int make_and_send(struct sr_instance* sr, char * interface, uint32_t dstIP, uint8_t* payld, unsigned int len, uint8_t proto) {
    assert(payld);
    assert(sr);
    assert(interface);
#if 0
    printf("********* at %s    Payload is 0x ", __func__);
    int i ;
    for(i = 0; i < len; i++) {
        printf("%hhx ", payld[i]);
    }
    printf("\n");
#endif

    /* doing some testing

     */


    printf("\n*************************\n\n");

    print_ip(dstIP);

    printf("\n\n**************************\n\n");
    char* test;
    test = longest_prefix(sr, ntohl(dstIP));

    printf("\n\n**************************\n");

    struct sr_vns_if* myIntf = sr_get_interface(sr, interface);

    struct ip* ipHdr = (struct ip*) malloc_or_die(20);

    int rtn;

    struct in_addr src;
    struct in_addr dst;
    src.s_addr = myIntf->ip;
    dst.s_addr = dstIP;

    //fill in ip hdr

    //How do we set version and hl?
    ipHdr->ip_hl = 5;
    ipHdr->ip_v = 4;

    ipHdr->ip_tos = 0x0;
    ipHdr->ip_len = htons(len + 20);
    ipHdr->ip_id = htons(1638);
    ipHdr->ip_off = 0x0;
    ipHdr->ip_ttl = 64;
    ipHdr->ip_p = proto;   // probably always IPPROTO_ICMP for the router
    ipHdr->ip_sum = 0x0;
    ipHdr->ip_src = src;
    ipHdr->ip_dst = dst;

    uint16_t check = cksum((uint8_t*)ipHdr, 20);
    ipHdr->ip_sum = check;

    //Then we make an ethernet payload

    //   Tracking back from sr_arp.c:298
    //  we don't have the valid ICMP here even so go back further

    uint8_t* packet = (uint8_t*) malloc_or_die(len + 20);
    packet = array_join(ipHdr, payld, 20, len);

#if 0
    printf("\n");

    for(i = 0; i < len + 20; i++) {
        printf("%hhx ", packet[i]);
    }
    //printf("\n*************      %s     ******************\n", __func__);

#endif
    rtn = arp_lookup(sr, interface, packet, dstIP, (len + 20));

    return rtn;

}
Example #10
0
int create_ICMP_pkt(struct sr_instance* sr, char* interface, uint32_t dstIP, uint8_t type, uint8_t code, uint16_t field1, uint16_t field2, uint8_t* data, unsigned int datalen) {

    assert(data);
    assert(sr);
    assert(interface);
#if 0
    printf("********* at %s    Payload is 0x ", __func__);
    int i;
    for(i = 0; i < datalen; i++) {
        printf("%x", data[i]);
    }
    printf("\n");
#endif
    int len, rtn;
    switch (type) {

    case 3:
    case 11:
        len = 8 + sizeof(struct ip) + 8; //8byte ICMP hdr, 20byte IP hdr, 8byte IP data
        break; //for now to keep it easy to follow code
    case 0:
        len = sizeof(struct sr_icmp_hdr) + datalen; // 8byte ICMP hdr, data as in echo rqst allowing for ID and sequence in data
        break;
    default:
        len = 8; //this might not be helpful...

    }
    //printf("********   We're assigning %d bytes of memory\n", len);
    struct sr_icmp_hdr* packet = (struct sr_icmp_hdr*) malloc_or_die(sizeof(struct sr_icmp_hdr));

    // now they all get some std entries

    packet->type = type;
    packet->code = code;
    packet->checksum = 0x0; // needs to be 0'ed before calculation
    packet->field1 = field1;
    packet->field2 = field2;

    //and now we fill the other entries as appropriate

    // printf("********* at %s    After conversion to packet \n ", __func__);
    // print_icmp_pkt(packet);

    //finally we can add a checksum
    //uint16_t check = cksum((uint8_t*)packet, len);   // The problem is I can't do this cast apparently

    //printf("\n\n********* at %s    transferring  0x \n", __func__);
    //print_icmp_pkt(packet);

    uint8_t* Pkt = array_join(packet, data, sizeof(struct sr_icmp_hdr), datalen);

    //memcpy(Pkt, packet, len);
    uint16_t check = cksum(Pkt, len);
    // printf("\n\n &&&&&&&&&&   the checksum is calculated as %hu\n", check);

    ((struct sr_icmp_hdr*)Pkt)->checksum = check;

    // Pkt = icmp_to_raw(packet, len);

    //so we still have the issue of how to insert the checksum


    rtn = make_and_send(sr, interface, dstIP, Pkt, len, IPPROTO_ICMP);

    if(rtn == 2) {
        printf("*************    ICMP pkt, ARP request sent\n");
        return 2;
    }
    else if (rtn == 1) {
        printf("**************    ICMP packet, we had an ARP entry\n");
        return 2;
    }
    else {
        return 0;
    }
    return 0;
}