Example #1
0
//when you need to handle a join reply, use the params join_ip and join_port
//otherwise, join_ip=0 and join_port=-1
void peer_list(unsigned int join_ip, short join_port, unsigned int room){
  //create payload for join and update replies
  struct peer *s;
  int num_in_room = 0;
  for(s=peers; s != NULL; s=(peer *)s->hh.next){
    if(s->room==room){
      num_in_room = num_in_room+1;
    }
  }
  struct sockaddr_in list[num_in_room];
  int a = 0;
  for(s=peers; s != NULL; s=(peer *)s->hh.next){
    if(s->room==room){
      unsigned int peer_ip = get_ip(s->ip_and_port);
      short peer_port = get_port(s->ip_and_port);
      struct sockaddr_in peer_info = get_sockaddr_in(peer_ip, peer_port);
      sockaddr_in* peer_info_ptr = &peer_info;
      memcpy((sockaddr_in*)&list[a], peer_info_ptr, sizeof(peer_info));
      a=a+1;
    }
  }

  packet update_pkt;
  update_pkt.header.type = 'u';
  update_pkt.header.error = '\0';
  update_pkt.header.payload_length = num_in_room * sizeof(struct sockaddr_in);
  memcpy(update_pkt.payload, list, num_in_room * sizeof(struct sockaddr_in));
  for(s=peers; s != NULL; s=(peer *)s->hh.next){
    if(s->room==room){
      unsigned int peer_ip = get_ip(s->ip_and_port);
      short peer_port = get_port(s->ip_and_port);
      if(join_port!=-1 and join_ip!=0 and peer_ip == join_ip and peer_port==join_port){
        //send join
        packet join_pkt;
        join_pkt.header.type = 'j';
        join_pkt.header.error = '\0';
        join_pkt.header.room = room;
        join_pkt.header.payload_length = num_in_room * sizeof(struct sockaddr_in);
        memcpy(join_pkt.payload, list, num_in_room * sizeof(struct sockaddr_in));
        struct sockaddr_in peer_addr = get_sockaddr_in(peer_ip, peer_port);
        int status = sendto(sock, &join_pkt, sizeof(join_pkt), 0, (struct sockaddr *)&peer_addr, sizeof(peer_addr));
        if (status == -1) {
          pthread_mutex_lock(&stdout_lock);
          fprintf(stderr, "%s\n", "error - error sending packet to peer");
          pthread_mutex_unlock(&stdout_lock);
        }
      }else{
        struct sockaddr_in peer_addr = get_sockaddr_in(peer_ip, peer_port);
        int status = sendto(sock, &update_pkt, sizeof(update_pkt), 0, (struct sockaddr *)&peer_addr, sizeof(peer_addr));
        if (status == -1) {
          pthread_mutex_lock(&stdout_lock);
          fprintf(stderr, "%s\n", "error - error sending packet to peer");
          pthread_mutex_unlock(&stdout_lock);
        }
      }
    }
  }
}
Example #2
0
static void incoming_arp(struct clip_vcc *clip_vcc, struct atmarphdr *hdr,
    int len)
{
    void *spa,*tpa;
    u32 src_ip,tgt_ip;
    u8 *here;

    if (len < hdr->data - (u8 *)hdr)
    {
	printk(KERN_WARNING "got truncated ARP packet (%d bytes)\n", len);
	return;
    }
    if (hdr->ar_hrd != htons(ARPHRD_ATM))
    {
	printk(KERN_WARNING "unknown hw protocol 0x%04x", ntohs(hdr->ar_hrd));
	return;
    }
    if (hdr->ar_pro != htons(ETH_P_IP))
    {
	printk(KERN_WARNING "unknown upper protocol 0x%04x",
	    ntohs(hdr->ar_pro));
	return;
    }
    if (!(hdr->ar_shtl & TL_LEN)) hdr->ar_shtl = 0; /* paranoia */
    if (!(hdr->ar_thtl & TL_LEN)) hdr->ar_thtl = 0;
    here = hdr->data;
    get_addr(&here, hdr->ar_shtl & TL_LEN);
    get_addr(&here, hdr->ar_sstl & TL_LEN);
    spa = get_addr(&here, hdr->ar_spln);
    get_addr(&here, hdr->ar_thtl & TL_LEN);
    get_addr(&here, hdr->ar_tstl & TL_LEN);
    tpa = get_addr(&here, hdr->ar_tpln);
    if (here - (u8 *)hdr > len)
    {
	printk(KERN_WARNING "message too short (got %d, need %d)",len,
	    here - (u8 *)hdr);
	return;
    }
    src_ip = get_ip(spa);
    tgt_ip = get_ip(tpa);
    
    switch (ntohs(hdr->ar_op)) {
    case ARPOP_InREQUEST:
	DPRINTK("got InARP_REQ");
	if (!clip_learn(clip_vcc, src_ip))
	    clip_inarp_reply_send(clip_vcc->vcc, src_ip);
	break;
    case ARPOP_InREPLY:
	DPRINTK("got InARP_REP");
	clip_learn(clip_vcc, src_ip);
	break;
    default:
	DPRINTK("unrecognized ARP op 0x%x", ntohs(hdr->ar_op));
    }
}
Example #3
0
void Client::disconnect(const char* reason)
{
	if(!connected)
		return;

	if(reason)
		logger->info(format("[%1%] Disconnecting - %2%") % get_ip() % reason);
	else
		logger->info(format("[%1%] Disconnection. Reason unknown.") % get_ip());

	really_disconnect(socket, logger);

	connected = false;
}
Example #4
0
int tcp_connect(char *host)
{
  struct sockaddr_in *remote;
  int sock;
  int tmpres;
  char *ip;

  if((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0){
    perror("Can't create TCP socket");
    return 0;
  }

  ip = get_ip(host);
  fprintf(stderr, "IP is %s\n", ip);
  remote = (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in *));
  remote->sin_family = AF_INET;
  tmpres = inet_pton(AF_INET, ip, (void *)(&(remote->sin_addr.s_addr)));
  if( tmpres < 0)
  {
    perror("Can't set remote->sin_addr.s_addr");
    return 0;
  }else if(tmpres == 0)
  {
    fprintf(stderr, "%s is not a valid IP address\n", ip);
    return 0;
  }
  remote->sin_port = htons(PORT);

  if(connect(sock, (struct sockaddr *)remote, sizeof(struct sockaddr)) < 0){
    perror("Could not connect");
    return 0;
  }
  return sock;
}
Example #5
0
int main()
{
  // sock: the socket.
  int sock = create_tcp_socket();

  // remote: a record of an input socket address.
  struct sockaddr_in* remote =
    (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in *));
  remote->sin_family = AF_INET;
  host = argv[1];
  char* ip = get_ip(host);
  int tmp_res = inet_pton(AF_INET, ip, (void*) (&(remote->sin_addr.s_addr)));
  if (tmp_res < 0) {
    fprintf(stderr, "inet_pton failed\n");
    exit(1);
  }
  remote->sin_port = htons(PORT);

  // Connect the socket to the remote host.
  if (connect(sock, (struct sockaddr*) remote, sizeof(struct sockaddr)) < 0) {
    fprintf(stderr, "connect failed\n");
    exit(0);
  }

  printf("connected successfully to remote host\n");
  return;
}
Example #6
0
int send_ipmac()              //sleep 2s ,发送一次,接收函数需要无阻塞
{
  char sendmsg[100];
  char mac_data[30];
  char ipaddr[40];
  memset(mac_data,0,sizeof(char)*30);
  memset(ipaddr,0,sizeof(char)*40);
  memset(sendmsg,0,sizeof(char)*100);
  
  if(!get_ip("eth0",ipaddr))
  {
     DEBUG_printf("get IP error\n");  
  }
  get_macforkey(mac_data,"eth0");
  strncpy(mac_tmp,mac_data,strlen(mac_data));
  strcpy(sendmsg,ipaddr);
  strcat(sendmsg,",");
  strcat(sendmsg,mac_data);
  
  int ret=sendto(udp_sock, sendmsg, strlen(sendmsg), 0, (struct sockaddr*)&addrto, sizeof(addrto)); 
  if(ret<0)
  {
   DEBUG_printf("send error....");
  }
  else
  {		
   DEBUG_printf("send ipmac:\n%s\n",sendmsg);	
  }
 DELAY_2S;
  return 1;
 }
Example #7
0
int send_request(struct request* req, int* http_response_code, char * buffer) {

  struct sockaddr_in *remote;
  int sock;
  int buffer_size = TAILLE;
  int tmpres;

  char ip[16];
  memset( (char*) ip, 0, 16);
  
   get_ip(req->host, (char*) ip);
  
  if (ip==NULL) {
    perror("libvmod_3scale: could not resolve the ip");
  }
  else {

    char* template;
    char * srequest;

    if (req->http_verb==HTTP_POST) {

      int body_len = strlen(req->body);
      char tmp[128];
      sprintf(tmp,"%d",body_len+1); 
      int body_len_len = strlen(tmp);
      
      if ((req->header==NULL) || (strlen(req->header)==0)) {
Example #8
0
int send_uptime(void)
{
  struct sockaddr_in sai;
  struct stat st;
  PackUp *mem;
  int len, servidx;
  char servhost[UHOSTLEN] = "none";
  module_entry *me;

  if (uptimeip == -1) {
    uptimeip = get_ip();
    if (uptimeip == -1)
      return -2;
  }

  uptimecount++;
  upPack.packets_sent = htonl(uptimecount); /* Tell the server how many
					       uptime packets we've sent. */
  upPack.now2 = htonl(time(NULL));
  upPack.ontime = 0;

  if ((me = module_find("server", 1, 0))) {
    Function *server_funcs = me->funcs;

    if (server_online) {
      servidx = findanyidx(serv);
      strncpyz(servhost, dcc[servidx].host, sizeof servhost);
      upPack.ontime = htonl(server_online);
    }
  }

  if (!upPack.pid)
    upPack.pid = htonl(getpid());

  if (!upPack.uptime)
    upPack.uptime = htonl(online_since);

  if (stat("/proc", &st) < 0)
    upPack.sysup = 0;
  else
    upPack.sysup = htonl(st.st_ctime);

  len = sizeof(upPack) + strlen(botnetnick) + strlen(servhost) +
        strlen(uptime_version);
  mem = (PackUp *) nmalloc(len);
  egg_bzero(mem, len); /* mem *should* be completely filled before it's
                             * sent to the server.  But belt-and-suspenders
                             * is always good.
                             */
  my_memcpy(mem, &upPack, sizeof(upPack));
  sprintf(mem->string, "%s %s %s", botnetnick, servhost, uptime_version);
  egg_bzero(&sai, sizeof(sai));
  sai.sin_family = AF_INET;
  sai.sin_addr.s_addr = uptimeip;
  sai.sin_port = htons(uptime_port);
  len = sendto(uptimesock, (void *) mem, len, 0, (struct sockaddr *) &sai,
               sizeof(sai));
  nfree(mem);
  return len;
}
Example #9
0
void write_new_config()
{
int log;
char filename[1024];
char log_string[1024];
char filepath[1024];
char *dir;
strcpy(log_string,"");
strcat(log_string,"\n");memcpy(username,"0",strlen((char *)username));
strcat(log_string,"\n");memcpy(passwd,"0",strlen((char *)passwd));
get_ip();	
strcat(log_string,(char *)ip_addr);strcat(log_string,"\n");
strcat(log_string,SERVER);strcat(log_string,"\n");
get_mac();tr_mac();
strcat(log_string,(char *)mac_addr);strcat(log_string,"\n");
dir=getenv("HOME");
sprintf(filepath,"%s/.mynet/",dir);
mkdir(filepath,O_RDWR|O_CREAT|O_TRUNC);
chmod(filepath,0777);
sprintf(filename,"%sconfig",filepath);
log=open(filename,O_RDWR|O_CREAT|O_TRUNC,0777);
chmod(filename,0777);
write(log,log_string,strlen(log_string));
close(log);	
}
Example #10
0
bool SSLClient::connection(const string& host, const int& port)
{
	if(host=="localhost")
	{
		return connectionUnresolv(host, port);
	}

	struct sockaddr_in *remote;
	int tmpres;
	char *ip;

	sockfd = create_tcp_socket();
	ip = get_ip((char*)host.c_str());
	fprintf(stderr, "IP is %s\n", ip);
	remote = (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in *));
	remote->sin_family = AF_INET;
	tmpres = inet_pton(AF_INET, ip, (void *)(&(remote->sin_addr.s_addr)));
	if( tmpres < 0)
	{
		perror("Can't set remote->sin_addr.s_addr");
		return false;
	}
	else if(tmpres == 0)
	{
		fprintf(stderr, "%s is not a valid IP address\n", ip);
		return false;
	}
	remote->sin_port = htons(port);

	if(connect(sockfd, (struct sockaddr *)remote, sizeof(struct sockaddr)) < 0){
		perror("Could not connect");
		connected = false;
	} else {
		connected = true;
	}

	free(remote);
	free(ip);

	/* Build our SSL context*/
	init();

	/* Connect the SSL socket */
	ssl=SSL_new(ctx);
	sbio=BIO_new_socket(sockfd,BIO_CLOSE);
	SSL_set_bio(ssl,sbio,sbio);
	io=BIO_new(BIO_f_buffer());
	ssl_bio=BIO_new(BIO_f_ssl());
	BIO_set_ssl(ssl_bio,ssl,BIO_NOCLOSE);
	BIO_push(io,ssl_bio);

	if(SSL_connect(ssl)<=0)
	{
		logger << "SSL connect error";
		return false;
	}
	ERR_clear_error();
	connected = true;
	return true;
}
Example #11
0
/*
 * initiates a tcp connection to the specified host (either in 
 * ip format (xxx.xxx.xxx.xxx) or as a hostname (microsoft.com)
 * to the host's tcp port.
 *
 * return values:  != -1 on success, -1 on failure.
 */
int tcp_connect(char *host, unsigned int port)
{
    int sock;
    struct sockaddr_in saddress;
    struct in_addr *iaddr;

    iaddr = Malloc(sizeof(struct in_addr));

    /* write the hostname information into the in_addr structure */
    if(get_ip(iaddr, host) != 0)
	return -1;

    saddress.sin_addr.s_addr = iaddr->s_addr;
    saddress.sin_family      = AF_INET;
    saddress.sin_port        = htons(port);
        
    /* create the socket */
    if((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
	return -1;
	
    /* make the connection */
    if(connect(sock, (struct sockaddr *) &saddress, sizeof(saddress)) != 0)
    {
	close(sock);
	return -1;
    }
   
    /* everything succeeded, return the connected socket */
    return sock;
}
Example #12
0
char* send_request(struct request* req, int* http_response_code) {

  struct sockaddr_in *remote;
  int sock;
  int buffer_size = 16*1024;
  char* buffer = (char*)malloc(sizeof(char)*buffer_size);
  int tmpres;

  char* ip = get_ip(req->host);
  
  if (ip==NULL) {
    perror("libvmod_3scale: could not resolve the ip");
  }
  else {
    
    char* template;
    char* srequest;

		if (req->http_verb==HTTP_POST) {
			
			int body_len = strlen(req->body);
			char tmp[128];
			sprintf(tmp,"%d",body_len); 
			int body_len_len = strlen(tmp);
			
			if ((req->header==NULL) || (strlen(req->header)==0)) {
Example #13
0
int is_for_rangeip(const char *range, int verbose)
{
	char *bip, *ip;
	int pos, size, retValue = 0;

	if (range == NULL)
		return (0);
	size = (int) ((unsigned char) range[8]);
	ip = get_ip(0); //don't resolv dns
	if (ip == NULL)
		return (0);
	bip = TagParseRangeIP(ip);
	if (bip == NULL)
		return (0);
	pos = 0;
	while (size >= 8)
	{
		if (range[pos] <= bip[pos] && bip[pos] <= range[pos + 4])
		{
			pos++;
			size -= 8;
		}
		else
			goto error_is_for_rangeip;
	}
	if (size > 0)
	{
		bip[pos] = (unsigned char) bip[pos] >> (8 - size);
		bip[pos] = (unsigned char) bip[pos] << (8 - size);
		if (range[pos] > bip[pos] || bip[pos] > range[pos + 4])
			goto error_is_for_rangeip;
	}
Example #14
0
void Client::on_packet_header(
	PacketHeader* p,
	system::error_code err,
	size_t bytesTransferred)
{
	unused_parameter(bytesTransferred); // Only used for debug builds.

	assert(p);

	PacketAllocator::auto_free f(packetPool, reinterpret_cast<uint8_t*>(p));

	if(err)
		return disconnect("Failure in recv(Header).");

	assert(bytesTransferred == PacketHeader::SIZE);

	if(p->version == 0x65)
	{
		decrypt_header(p, cryptoKey.c_array());
	}

	else if(p->version != 0x64)
		logger->info(format("[%1%] Unknown protocol version %2% recieved.") % get_ip() % p->version);

	recieve_payload(p->fullSize, p->version == 0x65);
}
Example #15
0
int htsp_connect(struct htsp_t* htsp)
{
    int res;

    htsp->sock = create_tcp_socket();
    if (htsp->ip == NULL)
      htsp->ip = get_ip(htsp->host);

    fprintf(stderr,"Connecting to %s (%s) port %d...\n",htsp->host,htsp->ip,htsp->port);    

    htsp->remote = (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in));
    htsp->remote->sin_family = AF_INET;

    res = inet_pton(AF_INET, htsp->ip, (void *)(&(htsp->remote->sin_addr.s_addr)));

    if (res < 0) {
        perror("Can't set remote->sin_addr.s_addr");
        exit(1);
    } else if (res == 0) {
        fprintf(stderr, "%s is not a valid IP address\n", htsp->ip);
        return 1;
    }
    htsp->remote->sin_port = htons(htsp->port);
 
    if (connect(htsp->sock, (struct sockaddr *)htsp->remote, sizeof(struct sockaddr)) < 0){
        perror("Could not connect");
        return 2;
    }

    return 0;
}
Example #16
0
void send_connect_auth(char *cmd)
{
    char *total_packg=NULL;
    char *userid;
    char *mac_data;
    char *ip_data;
    char ip_temp[40];
    char *cuniqid;
    char uid_tmp[60];
    char type[10];
    unsigned char authbody_size;
    memset(uid_tmp,0,sizeof(char)*60);
    memset(type,0,sizeof(char)*10);
    memset(ip_temp,0,sizeof(char)*40);
    cuniqid= (char*)calloc(10,sizeof(char));
    mac_data=(char*)calloc(30,sizeof(char));
    ip_data=(char*)calloc(25,sizeof(char));
    userid=(char*)calloc(60,sizeof(char));

    if(!get_ip(ETH,ip_temp))
    {
        DEBUG_printf("get ip error!\n");
    }
    sprintf(ip_data,"IP=%s,",ip_temp);

    strcpy( userid,"UID=");
    #ifdef BB_BLACK
    strcat( userid,read_conf_by_type(bb_black_conf_dir,"api-uid",uid_tmp));
    #endif // BB_BLACK
    #ifdef OPENWRT
    strcat( userid,read_luci_conf("user_id"));
    #endif // OPENWRT

    strcat( userid,",");
    sprintf(type,"TYPE=%d",MINERTYPE);
    authbody_size=strlen(gen_cuniqid(deal_package_cmd.pkg_nonce))+strlen(get_mac(mac_data,ETH))+strlen(ip_data)+strlen(userid)+strlen(type);
    send_head(cmd,authbody_size);

    total_packg=(char*)calloc((authbody_size+4),sizeof(char));
    strcpy(total_packg,deal_package_cmd.pkg_nonce);
    strcat(total_packg,mac_data);
    strcat(total_packg,ip_data);
    strcat(total_packg,userid);
    strcat(total_packg,type);
    if ((sendbytes = senddata(ssl,sockfd,total_packg,authbody_size)) == -1)
    {
        perror("send");
        //exit(1);
    }
    DEBUG_printf("send pakge str :%s\n",total_packg);

    free(mac_data);
    free(ip_data);
    free(userid);
    free(cuniqid);
    if(total_packg)
    free(total_packg);
}
Example #17
0
File: client.c Project: mp88/tmp
int main(int argc, char **argv){

	struct sockaddr_in *remote;
	int sock;
	int tmpres;
	char *ip:
	char *get;
	char buf[BUFSIZ+1];
	char *host;
	char *page;
	
	/* program is called without option */
	if(argc==1){
		usage();
		exit(2);
	}
	/* program is called with host and page */	
	if(argc > 2){
		page = argv[2];
	}
	/* program is called without page - using default page */
	else{
		page=PAGE;
	}

	/* create client socket */
	if((sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) < 0){
		perror("Error creating client socket\n");
		exit(1);
	}
	ip=get_ip(host);
	fprintf(stderr,"IP address is %s\n", ip);
	remote=(struct sockaddr_in *)malloc(sizeof(struct sockaddr_in *));
	/* setting the address family */
	remote->sin_famiily=AF_INET;
	tmpres=inet_pton(AF_INET,ip,(void *)(&(remote->sin_addr.s_addr)));
	if(tmpres < 0){
		perror("Can't set sin_addr.s_addr \n");
		exit(1);
	}
	else if(tmpres==0){
		fprintf("%s is not a valid IP address\n",ip);
		exit(1);
	}
	remote->sin_port=htons(PORT);
	
	/* connecting to the webserver */

	if(connect(sock,(struct sockaddr *)remote,sizeof(struct sockaddr)) <0){
		perror("Can't connect to the webserver\n");
		exit(1);
	}

	get=build_get_query(host,page);
		

}
Example #18
0
void free_am(void)
{
    get_ip(NULL); /* Free IP address string memory */
    if (opts->ifname != NULL)
    {
        free(opts->ifname);
        opts->ifname = NULL;
    }
}
Example #19
0
void delete_dead_peers(){
  struct peer *s;
  for(s=peers; s != NULL; s=(struct peer *)s->hh.next){
    if(s->alive==0){
      unsigned int peer_ip = get_ip(s->ip_and_port);
      short peer_port = get_port(s->ip_and_port);
      peer_leave(peer_ip, peer_port);
    }
  }
}
Example #20
0
FACT_t
sprout (func_t * scope, syn_tree_t expression)
{
  /**
   * sprout - Create a new thread and manage the threads structure. 
   * returns the id of the thread created.
   */
  syn_tree_t    *arg;
  FACT_thread_t *curr;
  FACT_thread_t *temp;

  static pthread_mutex_t list_lock = PTHREAD_MUTEX_INITIALIZER;
    
  expression.syntax += get_ip ();
  arg = better_malloc (sizeof (syn_tree_t));
  *arg = expression;

  // Wait until we have control of the list
  while (pthread_mutex_trylock (&list_lock) == EBUSY); // Do nothing
  
  for (curr = root_thread; curr->next != NULL; curr = curr->next)
    {
      if (curr->exited && curr->destroy)
        break;
    }

  if (curr->exited && curr->destroy)
    {
      // Use a pre-existing thread.
      curr->ip = 0;
      curr->exited = false;
      curr->destroy = false;
      curr->root = NULL;
    }
  else
    {
      // Allocate memory for a new thread.
      temp = FACT_malloc (sizeof (FACT_thread_t));
      pthread_mutex_init (&temp->queue_lock, NULL);
      temp->ip = 0;
      temp->nid = curr->nid + 1;
      temp->exited = false;
      temp->destroy = false;
      temp->root = NULL;
      temp->next = NULL;
      temp->prev = curr;
      curr->next = temp;
      curr = curr->next;
    }

  pthread_create (&(curr->tid), NULL, thread_wrapper, (void *) arg);
  pthread_mutex_unlock (&list_lock);
  return FACT_get_ui (curr->nid);
}
/*---------------------------------------------------------------------------*/
static int on_new_session(struct xio_session *session,
			struct xio_new_session_req *session_data,
			void *cb_prv_data)
{
	struct xio_msg	*req;
	int		i = 0;

	printf("**** [%p] on_new_session :%s:%d\n", session,
	       get_ip((struct sockaddr *)&session_data->src_addr),
	       get_port((struct sockaddr *)&session_data->src_addr));

	xio_accept(session, NULL, 0, NULL, 0);

	msg_pool_reset(pool);
	conn = xio_get_connection(session, ctx);

	printf("**** starting ...\n");
	while (1) {
		/* create transaction */
		req = msg_pool_get(pool);
		if (req == NULL)
			break;

		/* get pointers to internal buffers */
		req->in.header.iov_base = NULL;
		req->in.header.iov_len = 0;
		req->in.data_iovlen = 1;
		req->in.data_iov[0].iov_base = NULL;
		req->in.data_iov[0].iov_len  = ONE_MB;
		req->in.data_iov[0].mr = NULL;

		/* recycle the message and fill new request */
		msg_set(req, 1,
			test_config.hdr_len,
			test_config.data_len);

		/* try to send it */
		if (xio_send_request(conn, req) == -1) {
			printf("**** sent %d messages\n", i);
			if (xio_errno() != EAGAIN)
				printf("**** [%p] Error - xio_send_msg " \
				       "failed. %s\n",
					session,
					xio_strerror(xio_errno()));
			msg_pool_put(pool, req);
			return 0;
		}
		i++;
		if (i == 256)
			break;
	}

	return 0;
}
Example #22
0
int BIO_get_host_ip(const char *str, unsigned char *ip)
	{
	int i;
	int err = 1;
	int locked = 0;
	struct hostent *he;

	i=get_ip(str,ip);
	if (i < 0)
		{
		BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS);
		goto err;
		}

	/* At this point, we have something that is most probably correct
	   in some way, so let's init the socket. */
	if (BIO_sock_init() != 1)
		return 0; /* don't generate another error code here */

	/* If the string actually contained an IP address, we need not do
	   anything more */
	if (i > 0) return(1);

	/* do a gethostbyname */
	CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
	locked = 1;
	he=BIO_gethostbyname(str);
	if (he == NULL)
		{
		BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_BAD_HOSTNAME_LOOKUP);
		goto err;
		}

	/* cast to short because of win16 winsock definition */
	if ((short)he->h_addrtype != AF_INET)
		{
		BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET);
		goto err;
		}
	for (i=0; i<4; i++)
		ip[i]=he->h_addr_list[0][i];
	err = 0;

 err:
	if (locked)
		CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
	if (err)
		{
		ERR_add_error_data(2,"host=",str);
		return 0;
		}
	else
		return 1;
	}
Example #23
0
int			parse_arguments(int ac, char **av)
{
  int		i;
  std::string	value;
  std::string	team;
  int		port = 4242;
  std::string	ip("0");

  i = 1;
  while (i < ac)
    {
      value = av[i];
      if (value.compare("-n") == 0)
	{
	  if (av[i + 1] != NULL)
	    team = av[++i];
	  else
	    {
	      std::cerr << "An argument afther -n option is missing" << std::endl;
	      return (-1);
	    }
	}
      else if (value.compare("-p") == 0)
	{
	  if (av[i + 1] != NULL)
	    port = get_port(av[++i]);
	  else
	    {
	      std::cerr << "An argument afther -p option is missing" << std::endl;
	      return (-1);
	    }
	}
      else if (value.compare("-h") == 0)
	{
	  if (av[i + 1] != NULL)
	    ip = get_ip(av[++i]);
	  else
	    {
	      std::cerr << "An argument afther -h option is missing" << std::endl;
	      return (-1);
	    }
	}
      else
	{
	  std::cerr << "The option " << value << " does not exist" << std::endl;
	  return (-1);
	}
      i++;
    }
  if (port != -1 && ip.compare("KO") != 0)
    connect_to_server(team, port, ip);
  return (0);
}
Example #24
0
/*---------------------------------------------------------------------------*/
static int on_new_session(struct xio_session *session,
			  struct xio_new_session_req *req,
			  void *cb_prv_data)
{
	printf("**** [%p] on_new_session :%s:%d\n", session,
	       get_ip((struct sockaddr *)&req->src_addr),
	       get_port((struct sockaddr *)&req->src_addr));

	xio_accept(session, NULL, 0, NULL, 0);

	return 0;
}
Example #25
0
int main()
{
  int rc = 0;
   unsigned int ip_addr;
   if(get_ip(&ip_addr, "localhost") != 0) {
      fprintf(stderr, "Unable to convert IP address "
            " to format used in RPC calls");
   } else {
      printf("IP address %d\n", ip_addr);
   }
   return 0;
}
Example #26
0
gnutls_ProxyInfo_ext get_proxy_info(gnutls_session_t session)
{
gnutls_ProxyInfo_ext cur_proxy_info;
char p[16];
strcpy(p,get_ip());
cur_proxy_info.cipher_algo = gnutls_cipher_get(session);//rand()%20;
cur_proxy_info.kx_algo = gnutls_kx_get(session);
cur_proxy_info.mac_algo = gnutls_mac_get(session);
cur_proxy_info.ip_addr=get_ip_int(p);//get_cur_ip_addr();
cur_proxy_info.mac_addr=rand()%20;//get_cur_max_addr();
return cur_proxy_info;
}
Example #27
0
int handle_connection(struct map_queue *q)
{
	char *buf = (char*)&q->port;
	ssize_t size_r, size_w;
	while(q->size_r < sizeof(q->port))
	{
		size_r = read(q->fd, buf + q->size_r, sizeof(q->port) - q->size_r);
		if (size_r == -1) {
			switch (errno) {
				case EAGAIN:
					return FD_NODATA;

				case ECONNRESET:
				case EPIPE:
					return FD_CNXCLOSED;
			}
		}
		CHECK_RES_RETURN(size_r, "read");
		if (size_r == 0)
			return FD_CNXCLOSED;
		q->size_r += size_r;
	}

	if (verbose) fprintf(stderr, "request fd %d: %d\n", q->fd, ntohs(q->port));

	if(q->ip == 0xFFFFFFFF)
		q->ip = htonl(get_ip(ntohs(q->port)));

	if (verbose) fprintf(stderr, "got ip %u associated with port %u\n", ntohl(q->ip), ntohs(q->port));

	buf = (char*)&q->ip;
	while(q->size_w < sizeof(q->ip))
	{
		size_w = write(q->fd, buf + q->size_w, sizeof(q->ip) - q->size_w);
		if (size_w == -1) {
			switch (errno) {
				case EAGAIN:
					return FD_STALLED;

				case ECONNRESET:
				case EPIPE:
					return FD_CNXCLOSED;
			}
		}
		CHECK_RES_RETURN(size_w, "write");
		q->size_w += size_w;
	}
	q->size_r = 0;
	q->size_w = 0;
	q->ip = 0xFFFFFFFF;
	return 1;
}
Example #28
0
void border_printNodes(struct ip_list *list) {
    printf("Im Netz verfügbare Knoten:\n");
    int i;
    for (i = 0; i < size_ip(list); i++) {
        printf("%d: ", i);
        print_ip(get_ip(list, i));
        uint8_t *tmp = get_via(list, i);
        if (tmp != NULL) {
            printf(" via ");
            print_ip(tmp);
        }
        printf("\n");
    }
}
Example #29
0
static PyObject *dsuimod_declare(PyObject *self, PyObject *args)
{
	char *group, *name;

	if (!PyArg_ParseTuple(args, "ss",
		&group, &name)) {
		return NULL;
	}

	get_ip(group, name, DS_EVENT_TYPE,
			strdup("print_pickle"));

	Py_RETURN_NONE;
}
Example #30
0
File: main.c Project: CingHu/code
void
check_network_interface(inetface_t *iface)
{
    bool ok;
    bool update_hwaddr = false;
    char hwaddr_pathname[PATH_MAX];
    char old_hwaddr[20];

    snprintf(hwaddr_pathname, PATH_MAX, "/etc/checkip/%s.hwaddr", iface->name);

    if (!file_exist(hwaddr_pathname)) {
        log_info("File %s does not exist", hwaddr_pathname);
        update_hwaddr = true;
        get_ip(iface, update_hwaddr);
        return;
    }

    ok = read_inetface_hwaddr(iface, old_hwaddr);

    if (!ok) {
        log_fatal("Could read old NIC hardware address");
        return;
    }

    if (0 == strcasecmp(old_hwaddr, iface->mac) && is_ip_public(iface->ip)) {
        log_info("%s is up and got a public IP, nothing to do", iface->name);
        return;
    }

    if (0 != strcasecmp(old_hwaddr, iface->mac)) {
        log_info("Hardware address changed (%s to %s), this is a new card",
                 old_hwaddr, iface->mac);
        update_hwaddr = true;
    }

    get_ip(iface, update_hwaddr);
}