Ejemplo n.º 1
0
Packet_Checksum *
Packet_Checksum_create(uint32 frameNr, uint32 checksum) {
	Packet_Checksum *packet =
			(Packet_Checksum *) Packet_create(PACKET_CHECKSUM, 0);
	packet->frameNr = hton32(frameNr);
	packet->checksum = hton32(checksum);
	return packet;
}
Ejemplo n.º 2
0
uint64_t hton64(uint64_t val){
	uint32_t *tmp_in = (uint32_t*)&val;
	uint32_t tmp_out[2] = {
		hton32(tmp_in[1]),
		hton32(tmp_in[0]),
	};
    return *(uint64_t*)tmp_out;
}
Ejemplo n.º 3
0
/* Open new pptp_connection.  Returns NULL on failure. */
PPTP_CONN * pptp_conn_open(int inet_sock, int isclient, pptp_conn_cb callback)
{
    PPTP_CONN *conn;
    /* Allocate structure */
    if ((conn = malloc(sizeof(*conn))) == NULL) return NULL;
    if ((conn->call = vector_create()) == NULL) { free(conn); return NULL; }
    /* Initialize */
    conn->inet_sock = inet_sock;
    conn->conn_state = CONN_IDLE;
    conn->ka_state  = KA_NONE;
    conn->ka_id     = 1;
    conn->call_serial_number = 0;
    conn->callback  = callback;
    /* Create I/O buffers */
    conn->read_size = conn->write_size = 0;
    conn->read_alloc = conn->write_alloc = INITIAL_BUFSIZE;
    conn->read_buffer =
        malloc(sizeof(*(conn->read_buffer)) * conn->read_alloc);
    conn->write_buffer =
        malloc(sizeof(*(conn->write_buffer)) * conn->write_alloc);
    if (conn->read_buffer == NULL || conn->write_buffer == NULL) {
        if (conn->read_buffer  != NULL) free(conn->read_buffer);
        if (conn->write_buffer != NULL) free(conn->write_buffer);
        vector_destroy(conn->call); free(conn); return NULL;
    }
    /* Make this socket non-blocking. */
    fcntl(conn->inet_sock, F_SETFL, O_NONBLOCK);
    /* Request connection from server, if this is a client */
    if (isclient) {
        struct pptp_start_ctrl_conn packet = {
            PPTP_HEADER_CTRL(PPTP_START_CTRL_CONN_RQST),
            hton16(PPTP_VERSION), 0, 0, 
            hton32(PPTP_FRAME_CAP), hton32(PPTP_BEARER_CAP),
            hton16(PPTP_MAX_CHANNELS), hton16(PPTP_FIRMWARE_VERSION), 
            PPTP_HOSTNAME, PPTP_VENDOR
        };
        /* fix this packet, if necessary */
        int idx, rc;
        idx = get_quirk_index();
        if (idx != -1 && pptp_fixups[idx].start_ctrl_conn) {
            if ((rc = pptp_fixups[idx].start_ctrl_conn(&packet)))
                warn("calling the start_ctrl_conn hook failed (%d)", rc);
        }
        if (pptp_send_ctrl_packet(conn, &packet, sizeof(packet)))
            conn->conn_state = CONN_WAIT_CTL_REPLY;
        else
            return NULL; /* could not send initial start request. */
    }
    /* Set up interval/keep-alive timer */
    /*   First, register handler for SIGALRM */
    sigpipe_create();
    sigpipe_assign(SIGALRM);
    global.conn = conn;
    /* Reset event timer */
    pptp_reset_timer();
    /* all done. */
    return conn;
}
Ejemplo n.º 4
0
/* This currently *only* works for client call requests.
 * We need to do something else to allocate calls for incoming requests.
 */
PPTP_CALL * pptp_call_open(PPTP_CONN * conn, pptp_call_cb callback,
        char *phonenr)
{
    PPTP_CALL * call;
    int i;
    int idx, rc;
    /* Send off the call request */
    struct pptp_out_call_rqst packet = {
        PPTP_HEADER_CTRL(PPTP_OUT_CALL_RQST),
        0,0, /*call_id, sernum */
        hton32(PPTP_BPS_MIN), hton32(PPTP_BPS_MAX),
        hton32(PPTP_BEARER_CAP), hton32(PPTP_FRAME_CAP), 
        hton16(PPTP_WINDOW), 0, 0, 0, {0}, {0}
    };
    assert(conn && conn->call);
    assert(conn->conn_state == CONN_ESTABLISHED);
    /* Assign call id */
    if (!vector_scan(conn->call, 0, PPTP_MAX_CHANNELS - 1, &i))
        /* no more calls available! */
        return NULL;
    /* allocate structure. */
    if ((call = malloc(sizeof(*call))) == NULL) return NULL;
    /* Initialize call structure */
    call->call_type = PPTP_CALL_PNS;
    call->state.pns = PNS_IDLE;
    call->call_id   = (u_int16_t) i;
    call->sernum    = conn->call_serial_number++;
    call->callback  = callback;
    call->closure   = NULL;
    packet.call_id = htons(call->call_id);
    packet.call_sernum = htons(call->sernum);
    /* if we have a quirk, build a new packet to fit it */
    idx = get_quirk_index();
    if (idx != -1 && pptp_fixups[idx].out_call_rqst_hook) {
        if ((rc = pptp_fixups[idx].out_call_rqst_hook(&packet)))
            warn("calling the out_call_rqst hook failed (%d)", rc);
    }
    /* fill in the phone number if it was specified */
    if (phonenr) {
        strncpy((char *)packet.phone_num, phonenr, sizeof(packet.phone_num));
        packet.phone_len = strlen(phonenr);
        if( packet.phone_len > sizeof(packet.phone_num))
            packet.phone_len = sizeof(packet.phone_num);
        packet.phone_len = hton16 (packet.phone_len);
    }
    if (pptp_send_ctrl_packet(conn, &packet, sizeof(packet))) {
        pptp_reset_timer();
        call->state.pns = PNS_WAIT_REPLY;
        /* and add it to the call vector */
        vector_insert(conn->call, i, call);
        return call;
    } else { /* oops, unsuccessful. Deallocate. */
        free(call);
        return NULL;
    }
}
Ejemplo n.º 5
0
/*
 * ip_arp_recv_netbuf()
 *	Handle reception of an ARP packet for IP.
 */
void ip_arp_recv_netbuf(void *clnt, struct netbuf *nb)
{
    struct ethernet_client *ec;
    struct ip_datalink_instance *idi;
    struct eth_phys_header *eph;
    struct arp_header *ah;
    struct ip_arp_header *iah;
    struct ethernet_ip_instance *eii;

    ec = (struct ethernet_client *)clnt;
    idi = (struct ip_datalink_instance *)ec->ec_instance;
    eii = (struct ethernet_ip_instance *)idi;

    eph = (struct eth_phys_header *)nb->nb_datalink;
    ah = (struct arp_header *)nb->nb_network;
    iah = (struct ip_arp_header *)(ah + 1);

    if (ah->ah_haddr_len != 6) {
        debug_print_pstr("\farp haddr_len !6");
        return;
    }

    if (ah->ah_paddr_len != 4) {
        debug_print_pstr("\farp paddr_len !4");
        return;
    }

    if (hton32(iah->iah_dest_ip) != idi->idi_client->idc_addr) {
        return;
    }

    /*
     * Update our ARP cache with the sender's details.
     */
    ip_arp_cache_add(idi, eph->eph_src_mac, hton32(iah->iah_src_ip));

    switch (hton16(ah->ah_operation)) {
    case 1:
        /*
         * ARP request.
         */
        ip_arp_recv_request(idi, nb);
        break;

    case 2:
        /*
         * ARP response.
         */
        break;

    default:
        debug_print_pstr("\fip_arp_recv_netbuf: op");
        debug_print16(hton16(ah->ah_operation));
    }
}
Ejemplo n.º 6
0
/*
 * Picks an address given the scope of daddr 
 */
int esix_intf_pick_source_address(const struct ip6_addr *daddr)
{
	int i;
	//try go get an address of the same scope. Note that we assume
	//that a link local address is always avaiable (SLAAC link local)
	if((daddr->addr1 & hton32(0xffff0000)) == hton32(0xfe800000))
		i = esix_intf_get_type_address(LINK_LOCAL);
	else
		i = esix_intf_get_type_address(GLOBAL);

	return i;
}
Ejemplo n.º 7
0
/*
 * ethernet_ip_send_netbuf()
 *	Send a netbuf.
 *
 * Note that we assume that all parameters are supplied in network byte order.
 */
void ethernet_ip_send_netbuf(void *srv, struct netbuf *nb)
{
    struct ip_datalink_server *ids;
    struct ip_datalink_instance *idi;
    struct ethernet_ip_instance *eii;
    struct ethernet_server *es;
    struct ip_header *iph;
    struct ip_route *rt;
    u32_t addr;
    u8_t mac[6];

    ids = (struct ip_datalink_server *)srv;
    idi = (struct ip_datalink_instance *)ids->ids_instance;
    eii = (struct ethernet_ip_instance *)idi;
    iph = (struct ip_header *)nb->nb_network;

    rt = ip_route_find(idi, hton32(iph->ih_dest_addr));
    if (!rt) {
        debug_print_pstr("\fethernet_ip_send_netbuf: no rt:");
        debug_print32(hton32(iph->ih_dest_addr));
        return;
    }

    if (rt->ir_gateway) {
        addr = rt->ir_gateway;
    } else {
        addr = hton32(iph->ih_dest_addr);
    }

    if (ip_arp_cache_find(idi, mac, addr)) {
        spinlock_lock(&idi->idi_lock);
        es = eii->eii_ip_server;
        ethernet_server_ref(es);
        spinlock_unlock(&idi->idi_lock);

        es->es_send(es, mac, nb);

        ethernet_server_deref(es);
    } else {
        /*
         * If we don't know where this packet should go to then
         * it's time to find out.  For now we simply discard the
         * packet we were supposed to be sending.  Sometime in
         * the future, perhaps this should be changed for queueing
         * the request until the address is known.
         */
        ip_arp_request(idi, addr);
        debug_print_pstr("\fMAC not found:");
        debug_print32(addr);
        debug_print_pstr("rt:");
        debug_print32(rt->ir_addr.ir_network.irn_addr);
    }
}
Ejemplo n.º 8
0
void esix_intf_add_default_routes(u8_t intf_index, int intf_mtu)
{
	//link local route (fe80::/64)
	struct esix_route_table_row *ll_rt	= esix_w_malloc(sizeof(struct esix_route_table_row));
	if(ll_rt == NULL)
		return;
	
	ll_rt->addr.addr1	= hton32(0xfe800000);
	ll_rt->addr.addr2	= 0x0;
	ll_rt->addr.addr3	= 0x0;
	ll_rt->addr.addr4	= 0x0;
	ll_rt->mask.addr1	= 0xffffffff;
	ll_rt->mask.addr2	= 0xffffffff;
	ll_rt->mask.addr3	= 0x0;
	ll_rt->mask.addr4	= 0x0;
	ll_rt->next_hop.addr1	= 0x0; //a value of 0 means no next hop 
	ll_rt->next_hop.addr2	= 0x0; 
	ll_rt->next_hop.addr3	= 0x0; 
	ll_rt->next_hop.addr4	= 0x0; 
	ll_rt->ttl		= DEFAULT_TTL; 
	ll_rt->mtu		= intf_mtu;
	ll_rt->expiration_date	= 0x0; //this never expires
	ll_rt->interface	= intf_index;

	//multicast route (ff00:: /8)
	struct esix_route_table_row *mcast_rt	= esix_w_malloc(sizeof(struct esix_route_table_row));
	if(mcast_rt == NULL)
	{
		esix_w_free(ll_rt);
		return;
	}
	
	mcast_rt->addr.addr1		= hton32(0xff000000);
	mcast_rt->addr.addr2		= 0x0;
	mcast_rt->addr.addr3		= 0x0;
	mcast_rt->addr.addr4		= 0x0;
	mcast_rt->mask.addr1		= hton32(0xff000000); // /8
	mcast_rt->mask.addr2		= 0x0;
	mcast_rt->mask.addr3		= 0x0;
	mcast_rt->mask.addr4		= 0x0;
	mcast_rt->next_hop.addr1	= 0x0; //a value of 0 means no next hop 
	mcast_rt->next_hop.addr2	= 0x0; 
	mcast_rt->next_hop.addr3	= 0x0; 
	mcast_rt->next_hop.addr4	= 0x0; 
	mcast_rt->expiration_date	= 0x0; //this never expires
	mcast_rt->ttl			= DEFAULT_TTL;  // 1 should be ok, linux uses 255...
	mcast_rt->mtu			= intf_mtu;
	mcast_rt->interface		= intf_index;

	esix_intf_add_route_row(ll_rt);
	esix_intf_add_route_row(mcast_rt);
}
Ejemplo n.º 9
0
/*
 * ip_arp_recv_request()
 */
static void ip_arp_recv_request(struct ip_datalink_instance *idi, struct netbuf *nb)
{
    u8_t *send_packet;
    struct eth_phys_header *reph;
    struct arp_header *rah, *sah;
    struct ip_arp_header *rp, *sp;
    struct netbuf *nbrep;
    struct ethernet_ip_instance *eii;
    struct ethernet_server *es;

    eii = (struct ethernet_ip_instance *)idi;

    reph = (struct eth_phys_header *)nb->nb_datalink;
    rah = (struct arp_header *)nb->nb_network;
    rp = (struct ip_arp_header *)(rah + 1);

    /*
     * Issue an ARP reply.
     */
    send_packet = membuf_alloc(sizeof(struct arp_header) + sizeof(struct ip_arp_header), NULL);

    sah = (struct arp_header *)send_packet;
    sp = (struct ip_arp_header *)(sah + 1);

    memcpy(sp->iah_dest_mac, rp->iah_src_mac, 6);

    spinlock_lock(&idi->idi_lock);
    es = eii->eii_arp_server;
    ethernet_server_ref(es);
    spinlock_unlock(&idi->idi_lock);

    memcpy(sp->iah_src_mac, es->es_get_mac(es), 6);

    sah->ah_hardware = rah->ah_hardware;
    sah->ah_protocol = rah->ah_protocol;
    sah->ah_haddr_len = rah->ah_haddr_len;
    sah->ah_paddr_len = rah->ah_paddr_len;
    sah->ah_operation = hton16(2);

    sp->iah_src_ip = hton32(idi->idi_client->idc_addr);
    sp->iah_dest_ip = hton32(rp->iah_src_ip);

    nbrep = netbuf_alloc();
    nbrep->nb_network_membuf = sah;
    nbrep->nb_network = sah;
    nbrep->nb_network_size = sizeof(struct arp_header) + sizeof(struct ip_arp_header);

    es->es_send(es, sp->iah_dest_mac, nbrep);

    netbuf_deref(nbrep);
    ethernet_server_deref(es);
}
Ejemplo n.º 10
0
/**
 * Adds a link local address/route based on the MAC address
 * and joins the all-nodes mcast group
 */
void esix_intf_init_interface(esix_ll_addr lla, u8_t  interface)
{
	struct ip6_addr addr;

	//builds our link local and associated multicast addresses
	//from the MAC address given by the L2 layer.
	
	//unicast link local
	addr.addr1 = 	hton32(0xfe800000); //0xfe80 
	addr.addr2 = 	hton32(0x00000000);
	addr.addr3 = 	hton32(	(ntoh16(lla[0]) << 16 & 0xff0000)
				| (ntoh16(lla[1]) & 0xff00)
				| 0x020000ff ); //stateless autoconf, 0x02 : universal bit

	addr.addr4 = 	hton32(	(0xfe000000) //0xfe here is OK
				| (ntoh16(lla[1])<< 16 & 0xff0000)
				| (ntoh16(lla[2])) );

	esix_intf_add_address(&addr,
			0x80,			// /128
			0x0,			//this one never expires
			LINK_LOCAL);

	//first row of the neighbors table is us
        addr.addr1 =    hton32(0xfe800000); //0xfe80
        addr.addr2 =    hton32(0x00000000);
        addr.addr3 =    hton32( (ntoh16(lla[0]) << 16 & 0xff0000)
                                | (ntoh16(lla[1]) & 0xff00)
                                | 0x020000ff ); //stateless autoconf, 0x02 : universal bit

        addr.addr4 =    hton32( (0xfe000000) //0xfe here is OK
                                | (ntoh16(lla[1])<< 16 & 0xff0000)
                                | (ntoh16(lla[2])) );

	esix_intf_add_neighbor(&addr,
		lla, // MAC address
		0, // never expires
		INTERFACE);

	//multicast all-nodes (for router advertisements)
	addr.addr1 = 	hton32(0xff020000); 	//ff02::1 
	addr.addr2 = 	0;
	addr.addr3 = 	0;
	addr.addr4 = 	hton32(1);
	esix_intf_add_address(&addr,
			0x80, 			// /128
			0x0,			//this one never expires
			MULTICAST);

}
Ejemplo n.º 11
0
yrmcds_error
yrmcds_cnt_acquire(yrmcds_cnt* c, const char* name, size_t name_len,
                   uint32_t resources, uint32_t initial, uint32_t* serial) {
    if( name == NULL || name_len == 0 || name_len > UINT16_MAX ||
        resources == 0 || resources > initial )
        return YRMCDS_BAD_ARGUMENT;

    char body[10];
    hton32(resources, body);
    hton32(initial, body + 4);
    hton16((uint16_t)name_len, body + 8);
    return send_command(c, YRMCDS_CNT_CMD_ACQUIRE, serial,
                        sizeof(body), body, name_len, name);
}
Ejemplo n.º 12
0
int32_t osc_message_s_renameCopy(char *dest, t_osc_msg_s *src, int32_t new_address_len, char *new_address)
{
	if(!dest){
		return 0;
	}
	if(osc_error_validateAddress(new_address)){
		return 0;
	}
	int32_t oldlen = osc_message_s_getSize(src);
	//int32_t old_address_len = strlen(osc_message_s_getAddress(src));
	//int32_t newlen = oldlen - (old_address_len - new_address_len);
	//while(newlen % 4){
	//newlen++;
	//}
	int32_t newlen = oldlen - osc_util_getPaddedStringLen(osc_message_s_getAddress(src)) + osc_util_getPaddingForNBytes(new_address_len);
	*((int32_t *)dest) = hton32(newlen);
	char *ptr = dest + 4;
	if(new_address_len > 0){
		memcpy(ptr, new_address, new_address_len);
	}
	ptr += new_address_len;
	*ptr++ = '\0';
	while((ptr - dest) % 4){
		*ptr++ = '\0';
	}
	memcpy(ptr, src->typetags, oldlen - (src->typetags - src->address));
	return newlen;
}
Ejemplo n.º 13
0
Packet_Ping *
Packet_Ping_create(uint32 id) {
	Packet_Ping *packet = (Packet_Ping *) Packet_create(PACKET_PING, 0);

	packet->id = hton32(id);
	return packet;
}
Ejemplo n.º 14
0
Packet_FrameCount *
Packet_FrameCount_create(uint32 frameCount) {
	Packet_FrameCount *packet =
			(Packet_FrameCount *) Packet_create(PACKET_FRAMECOUNT, 0);
	packet->frameCount = hton32(frameCount);
	return packet;
}
Ejemplo n.º 15
0
Packet_Ack *
Packet_Ack_create(uint32 id) {
	Packet_Ack *packet = (Packet_Ack *) Packet_create(PACKET_ACK, 0);

	packet->id = hton32(id);
	return packet;
}
Ejemplo n.º 16
0
int gtpie_tv4(void *p, unsigned int *length, unsigned int size, uint8_t t, uint32_t v) {
  if ((*length + 5) >= size) return 1;
  ((union gtpie_member*) (p + *length))->tv4.t = hton8(t);
  ((union gtpie_member*) (p + *length))->tv4.v = hton32(v);
  *length += 5;
  return 0;
}
Ejemplo n.º 17
0
static void send_request (BArpProbe *o)
{
    if (o->send_sending) {
        BLog(BLOG_ERROR, "cannot send packet while another packet is being sent!");
        return;
    }
    
    // build packet
    struct arp_packet *arp = &o->send_packet;
    arp->hardware_type = hton16(ARP_HARDWARE_TYPE_ETHERNET);
    arp->protocol_type = hton16(ETHERTYPE_IPV4);
    arp->hardware_size = hton8(6);
    arp->protocol_size = hton8(4);
    arp->opcode = hton16(ARP_OPCODE_REQUEST);
    memcpy(arp->sender_mac, o->if_mac, 6);
    arp->sender_ip = hton32(0);
    memset(arp->target_mac, 0, sizeof(arp->target_mac));
    arp->target_ip = o->addr;
    
    // send packet
    PacketPassInterface_Sender_Send(o->send_if, (uint8_t *)&o->send_packet, sizeof(o->send_packet));
    
    // set sending
    o->send_sending = 1;
}
Ejemplo n.º 18
0
void
send_ima( tNode* pNode, BOOL fSendNow ) {
    IAnnexET00IAmAlive  ima[sizeof_IAnnexET00IAmAlive_ND];
    BYTE                cookie[4];

    ima[IAnnexET00IAmAlive_Header+IAnnexET00Header_PFLAGS]  = 0;
    AEPOr_T( ima[IAnnexET00IAmAlive_Header+IAnnexET00Header_PFLAGS], AEPT_TransportMessage );
    /*
    ima.Header.S    = 0;
    ima.Header.A    = 0;
    ima.Header.RES  = 0;
    */
    ima[IAnnexET00IAmAlive_Header+IAnnexET00Header_TRANSPORT_TYPE] = AEPT00_IAmAlive;

    IMASet_P( ima );

    hton16( (UINT16)get_ima_interval( pNode ), &ima[IAnnexET00IAmAlive_VALIDITY] );

    IMASet_CookieLen( ima, sizeof( UINT32 ) );

    hton32( timerGetTimeInMilliseconds(), &cookie[0] );

    send_payload(
            pNode,
            ima,
            sizeof_IAmAliveHeader( &ima ),
            &cookie[0],
            4,
            NULL,
            0,
            FALSE,
            FALSE,
            fSendNow
        );
}
Ejemplo n.º 19
0
Archivo: osc_mem.c Proyecto: CNMAT/libo
t_osc_err osc_mem_encodeByteorder(unsigned char typetag, char *data, char **out)
{
	size_t size = osc_sizeof(typetag, data);
	if(!osc_mem_shouldByteswap(typetag)){
		memcpy(*out, data, size);
		return OSC_ERR_NONE;
	}
	char tmp[size];
	switch(size){
	case 1:
		break;
	case 2:
		*((uint16_t *)tmp) = hton16(*((uint16_t *)data));
		break;
	case 4:
		*((uint32_t *)tmp) = hton32(*((uint32_t *)data));
		break;
	case 8:
		*((uint64_t *)tmp) = hton64(*((uint64_t *)data));
		break;	
	case 16:
		*((uint128_t *)tmp) = hton128(*((uint128_t *)data));
		break;
	}
	memcpy(*out, tmp, size);
	return OSC_ERR_NONE;
}
Ejemplo n.º 20
0
/* routing stuff is still missing */
void tcp_respond(struct tcpiphdr *ti, IO_Rec *recs, int nr_recs,
		 iphost_st *host_st, intf_st *ifs, tcp_seq ack,
		 tcp_seq seq, int flags)
{
    register int tlen=0;

    TRC(printf("tcp respond \n"));
#define xchg(a,b,type) { type t; t=a; a=b; b=t; }
    xchg(ti->ti_dst.s_addr, ti->ti_src.s_addr, uint32_t);
    xchg(ti->ti_dport, ti->ti_sport, uint16_t);
#undef xchg

    ti->ti_len = htons((uint16_t)(sizeof (struct tcphdr) + tlen));
    tlen += sizeof (struct tcpiphdr);
    ti->ti_next = ti->ti_prev = 0;
    ti->ti_x1 = 0;
    TRC(printf("ack before setting back %d\n", ack));
    ti->ti_seq = hton32(seq);
    ti->ti_ack = hton32(ack);
    ti->ti_x2 = 0;
    ti->ti_off = sizeof (struct tcphdr) >> 2;
    ti->ti_flags = flags;
    ti->ti_win = hton16(ti->ti_win);
    ti->ti_urp = 0;
    ti->ti_sum = 0;
    TRC(printf("calling cksum with len %d\n", tlen));

    /* checksum computes over tcp and ip (overlay) header */
    if (recs[1].len == 0) {
	ti->ti_sum = in_cksum((uint16_t *)ti, tlen);
    } else {
	printf("tcp_respond: checksum more recs, "
	       "nr recs %d rec 0 len %d rec 1 len%d\n",
	       nr_recs, recs[0].len, recs[1].len);
	ti->ti_sum = cksum_morerecs((uint16_t *)ti,
				    recs[0].len - sizeof(struct ether_header),
				    recs, nr_recs);
    }
    TRC(printf("calling cksum done\n"));

    ((struct ip *)ti)->ip_len = tlen;
    ((struct ip *)ti)->ip_ttl = MAXTTL;

    TRC(printf("tcp respond calling ip_output\n"));

    ip_output(recs, nr_recs, host_st, ifs, 0, flags);
}
Ejemplo n.º 21
0
Packet_SeedRandom *
Packet_SeedRandom_create(uint32 seed) {
	Packet_SeedRandom *packet =
			(Packet_SeedRandom *) Packet_create(PACKET_SEEDRANDOM, 0);

	packet->seed = hton32(seed);
	return packet;
}
Ejemplo n.º 22
0
Packet_InputDelay *
Packet_InputDelay_create(uint32 delay) {
	Packet_InputDelay *packet =
			(Packet_InputDelay *) Packet_create(PACKET_INPUTDELAY, 0);

	packet->delay = hton32(delay);
	return packet;
}
Ejemplo n.º 23
0
/*
 * esix_intf_check_source_addr : make sure that the source address isn't multicast
 * if it is, choose an address from the corresponding scope
 */
int esix_intf_check_source_addr(struct ip6_addr *saddr, const struct ip6_addr *daddr)
{
	int i = -1;

	if(	(saddr->addr1 & hton32(0xff000000)) == hton32(0xff000000))
	{
		//try to chose an address of the correct scope to replace it.
		if((daddr->addr1 & hton32(0xffff0000)) == hton32(0xfe800000))
			i = esix_intf_get_type_address(LINK_LOCAL);
		
		if( (i < 0 ) && (i = esix_intf_get_type_address(GLOBAL)) < 0)
			return -1;
							
		*saddr	= addrs[i]->addr; 
	}
	return 1;
}
Ejemplo n.º 24
0
/*
 * ip_arp_request()
 *	Issue an ARP request for a given IP address.
 */
u8_t ip_arp_request(struct ip_datalink_instance *idi, u32_t ip)
{
    u8_t *pkt;
    struct netbuf *nb;
    struct arp_header *ah;
    struct ip_arp_header *iah;
    static u8_t broadcast_mac[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
    struct ethernet_ip_instance *eii;
    struct ethernet_server *es;

    eii = (struct ethernet_ip_instance *)idi;

    pkt = membuf_alloc(sizeof(struct arp_header) + sizeof(struct ip_arp_header), NULL);

    ah = (struct arp_header *)pkt;
    ah->ah_hardware = hton16(1);
    ah->ah_protocol = hton16(0x0800);
    ah->ah_haddr_len = 6;
    ah->ah_paddr_len = 4;
    ah->ah_operation = hton16(1);

    iah = (struct ip_arp_header *)(ah + 1);
    iah->iah_src_ip = hton32(idi->idi_client->idc_addr);
    iah->iah_dest_ip = hton32(ip);

    spinlock_lock(&idi->idi_lock);
    es = eii->eii_arp_server;
    ethernet_server_ref(es);
    spinlock_unlock(&idi->idi_lock);

    memcpy(iah->iah_src_mac, es->es_get_mac(es), 6);
    memcpy(iah->iah_dest_mac, broadcast_mac, 6);

    nb = netbuf_alloc();
    nb->nb_network_membuf = ah;
    nb->nb_network = ah;
    nb->nb_network_size = sizeof(struct arp_header) + sizeof(struct ip_arp_header);

    es->es_send(es, broadcast_mac, nb);

    netbuf_deref(nb);
    ethernet_server_deref(es);

    return 0;
}
Ejemplo n.º 25
0
Archivo: send.c Proyecto: Handy2015/h2o
yrmcds_error yrmcds_touch(yrmcds* c, const char* key, size_t key_len,
                          uint32_t expire, int quiet, uint32_t* serial) {
    if( c == NULL || key == NULL || key_len == 0 )
        return YRMCDS_BAD_ARGUMENT;

    char extras[4];
    hton32(expire, extras);
    return send_command(c, YRMCDS_CMD_TOUCH, 0, serial, key_len, key,
                        sizeof(extras), extras, 0, NULL);
}
Ejemplo n.º 26
0
Archivo: send.c Proyecto: Handy2015/h2o
static yrmcds_error send_data(
    yrmcds* c, yrmcds_command cmd, const char* key, size_t key_len,
    const char* data, size_t data_len, uint32_t flags, uint32_t expire,
    uint64_t cas, uint32_t* serial) {
    if( c == NULL || key == NULL || key_len == 0 ||
        data == NULL || data_len == 0 )
        return YRMCDS_BAD_ARGUMENT;

    int compressed = 0;
#ifdef LIBYRMCDS_USE_LZ4
    if( (c->compress_size > 0) && (data_len > c->compress_size) ) {
        if( flags & YRMCDS_FLAG_COMPRESS )
            return YRMCDS_BAD_ARGUMENT;

        size_t bound = (size_t)LZ4_compressBound((int)data_len);
        char* new_data = (char*)malloc(bound + sizeof(uint32_t));
        if( new_data == NULL )
            return YRMCDS_OUT_OF_MEMORY;
        uint32_t new_size =
            (uint32_t)LZ4_compress(data, new_data + sizeof(uint32_t),
                                   (int)data_len);
        if( new_size == 0 ) {
            free(new_data);
            return YRMCDS_COMPRESS_FAILED;
        }
        hton32((uint32_t)data_len, new_data);
        flags |= YRMCDS_FLAG_COMPRESS;
        data_len = sizeof(uint32_t) + new_size;
        data = new_data;
        compressed = 1;
    }
#endif // LIBYRMCDS_USE_LZ4

    char extras[8];
    hton32(flags, extras);
    hton32(expire, &extras[4]);
    yrmcds_error e = send_command(c, cmd, cas, serial, key_len, key,
                                  sizeof(extras), extras, data_len, data);
    if( compressed )
        free((void*)data);
    return e;
}
Ejemplo n.º 27
0
yrmcds_error
yrmcds_cnt_release(yrmcds_cnt* c, const char* name, size_t name_len,
                   uint32_t resources, uint32_t* serial) {
    if( name == NULL || name_len == 0 || name_len > UINT16_MAX )
        return YRMCDS_BAD_ARGUMENT;

    char body[6];
    hton32(resources, body);
    hton16((uint16_t)name_len, body + 4);
    return send_command(c, YRMCDS_CNT_CMD_RELEASE, serial,
                        sizeof(body), body, name_len, name);
}
Ejemplo n.º 28
0
Archivo: send.c Proyecto: Handy2015/h2o
yrmcds_error yrmcds_decr(yrmcds* c, const char* key, size_t key_len,
                         uint64_t value, int quiet, uint32_t* serial) {
    if( c == NULL || key == NULL || key_len == 0 )
        return YRMCDS_BAD_ARGUMENT;

    char extras[20];
    hton64(value, extras);
    hton64((uint64_t)0, &extras[8]);
    hton32(~(uint32_t)0, &extras[16]);
    return send_command(c, quiet ? YRMCDS_CMD_DECREMENTQ : YRMCDS_CMD_DECREMENT,
                        0, serial, key_len, key,
                        sizeof(extras), extras, 0, NULL);
}
Ejemplo n.º 29
0
void ovalidate_anything(t_ovalidate *x, t_symbol *msg, int argc, t_atom *argv)
{
	if(msg == gensym("xosc-msgsize-bug")){
		// DON'T DO SHIT LIKE THIS---THIS ISN'T THE WILD F*****G WEST
		long len = atom_getlong(argv + 1);
		char *ptr = (char *)atom_getlong(argv + 2);
		char *size = ptr + OSC_HEADER_SIZE;
		*((int32_t *)size) = hton32(100);
		ovalidate_fullPacket(x, atom_getsym(argv), argc - 1, argv + 1);
	}else{
		object_error((t_object *)x, "doesn't understand message %s", msg->s_name);
	}
}
Ejemplo n.º 30
0
/* return 0 on success, non zero otherwise */
int
orckit_atur3_build_hook(struct pptp_out_call_rqst* packet)
{
    unsigned int name_length = 10;

    struct pptp_out_call_rqst fixed_packet = {
	PPTP_HEADER_CTRL(PPTP_OUT_CALL_RQST),
	0, /* hton16(call->callid) */
	0, /* hton16(call->sernum) */
	hton32(PPTP_BPS_MIN), hton32(PPTP_BPS_MAX),
	hton32(PPTP_BEARER_DIGITAL), hton32(PPTP_FRAME_ANY),
	hton16(PPTP_WINDOW), 0, hton16(name_length), 0,
	{'R','E','L','A','Y','_','P','P','P','1',0}, {0}
    };

    if (!packet)
	return -1;

    memcpy(packet, &fixed_packet, sizeof(*packet));

    return 0;
}