Esempio n. 1
0
void netsendpacket(int ind, char *buf, int len)
{
	char bbuf[ sizeof(packbuf) + sizeof(PACKET_PROXY) ];
	PACKET_PROXYp prx = (PACKET_PROXYp)bbuf;
	int i;

	// send via master if in M/S mode and we are not the master, and the recipient is not the master and not ourselves
	if (!NetBroadcastMode && myconnectindex != connecthead && ind != myconnectindex && ind != connecthead) {
		if ((unsigned)len > sizeof(packbuf)) {
			initprintf("netsendpacket(): packet length > %d!\n",sizeof(packbuf));
			len = sizeof(packbuf);
		}

		initprintf("netsendpacket() sends proxy to %d\nPlayerIndex=%d Contents:",connecthead,ind);
		for (i=0; i<len; i++)
			initprintf(" %02x", buf[i]);
		initprintf("\n");
		
		prx->PacketType = PACKET_TYPE_PROXY;
		prx->PlayerIndex = (BYTE)ind;
		memcpy(&prx[1], buf, len);	// &prx[1] == (char*)prx + sizeof(PACKET_PROXY)
		len += sizeof(PACKET_PROXY);

		sendpacket(connecthead, bbuf, len);
		return;
	}

	sendpacket(ind, buf, len);

	initprintf("netsendpacket() sends normal to %d\nContents:",ind);
	for (i=0; i<len; i++)
		initprintf(" %02x", buf[i]);
	initprintf("\n");
}
Esempio n. 2
0
int send_LANdiscovery(uint16_t port, DHT *dht)
{
    uint8_t data[CRYPTO_PUBLIC_KEY_SIZE + 1];
    data[0] = NET_PACKET_LAN_DISCOVERY;
    id_copy(data + 1, dht->self_public_key);

    send_broadcasts(dht->net, port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE);

    int res = -1;
    IP_Port ip_port;
    ip_port.port = port;

    /* IPv6 multicast */
    if (dht->net->family == AF_INET6) {
        ip_port.ip = broadcast_ip(AF_INET6, AF_INET6);

        if (ip_isset(&ip_port.ip)) {
            if (sendpacket(dht->net, ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE) > 0) {
                res = 1;
            }
        }
    }

    /* IPv4 broadcast (has to be IPv4-in-IPv6 mapping if socket is AF_INET6 */
    ip_port.ip = broadcast_ip(dht->net->family, AF_INET);

    if (ip_isset(&ip_port.ip)) {
        if (sendpacket(dht->net, ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE)) {
            res = 1;
        }
    }

    return res;
}
Esempio n. 3
0
int main(int argc,char* argv[])
{
    int s1,port,i,n,r,Sb,Sn,Rn,flag=0,w=5,EarliestMiss=-1;
    char buff[256];

    if(argc<2)
    {
        printf("Port? : ");
        scanf("%d",&port);
        gets(buff);
    }
    else
        port=atoi(argv[1]);
    s1=connectto("127.0.0.1",port);

    printf("Enter the total number of packets to be sent : ");
    scanf("%d",&n);
    printf("Enter the percentage packet lose rate : ");
    scanf("%d",&r);
    printf("Selective repeat with window size %d\n",w);
    Sb=0;
    Sn=w-1;

    while(1)
    {
        for(i=Sb; i<=Sn; i++)
        {
            if(i<n)
                sendpacket(s1,i,r);
            if(waittoread(s1)==1)
            {
                bzero(&buff,256);
                read(s1,buff,255);
                printf("Request for packet %s received \n",buff);
                Rn=atoi(buff);
                if(Rn>EarliestMiss)
                    EarliestMiss=Rn;
            }
        }
        while(EarliestMiss>=Sb && EarliestMiss<=sn)
        {
            sendpacket(s1,EarliestMiss,r);
            if(waittoread(s1)==1)
            {
                bzero(&buff,256);
                read(s1,buff,255);
                printf("Request for packet %s received\n",buff);
                Rn=atoi(buff);
                EarliestMiss=Rn;
            }
        }
        Sn=Sn+w;
        Sb=Sb+w;
        if(Sb>=n)
            break;
        printf("Moving window forward\n");
    }
    close(s1);
    printf("Client closed \n");
}
Esempio n. 4
0
int lan_discovery_send(uint16_t port, DHT *dht)
{
    uint8_t data[CRYPTO_PUBLIC_KEY_SIZE + 1];
    data[0] = NET_PACKET_LAN_DISCOVERY;
    id_copy(data + 1, dht_get_self_public_key(dht));

    send_broadcasts(dht_get_net(dht), port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE);

    int res = -1;
    IP_Port ip_port;
    ip_port.port = port;

    /* IPv6 multicast */
    if (net_family(dht_get_net(dht)) == TOX_AF_INET6) {
        ip_port.ip = broadcast_ip(TOX_AF_INET6, TOX_AF_INET6);

        if (ip_isset(&ip_port.ip)) {
            if (sendpacket(dht_get_net(dht), ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE) > 0) {
                res = 1;
            }
        }
    }

    /* IPv4 broadcast (has to be IPv4-in-IPv6 mapping if socket is TOX_AF_INET6 */
    ip_port.ip = broadcast_ip(net_family(dht_get_net(dht)), TOX_AF_INET);

    if (ip_isset(&ip_port.ip)) {
        if (sendpacket(dht_get_net(dht), ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE)) {
            res = 1;
        }
    }

    return res;
}
Esempio n. 5
0
int main( int argc, char **argv)
{

    char buffer[8192];
    char dat[8192];
    int count;

    if(argc<4)
    {
         printf("Usage %s [host] [/folder/] [cmd]\n\nSimpleBBS <= v1.1 remote commands execution in c\ncoded by: unitedasia v.Dec.7.2005\ngreetz: iloveyouma\n",argv[0]);
         exit(1);
    }

    sprintf(dat, DATA);

    sprintf( buffer, "POST %sindex.php?v=newtopic&c=0 HTTP/1.0\nHost: %s\nContent-Type: application/x-www-form-urlencoded\nContent-Length: %d\n\n%s\n\n\n", argv[2], argv[1], strlen(dat), dat);

    sendpacket(buffer,0,argv[1]);

    sprintf( buffer, "GET %sdata/topics.php?cmd=%s HTTP/1.0\nHost: %s\n\n", argv[2], argv[3], argv[1]);

    sendpacket(buffer,1,argv[1]);

    return count;
}
Esempio n. 6
0
int send_LANdiscovery(uint16_t port, DHT *dht)
{
    uint8_t data[crypto_box_PUBLICKEYBYTES + 1];
    data[0] = NET_PACKET_LAN_DISCOVERY;
    id_copy(data + 1, dht->self_public_key);

#ifdef __linux
    send_broadcasts(dht->net, port, data, 1 + crypto_box_PUBLICKEYBYTES);
#endif
    int res = -1;
    IP_Port ip_port;
    ip_port.port = port;

    /* IPv6 multicast */
    if (dht->net->family == AF_INET6) {
        ip_port.ip = broadcast_ip(AF_INET6, AF_INET6);

        if (ip_isset(&ip_port.ip))
            if (sendpacket(dht->net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES) > 0)
                res = 1;
    }

    /* IPv4 broadcast (has to be IPv4-in-IPv6 mapping if socket is AF_INET6 */
    ip_port.ip = broadcast_ip(dht->net->family, AF_INET);

    if (ip_isset(&ip_port.ip))
        if (sendpacket(dht->net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES))
            res = 1;

    return res;
}
Esempio n. 7
0
int main(int argc,char **argv)
{
    mutil_thread = 0;
    setup_signal_handler();
    init_clients();
    InitNetSystem();
    ENGINE engine = CreateEngine();
    int csize = atoi(argv[3]);
    int i = 0;
    for(; i < csize; ++i)
        EConnect(engine,argv[1],atoi(argv[2]),(void*)engine,on_connect,1000);
    uint32_t tick,now;
    tick = now = GetSystemMs();
    while(!stop) {
        EngineRun(engine,50);
        sendpacket();
        now = GetSystemMs();
        if(now - tick > 1000)
        {
            printf("ava_interval:%d\n",ava_interval);
            tick = now;
        }
    }
    CleanNetSystem();
    return 0;
}
Esempio n. 8
0
int send_ping_request(PING *ping, IP_Port ipp, size_t *client_id)
{
    size_t   pk[DHT_PING_SIZE];
    int       rc;
    size_t  ping_id;

    if (is_pinging(ping, ipp, 0) || id_equal(client_id, ping->dht->self_public_key))
        return 1;

    // Generate random ping_id.
    ping_id = add_ping(ping, ipp);

    pk[0] = NET_PACKET_PING_REQUEST;
    id_copy(pk + 1, ping->dht->self_public_key);     // Our pubkey
    new_nonce(pk + 1 + CLIENT_ID_SIZE); // Generate new nonce

    // Encrypt ping_id using recipient privkey
    rc = encrypt_data(client_id,
                      ping->dht->self_secret_key,
                      pk + 1 + CLIENT_ID_SIZE,
                      (size_t *) &ping_id, sizeof(ping_id),
                      pk + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES);

    if (rc != sizeof(ping_id) + crypto_box_MACBYTES)
        return 1;

    return sendpacket(ping->dht->net, ipp, pk, sizeof(pk));
}
Esempio n. 9
0
static void function (struct channel * channel, void * memory, ssize_t extent)

{
	struct ether_header * frame = (struct ether_header *)(memory);
	unsigned length;
	while ((length = (unsigned)(hexload (memory, extent, stdin))) > 0)
	{
		if (length < (ETHER_MIN_LEN - ETHER_CRC_LEN))
		{
			error (1, ENOTSUP, "Frame size of %d is less than %d bytes", length, (ETHER_MIN_LEN - ETHER_CRC_LEN));
		}
		if (length > (ETHER_MAX_LEN - ETHER_CRC_LEN))
		{
			error (1, ENOTSUP, "Frame size of %d is more than %d bytes", length, (ETHER_MAX_LEN - ETHER_CRC_LEN));
		}
		if (_anyset (channel->flags, CHANNEL_UPDATE_TARGET))
		{
			memcpy (frame->ether_dhost, channel->peer, sizeof (frame->ether_dhost));
		}
		if (_anyset (channel->flags, CHANNEL_UPDATE_SOURCE))
		{
			memcpy (frame->ether_shost, channel->host, sizeof (frame->ether_shost));
		}
		sendpacket (channel, memory, length);
		if (_anyset (channel->flags, CHANNEL_LISTEN))
		{
			while (readpacket (channel, memory, extent) > 0);
		}
	}
	return;
}
Esempio n. 10
0
int c_brem(w_coord wcoord, b_coord bcoord) {

    server_socket *dst;

    n_coord ncoord;

    void *p;
    lt_packet out_packet;

    client_func_checks();

    ncoord = wcoord_to_ncoord(wcoord);

    dst = find_neighbor(ncoord);

    if (!dst) return 0;

    makepacket(&out_packet, T_BREM);
    p = &out_packet.payload;

    if (!put_wx(&p, wcoord.x, &PLength(&out_packet), &PArgc(&out_packet))) return 1;
    if (!put_wy(&p, wcoord.y, &PLength(&out_packet), &PArgc(&out_packet))) return 1;
    if (!put_wz(&p, wcoord.z, &PLength(&out_packet), &PArgc(&out_packet))) return 1;
    if (!put_bx(&p, bcoord.x, &PLength(&out_packet), &PArgc(&out_packet))) return 1;
    if (!put_by(&p, bcoord.y, &PLength(&out_packet), &PArgc(&out_packet))) return 1;
    if (!put_bz(&p, bcoord.z, &PLength(&out_packet), &PArgc(&out_packet))) return 1;

    return (sendpacket(dst, &out_packet));

}
Esempio n. 11
0
boolean PN532::InCommunicateThru(const byte * data, const byte len) {
	packet[0] = COMMAND_InCommunicateThru;
	packet[1] = len + 1;
	memcpy(packet + 2, data, len);

#ifdef FELICADEBUG
	Serial.print("Thru: ");
	Serial.print("count = ");
	Serial.print(len + 1, DEC);
	Serial.print("  ");
	printHexString(packet, len + 2);
	Serial.println();
#endif

	/* Send the command */
	sendpacket(len + 2);
	comm_status = COMMAND_ISSUED;
	last_command = COMMAND_InCommunicateThru;
	if (!checkACKframe()) {
		comm_status = ACK_NOT_RECEIVED;
		return 0;
	}
	comm_status = ACK_FRAME_RECEIVED;
	return 1;
}
Esempio n. 12
0
/* Try to send a friend request to peer with public_key.
 * data is the data in the request and length is the length.
 * return -1 if failure.
 * return  0 if it sent the friend request directly to the friend.
 * return the number of peers it was routed through if it did not send it directly.
 */
int send_friendrequest(DHT *dht, uint8_t *public_key, uint32_t nospam_num, uint8_t *data, uint32_t length)
{
    if (length + sizeof(nospam_num) > MAX_DATA_SIZE)
        return -1;

    uint8_t temp[MAX_DATA_SIZE];
    memcpy(temp, &nospam_num, sizeof(nospam_num));
    memcpy(temp + sizeof(nospam_num), data, length);
    uint8_t packet[MAX_DATA_SIZE];
    int len = create_request(dht->c->self_public_key, dht->c->self_secret_key, packet, public_key, temp,
                             length + sizeof(nospam_num),
                             CRYPTO_PACKET_FRIEND_REQ);

    if (len == -1)
        return -1;

    IP_Port ip_port = DHT_getfriendip(dht, public_key);

    if (ip_port.ip.uint32 == 1)
        return -1;

    if (ip_port.ip.uint32 != 0) {
        if (sendpacket(dht->c->lossless_udp->net->sock, ip_port, packet, len) != -1)
            return 0;

        return -1;
    }

    int num = route_tofriend(dht, public_key, packet, len);

    if (num == 0)
        return -1;

    return num;
}
Esempio n. 13
0
File: client.c Progetto: twonly/mis
int	ppfs_chmod (const char *path, mode_t mt){
  fprintf(stderr, "ppfs_chmod path : %s\n", path);

  ppacket *s = createpacket_s(4+strlen(path)+4, CLTOMD_CHMOD,-1);
  uint8_t* ptr = s->startptr+HEADER_LEN;

  put32bit(&ptr, strlen(path));
  memcpy(ptr, path, strlen(path));
  ptr+=strlen(path);
  put32bit(&ptr, mt);

  sendpacket(fd, s);
  free(s);

  s = receivepacket(fd);
  const uint8_t* ptr2 = s->startptr;
  int status = get32bit(&ptr2);

  if(status == 0){
    print_attr((const attr*)ptr2);

    attr_cache* ac;
    if(lookup_attr_cache(path,&ac) == 0){
      ac->a.mode = mt;
    }

  }
  free(s);

  return status;
}
Esempio n. 14
0
/* Create and send an onion announce request packet.
 *
 * path is the path the request will take before it is sent to dest.
 *
 * public_key and secret_key is the kepair which will be used to encrypt the request.
 * ping_id is the ping id that will be sent in the request.
 * client_id is the client id of the node we are searching for.
 * data_public_key is the public key we want others to encrypt their data packets with.
 * sendback_data is the data of ONION_ANNOUNCE_SENDBACK_DATA_LENGTH length that we expect to
 * receive back in the response.
 *
 * return -1 on failure.
 * return 0 on success.
 */
int send_announce_request(Networking_Core *net, const Onion_Path *path, Node_format dest, const uint8_t *public_key,
                          const uint8_t *secret_key, const uint8_t *ping_id, const uint8_t *client_id, const uint8_t *data_public_key,
                          uint64_t sendback_data)
{
    uint8_t request[ONION_ANNOUNCE_REQUEST_SIZE];
    int len = create_announce_request(request, sizeof(request), dest.public_key, public_key, secret_key, ping_id, client_id,
                                      data_public_key, sendback_data);

    if (len != sizeof(request)) {
        return -1;
    }

    uint8_t packet[ONION_MAX_PACKET_SIZE];
    len = create_onion_packet(packet, sizeof(packet), path, dest.ip_port, request, sizeof(request));

    if (len == -1) {
        return -1;
    }

    if (sendpacket(net, path->ip_port1, packet, len) != len) {
        return -1;
    }

    return 0;
}
Esempio n. 15
0
int send_ping_request(IP_Port ipp, clientid_t* client_id)
{
    pingreq_t pk;
    int       rc;
    uint64_t  ping_id;

    if (is_pinging(ipp, 0) || id_eq(client_id, self_id))
        return 1;

    // Generate random ping_id
    ping_id = add_ping(ipp);

    pk.magic = PACKET_PING_REQ;
    id_cpy(&pk.client_id, self_id);     // Our pubkey
    random_nonce((uint8_t*) &pk.nonce); // Generate random nonce

    // Encrypt ping_id using recipient privkey
    rc = encrypt_data((uint8_t*) client_id,
                      self_secret_key,
                      (uint8_t*) &pk.nonce,
                      (uint8_t*) &ping_id, sizeof(ping_id),
                      (uint8_t*) &pk.ping_id);

    if (rc != sizeof(ping_id) + ENCRYPTION_PADDING)
        return 1;

    return sendpacket(ipp, (uint8_t*) &pk, sizeof(pk));
}
Esempio n. 16
0
/* Try to send a friendrequest to peer with public_key
   data is the data in the request and length is the length.
   return -1 if failure.
   return  0 if it sent the friend request directly to the friend.
   return the number of peers it was routed through if it did not send it directly.*/
int send_friendrequest(uint8_t * public_key, uint8_t * data, uint32_t length)
{
    uint8_t packet[MAX_DATA_SIZE];
    int len = create_request(packet, public_key, data, length, 32); /* 32 is friend request packet id */

    if (len == -1)
        return -1;

    IP_Port ip_port = DHT_getfriendip(public_key);

    if (ip_port.ip.i == 1)
        return -1;

    if (ip_port.ip.i != 0) {
        if (sendpacket(ip_port, packet, len) != -1)
            return 0;
        return -1;
    }

    int num = route_tofriend(public_key, packet, len);

    if (num == 0)
        return -1;

    return num;
}
/*
 * Driver transmit daemon
 */
void
wd_txDaemon (void *arg)
{
	struct wd_softc *sc = (struct wd_softc *)arg;
	struct ifnet *ifp = &sc->arpcom.ac_if;
	struct mbuf *m;
	rtems_event_set events;

	for (;;) {
		/*
		 * Wait for packet
		 */
		rtems_bsdnet_event_receive (START_TRANSMIT_EVENT, RTEMS_EVENT_ANY | RTEMS_WAIT, RTEMS_NO_TIMEOUT, &events);

		/*
		 * Send packets till queue is empty
		 */
		for (;;) {
			/*
			 * Get the next mbuf chain to transmit.
			 */
			IF_DEQUEUE(&ifp->if_snd, m);
			if (!m)
				break;
			sendpacket (ifp, m);
		}
		ifp->if_flags &= ~IFF_OACTIVE;
	}
}
Esempio n. 18
0
void clinterface::sendaa(client *who, absuser *ex)
{
   char data[1000];
   sprintf(data,"%s:SERVER:%s:%s::%d", who->callsign, who->realname,
      who->cid,who->rating,who->protocol);
   sendpacket(NULL, NULL, ex, CLIENT_ALL, -1, CL_ADDATC, data);
}
Esempio n. 19
0
void clinterface::sendap(client *who, absuser *ex)
{
   char data[1000];
   sprintf(data,"%s:SERVER:%s::%d:%s:%d",who->callsign,who->cid,who->rating,
      who->protocol,who->simtype);
   sendpacket(NULL, NULL, ex, CLIENT_ALL, -1, CL_ADDPILOT, data);
}
Esempio n. 20
0
File: client.c Progetto: twonly/mis
int	ppfs_chown (const char *path, uid_t uid, gid_t gid){
  fprintf(stderr, "ppfs_chown path : %s\n", path);


  ppacket *s = createpacket_s(4+strlen(path)+8, CLTOMD_CHOWN, -1);
  uint8_t* ptr = s->startptr+HEADER_LEN;

  put32bit(&ptr, strlen(path));
  memcpy(ptr, path, strlen(path));
  ptr+=strlen(path);
  put32bit(&ptr, uid);
  put32bit(&ptr, gid);

  sendpacket(fd, s);
  free(s);

  s = receivepacket(fd);
  const uint8_t* ptr2 = s->startptr;
  int status = get32bit(&ptr2);

  if(status == 0){
    print_attr((const attr*)ptr2);

    attr_cache* ac;
    if(lookup_attr_cache(path,&ac) == 0){
      ac->a.uid = uid;
      ac->a.gid = gid;
    }
  }
  free(s);

  return status;
}
Esempio n. 21
0
/* Function to send onion packet via TCP and UDP.
 *
 * return -1 on failure.
 * return 0 on success.
 */
static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, const Onion_Path *path, IP_Port dest,
                                     const uint8_t *data, uint32_t length)
{
    if (path->ip_port1.ip.family == AF_INET || path->ip_port1.ip.family == AF_INET6) {
        uint8_t packet[ONION_MAX_PACKET_SIZE];
        int len = create_onion_packet(packet, sizeof(packet), path, dest, data, length);

        if (len == -1)
            return -1;

        if (sendpacket(onion_c->net, path->ip_port1, packet, len) != len)
            return -1;

        return 0;
    } else if (path->ip_port1.ip.family == TCP_FAMILY) {
        uint8_t packet[ONION_MAX_PACKET_SIZE];
        int len = create_onion_packet_tcp(packet, sizeof(packet), path, dest, data, length);

        if (len == -1)
            return -1;

        return send_tcp_onion_request(onion_c->c, packet, len);
    } else {
        return -1;
    }
}
Esempio n. 22
0
File: client.c Progetto: twonly/mis
int	ppfs_rmdir (const char *path){
  fprintf(stderr, "ppfs_rmdir path : %s\n", path);

  dir_cache* dc;
  if(lookup_dir_cache(path,&dc) == 0){
    remove_dir_cache(dc);
    free_dir_cache(dc);
  }

  ppacket* p = createpacket_s(4+strlen(path),CLTOMD_RMDIR,-1);
  uint8_t* ptr = p->startptr + HEADER_LEN;

  put32bit(&ptr,strlen(path));
  memcpy(ptr,path,strlen(path));
  ptr += strlen(path);

  sendpacket(fd,p);
  free(p);

  p = receivepacket(fd);
  const uint8_t* ptr2 = p->startptr;
  int status = get32bit(&ptr2);

  fprintf(stderr, "rmdir status:%d\n", status);
  free(p);
  return status;
}
Esempio n. 23
0
byte PN532::InListPassiveTarget(const byte maxtg, const byte brty, byte * data,
		const byte length) {
//	byte inidatalen = 0;
	packet[0] = COMMAND_InListPassiveTarget;
	packet[1] = maxtg; // max 1 cards at once (we can set this to 2 later)
	packet[2] = brty;
	if (length > 0) {
		memcpy(packet + 3, data, length);
	}
#ifdef PN532DEBUG
	Serial.print("InListPassiveTarget << ");
	printHexString(packet, length + 3);
	Serial.println();
#endif
	sendpacket(3 + length);
	last_command = COMMAND_InListPassiveTarget;
	comm_status = COMMAND_ISSUED;
	if (!checkACKframe()) {
		comm_status = ACK_NOT_RECEIVED;
		return 0;
	}
#ifdef PN532DEBUG
	Serial.println("ACKed.");
#endif
	comm_status = ACK_FRAME_RECEIVED;
	return 1;
}
Esempio n. 24
0
static int handle_recv_2(void *object, IP_Port source, const uint8_t *packet, uint16_t length)
{
    Onion *onion = object;

    if (length > ONION_MAX_PACKET_SIZE)
        return 1;

    if (length <= 1 + RETURN_2)
        return 1;

    change_symmetric_key(onion);

    uint8_t plain[SIZE_IPPORT + RETURN_1];
    int len = decrypt_data_symmetric(onion->secret_symmetric_key, packet + 1, packet + 1 + crypto_box_NONCEBYTES,
                                     SIZE_IPPORT + RETURN_1 + crypto_box_MACBYTES, plain);

    if ((uint32_t)len != sizeof(plain))
        return 1;

    IP_Port send_to;

    if (ipport_unpack(&send_to, plain, len, 0) == -1)
        return 1;

    uint8_t data[ONION_MAX_PACKET_SIZE];
    data[0] = NET_PACKET_ONION_RECV_1;
    memcpy(data + 1, plain + SIZE_IPPORT, RETURN_1);
    memcpy(data + 1 + RETURN_1, packet + 1 + RETURN_2, length - (1 + RETURN_2));
    uint16_t data_len = 1 + RETURN_1 + (length - (1 + RETURN_2));

    if ((uint32_t)sendpacket(onion->net, send_to, data, data_len) != data_len)
        return 1;

    return 0;
}
Esempio n. 25
0
File: client.c Progetto: twonly/mis
int ppfs_utimens(const char* path,const struct timespec tv[2]){ //tv[0]: atime, tv[1] mtime


  ppacket* p = createpacket_s(4+strlen(path)+4+4,CLTOMD_UTIMENS,-1);
  uint8_t* ptr = p->startptr + HEADER_LEN;
  int len = strlen(path);

  put32bit(&ptr,len);
  memcpy(ptr,path,len);
  ptr += len;
  put32bit(&ptr,tv[0].tv_sec);
  put32bit(&ptr,tv[1].tv_sec);

  sendpacket(fd,p);
  free(p);

  p = receivepacket(fd);
  const uint8_t* ptr2 = p->startptr;
  int status = get32bit(&ptr2);
  if(status == 0){
    attr_cache* ac;
    if(lookup_attr_cache(path,&ac) == 0){
      ac->a.atime = tv[0].tv_sec;
      ac->a.ctime = tv[1].tv_sec;
    }
  }

  free(p);
  return status;
}
Esempio n. 26
0
//send a ping response
static int pingres(IP_Port ip_port, uint8_t * public_key, uint64_t ping_id)
{
    if(memcmp(public_key, self_public_key, CLIENT_ID_SIZE) == 0)//check if packet is gonna be sent to ourself
    {
        return 1;
    }
    
    uint8_t data[1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(ping_id) + ENCRYPTION_PADDING];
    uint8_t encrypt[sizeof(ping_id) + ENCRYPTION_PADDING];
    uint8_t nonce[crypto_box_NONCEBYTES];
    random_nonce(nonce);
    
    int len = encrypt_data(public_key, self_secret_key, nonce, (uint8_t *)&ping_id, sizeof(ping_id), encrypt);
    if(len != sizeof(ping_id) + ENCRYPTION_PADDING)
    {
        return -1;
    }
    data[0] = 1;
    memcpy(data + 1, self_public_key, CLIENT_ID_SIZE);
    memcpy(data + 1 + CLIENT_ID_SIZE, nonce, crypto_box_NONCEBYTES);
    memcpy(data + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, encrypt, len);
    
    return sendpacket(ip_port, data, sizeof(data));
    
}
Esempio n. 27
0
static int handle_recv_1(void *object, IP_Port source, const uint8_t *packet, uint16_t length)
{
    Onion *onion = object;

    if (length > ONION_MAX_PACKET_SIZE)
        return 1;

    if (length <= 1 + RETURN_1)
        return 1;

    change_symmetric_key(onion);

    uint8_t plain[SIZE_IPPORT];
    int len = decrypt_data_symmetric(onion->secret_symmetric_key, packet + 1, packet + 1 + crypto_box_NONCEBYTES,
                                     SIZE_IPPORT + crypto_box_MACBYTES, plain);

    if ((uint32_t)len != SIZE_IPPORT)
        return 1;

    IP_Port send_to;

    if (ipport_unpack(&send_to, plain, len, 1) == -1)
        return 1;

    uint16_t data_len = length - (1 + RETURN_1);

    if (onion->recv_1_function && send_to.ip.family != AF_INET && send_to.ip.family != AF_INET6)
        return onion->recv_1_function(onion->callback_object, send_to, packet + (1 + RETURN_1), data_len);

    if ((uint32_t)sendpacket(onion->net, send_to, packet + (1 + RETURN_1), data_len) != data_len)
        return 1;

    return 0;
}
Esempio n. 28
0
int main(int argc, char *argv[])
{
    struct bootp* bp;
    int s;

    get_args(argc, argv);

    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(SERVER_PORT);
    server_addr.sin_addr.s_addr = inet_addr(host_addr);


    if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
        fprintf(stderr, "cannot create socket\n");
        exit(1);
    }
    if ((bp = (struct bootp*) malloc(MAX_MSG_SIZE + 1000)) == NULL) {
        (void) fprintf(stderr, "Cannot malloc.\n");
        exit(1);
    };
    (void) memset(bp, 0, MAX_MSG_SIZE + 1000); /* ai exploit isn't secure */
    build_packet(bp, argc, argv);

    sendpacket(s, bp);
}
Esempio n. 29
0
char* cmd_identify(appconfig_t* myconfig)
{
	if (myconfig->verbose>0) printf("Executing CMD_IDENT\n");
	datapkt_t tosend;
	datapkt_t response;
	char nodename[CMD_IDENTIFY_LONGEST_NODE_NAME +1];
	memset(nodename, 0x00, CMD_IDENTIFY_LONGEST_NODE_NAME +1);

	for (int pktsgot=0; pktsgot<CMD_IDENTIFY_LONGEST_NODE_NAME /4; pktsgot++)
	{
		// assemble the request packet to send to the chip
		setnewseq(&tosend);
		tosend.nodeid = myconfig->nodeid;
		tosend.byte6 = CMD_IDENT;
		tosend.byte7 = pktsgot;
		tosend.byte8 = 0x00;

		// send it
		BOOL success = sendpacket(tosend, &response, myconfig->hnd, myconfig->key, myconfig->verbose);

		if (!success)
		{
			return NULL;
		}
		memcpy(&nodename[pktsgot*4], &(response.nodeid), 4);
		if (response.nodeid==00 || response.byte6==00 || response.byte7==00 || response.byte8==00)
			break;
	}

	char* toreturn = (char*)malloc((pktsgot*4)+1);
	strcpy(toreturn,nodename);

	return toreturn;
}
Esempio n. 30
0
File: ping.c Progetto: Dmdv/toxcore
static int send_ping_response(PING *ping, IP_Port ipp, const uint8_t *public_key, uint64_t ping_id,
                              uint8_t *shared_encryption_key)
{
    uint8_t   pk[DHT_PING_SIZE];
    int       rc;

    if (id_equal(public_key, ping->dht->self_public_key))
        return 1;

    uint8_t ping_plain[PING_PLAIN_SIZE];
    ping_plain[0] = NET_PACKET_PING_RESPONSE;
    memcpy(ping_plain + 1, &ping_id, sizeof(ping_id));

    pk[0] = NET_PACKET_PING_RESPONSE;
    id_copy(pk + 1, ping->dht->self_public_key);     // Our pubkey
    new_nonce(pk + 1 + crypto_box_PUBLICKEYBYTES); // Generate new nonce

    // Encrypt ping_id using recipient privkey
    rc = encrypt_data_symmetric(shared_encryption_key,
                                pk + 1 + crypto_box_PUBLICKEYBYTES,
                                ping_plain, sizeof(ping_plain),
                                pk + 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES );

    if (rc != PING_PLAIN_SIZE + crypto_box_MACBYTES)
        return 1;

    return sendpacket(ping->dht->net, ipp, pk, sizeof(pk));
}