Пример #1
0
static test_return_t binary_init_udp(memcached_st *memc)
{
    test_return_t test_rc;
    test_rc= pre_binary(memc);

    if (test_rc != TEST_SUCCESS)
        return test_rc;

    return init_udp(memc);
}
Пример #2
0
YJChat::YJChat(QWidget *parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);
	ui.m_tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
	m_client_to_server = new ClientToServer(this);
	//m_client_to_client = new ClientToClient(this);

	init_udp();
	init_connection();
}
Пример #3
0
/**
 * Main routine of the application
 */
int main(int argc, char **argv)
{
    struct device *dev = calloc(1, sizeof(struct device));

    if (system("clear") < 0)
        ERR("ERROR : COULD NOT CLEAR THE SCREEN\n");
    if (dev != NULL) {
        dev->ev_desc = init_device(argc, argv, dev);
        if (dev->ev_desc < 0) {
            ERR("ERROR : INIT DEVICE\n");
            return -1;
        }
    } else {
        ERR("ERROR : DEVICE ALLOCATION\n");
        return -1;
    }

    if (init_udp(dev->end_ip,
                 dev->host_port,
                 dev->target_port) < 0) {
        ERR("ERROR : INIT UDP SOCKET\n");
        return -1;
    }

    DBG("\n#*=*=*=*=*=*> DEVICE INFO <*=*=*=*=*=*#\n");
    DBG(" dev->job         = %s\n", dev->job?"TX":"RX");
    DBG(" dev->host_port   = %d\n", dev->host_port);
    DBG(" dev->target_port = %d\n", dev->target_port);
    DBG(" dev->end_ip      = %s\n", dev->end_ip);
    DBG(" dev->ev_dev      = %s\n", dev->ev_dev);
    DBG("#*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*#\n");
    switch (dev->job) {
    case DEVICE_JOB_TX:
        device_job_tx_loop(dev);
        break;
    case DEVICE_JOB_RX:
        device_job_rx_loop(dev);
        break;
    default:
        ERR("ERROR : UNKNOWN JOB\n");
        break;
    }
    close(dev->ev_desc);
    term_udp();
    free(dev);

    return 0;
}
Пример #4
0
/* TCPIP マネージャの初期化 
 */
ER
init_tcpip ()
{
  if (!initialized)
    {
      init_timer ();
      init_link ();
      init_ip ();
      init_udp ();
      init_tcp ();
      init_arp ();

      initialized = 1;
    }

  return (E_OK);
}
Пример #5
0
int main(int argc, char** argv){
    w=160; h=120;

    glutInit(&argc,argv); 
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
    glutCreateWindow("simple");
    glutDisplayFunc(display);
    glutIdleFunc(receiver);

    last = time(0);

    init_gl();
    init_udp(htons(12345));

    glutMainLoop();

    return 0;
}
Пример #6
0
void init_system (void) {
   /* Initialize configured interfaces and applications. */

#if ETH_ENABLE == 1
   init_eth_link ();
#endif
#if PPP_ENABLE == 1
   init_ppp_link ();
#endif
#if SLIP_ENABLE == 1
   init_slip_link ();
#endif

#if (IGMP_ENABLE & ETH_ENABLE) == 1
   init_igmp ();
#endif
#if UDP_ENABLE == 1
   init_udp ();
#endif
#if TCP_ENABLE == 1
   init_tcp ();
#endif
#if HTTP_ENABLE == 1
   init_http ();
#endif
#if TNET_ENABLE == 1
   init_tnet ();
#endif
#if TFTP_ENABLE == 1
   init_tftp ();
#endif
#if (NBNS_ENABLE & ETH_ENABLE) == 1
   init_nbns ();
#endif
#if (DHCP_ENABLE & ETH_ENABLE) == 1
   init_dhcp ();
#endif
#if DNS_ENABLE == 1
   init_dns ();
#endif
#if SMTP_ENABLE == 1
   init_smtp ();
#endif
}
Пример #7
0
Файл: log.c Проект: kuii/dfbNEON
DirectResult
direct_log_init( DirectLog  *log,
                 const char *param )
{
     switch (log->type) {
          case DLT_STDERR:
               return init_stderr( log );

          case DLT_FILE:
               return init_file( log, param );

          case DLT_UDP:
               return init_udp( log, param );

          default:
               break;
     }

     return DR_UNSUPPORTED;
}
Пример #8
0
DirectResult
direct_log_create( DirectLogType   type,
                   const char     *param,
                   DirectLog     **ret_log )
{
     DirectResult  ret = DR_INVARG;
     DirectLog    *log;

     log = D_CALLOC( 1, sizeof(DirectLog) );
     if (!log)
          return D_OOM();

     log->type = type;

     switch (type) {
          case DLT_STDERR:
               ret = init_stderr( log );
               break;

          case DLT_FILE:
               ret = init_file( log, param );
               break;

          case DLT_UDP:
               ret = init_udp( log, param );
               break;
     }

     if (ret)
          D_FREE( log );
     else {
          direct_util_recursive_pthread_mutex_init( &log->lock );

          D_MAGIC_SET( log, DirectLog );

          *ret_log = log;
     }

     return ret;
}
Пример #9
0
ClientToServer::ClientToServer(YJChat* parent):QObject(parent)
{
	m_parent = parent;
	init_udp();
	init_connection();
}
Пример #10
0
static int32_t
xmms_visualization_client_init_udp (xmms_visualization_t *vis, int32_t id, xmms_error_t *err)
{
	XMMS_DBG ("Trying to init udp!");
	return init_udp (vis, id, err);
}
Пример #11
0
/*
 * Daemonize and persist pid
 */
int
daemon_start()
{
    struct sigaction sig_action;
    sigset_t sig_set;
    pid_t otherpid;
    int curPID;
    pthread_t tcp4_thread, udp4_thread;
    pthread_t tcp6_thread, udp6_thread;

    /* Check if we can acquire the pid file */
    pfh = pidfile_open(NULL, 0600, &otherpid);

    if (pfh == NULL) {
        if (errno == EEXIST) {
            errx(EXIT_FAILURE, "Daemon already running, pid: %jd.", (intmax_t)otherpid);
        }
        err(EXIT_FAILURE, "Cannot open or create pidfile");
    }
    init_logger();

    /* Initialize TCP46 and UDP46 sockets */
    if (init_tcp() == EXIT_FAILURE)
        return (EXIT_FAILURE);
    if (init_udp() == EXIT_FAILURE)
        return (EXIT_FAILURE);

    /* start daemonizing */
    curPID = fork();

    switch (curPID) {
    case 0:			/* This process is the child */
        break;
    case -1:			/* fork() failed, should exit */
        perror("fork");
        return (EXIT_FAILURE);
    default:			/* fork() successful, should exit
					 * (parent) */
        return (EXIT_SUCCESS);
    }

    /* we are the child, complete the daemonization */

    /* Close standard IO */
    fclose(stdin);
    fclose(stdout);
    fclose(stderr);

    /* Block unnecessary signals */
    sigemptyset(&sig_set);
    sigaddset(&sig_set, SIGCHLD);	/* ignore child - i.e. we don't need
					 * to wait for it */
    sigaddset(&sig_set, SIGTSTP);	/* ignore tty stop signals */
    sigaddset(&sig_set, SIGTTOU);	/* ignore tty background writes */
    sigaddset(&sig_set, SIGTTIN);	/* ignore tty background reads */
    sigprocmask(SIG_BLOCK, &sig_set, NULL);	/* Block the above specified
						 * signals */

    /* Catch necessary signals */
    sig_action.sa_handler = signal_handler;
    sigemptyset(&sig_action.sa_mask);
    sig_action.sa_flags = 0;

    sigaction(SIGTERM, &sig_action, NULL);
    sigaction(SIGHUP, &sig_action, NULL);
    sigaction(SIGINT, &sig_action, NULL);

    /* create new session and process group */
    setsid();

    /* persist pid */
    pidfile_write(pfh);

    /* Create TCP and UDP listener threads */
    pthread_create(&tcp4_thread, NULL, tcp4_handler, NULL);
    pthread_create(&udp4_thread, NULL, udp4_handler, NULL);
#ifdef PF_INET6
    pthread_create(&tcp6_thread, NULL, tcp6_handler, NULL);
    pthread_create(&udp6_thread, NULL, udp6_handler, NULL);
#endif

    /*
     * Wait for threads to terminate, which normally shouldn't ever
     * happen
     */
    pthread_join(tcp4_thread, NULL);
    pthread_join(udp4_thread, NULL);
#ifdef PF_INET6
    pthread_join(tcp6_thread, NULL);
    pthread_join(udp6_thread, NULL);
#endif

    return (EXIT_SUCCESS);
}
Пример #12
0
void* external_command_thread(void* para)
{
	char *interface=(char*)para;
	int fd;
	char buf[MAXLEN];
	int l,n;
	int mode=0;

	printf("External IO Thread started, device %s\n",interface);

	if (!strncmp(interface, "rs232:",6)) {
		fd=init_rs232(interface);
	}
	else if (!strncmp(interface, "udp:",4)) {
		fd=init_udp(interface);
		mode=1;
	}
	else {
		// FIXME: udp&Co
		fprintf(stderr,"Unsupported interface type %s\n",interface);
		return NULL;
	}

	if (fd<0) {
		char err[256];
		strerror_r(errno,err,sizeof(err));
		fprintf(stderr,"Unable to open interface type %s (%s)\n",interface,err);
		return NULL;
	}

	l=0;

	while(1) {
		if (!mode) {
			// RS232

			n=read(fd,buf+l,1);

			if (n==1) {
				if (buf[l]=='\r' || buf[l]=='\n') {

					buf[l]=0;
					if (!external_send(buf))
						write(fd,"OK\n",3);
					else
						write(fd,"NAK\n",4);
					l=0;
				}
				else {
					if (l==MAXLEN-1)
						l=0;
					else
						l++;
				}
			}
			else
				usleep(40*1000);
		}
		else {
			char *p;
			n=read(fd,buf,MAXLEN-1);
			buf[MAXLEN-1]=0;
			// Only first line in packet
			p=strchr(buf,'\n');
			if (p)
				*p=0;
			external_send(buf);
		}
	}
	return NULL;
}
Пример #13
0
//this will be LinkLayerAbsInit when linked toghter with 6LowPan
int main(int argc, char **argv)
{
  int flags;			// Used to set non-blocking for stdin	

  int retval;
  ule6lo_status_t status;	// Used as result in many ule6lo lib calls
  ule6lo_IPEI_t ipei;
  ule6lo_macAddr_t mac;


  //Initialize test hooks
  ule6loTestIn_regRxHook(&test_rx);
  ule6loTestIn_regTxHook(&test_tx);

  // Setup stdin to operate non blocking
  flags = fcntl(0, F_GETFL, 0); 
  flags |= O_NONBLOCK; 
  fcntl(0, F_SETFL, flags);

  //Reset number of received bytes
  app_bytes_recv = 0;

  //Print instruction message
  printf("To send a message use this format and acknowledge with enter:\n<Destination ip> <Destination port> <message>\n");
  printf("Use port 3001 for now\n");

  // Debug print of contiki setup (defines etc)
  printContikiConfigurationInfo();



  printf("Args: <LBR IP> <LN port> <LN IPEI(mac addr style,example:00:00:00:00:01)> <Mac addr>\n");
  if(argc>=5)
  {
    status = ule6loGI_init();
    printf("ule6loGI_init() returned %i\n", status);

    // Initialize link layer
    sscanf(argv[3],"%2hhX:%2hhX:%2hhX:%2hhX:%2hhX",&(ipei.id[0]),&(ipei.id[1]),&(ipei.id[2]),&(ipei.id[3]),&(ipei.id[4]));
    sscanf(argv[4],"%2hhX:%2hhX:%2hhX:%2hhX:%2hhX:%2hhX",&(mac.u8[0]),&(mac.u8[1]),&(mac.u8[2]),&(mac.u8[3]),&(mac.u8[4]),&(mac.u8[5]));
    ule6loGI_setMacAddress(&mac);
    lla_init(argv[1],atoi(argv[2]),&ipei);

    printf("Using IP %s and port %i and IPEI %s and MAC addr %s\n",argv[1],atoi(argv[2]), argv[3], argv[4]);
  }
  else {
    printf("Incorrect number of arguments");
    return 1;
  }

  //Wait for connection
  while(ule6loGI_getStatus() != STATUS_SUCCESS) {
    sleep(1);
  }

  // Print our Link local address and our global address
  printLinkLocalAddress();
  printGloballAddress();

  //Create timer to print our IP addresses periodically
  stimer_set(&ipPrintTimer,10 );

  // Print all our IP addresses
  printIPAddresses();
  printIPV6Neighbourlist();


  init_udp();
  ule6lo_ip6addr_t loc_fipaddr2;
  memset(&loc_fipaddr2, 0x00, sizeof(loc_fipaddr2));
  loc_fipaddr2.u8[0] = 0xff;
  loc_fipaddr2.u8[1] = 0x02;
  loc_fipaddr2.u8[10] = 0x00;
  loc_fipaddr2.u8[11] = 0x00;
  loc_fipaddr2.u8[12] = 0x00;
  loc_fipaddr2.u8[13] = 0x01;
  loc_fipaddr2.u8[15] = 0x05;
  ule6loGI_addMulticastAddr(&loc_fipaddr2);
  // Run forever	
  while(1){
    // Check the stdin for data
	readCommandLine(app_res, app_buffer, app_bytes_recv);

    // Let link layer receive data is any is present
    llaProcess();

	debugPrint();

    // Allow the stack to run
    ule6loOS_processRun();
  }

  return 0;
}
Пример #14
0
void get_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet)
{
    const struct eap_header *eap_header
        = (struct eap_header *) (&packet[ETH_HLEN+AUTH_HLEN]);

    ehid = eap_header->eap_id;
    switch (eap_header->eap_code) {
        case EAP_CODE_REQUEST:
            switch (eap_header->eap_type) {
                case EAP_REQUEST_IDENTITY:
                    if (state == STARTED) {
                        fprintf(stdout, "Identification Received\n");
                        state = IDENTIFIED;
                        send_eap_packet(EAP_RESPONSE_IDENTITY);
                    }
                    else {
                        fprintf(stdout, "Warning: we haven't started\n");
                    }
                    return;
                case EAP_REQUEST_NOTIFICATION:
                /* got this packet if authentication failed or in use*/
                    fprintf(stdout, "Server Notification: %s\n",
                            packet+ETH_HLEN+AUTH_HLEN+EAP_HLEN);
                    send_eap_packet(EAP_RESPONSE_MD5_CHALLENGE);
                    return;
                case EAP_REQUEST_MD5_CHALLENGE:
                    state = AUTHED;
                    fprintf(stdout, "MD5 Challenge Received\n");

                    memcpy(md5_challenge,
                           packet+ETH_HLEN+AUTH_HLEN+EAP_HLEN+0x01,
                           0x10);
                    md5digest();

                    send_eap_packet(EAP_RESPONSE_MD5_CHALLENGE);
                    return;
            }
        case EAP_CODE_SUCCESS:
            state = ONLINE;
            fprintf(stdout, "Login Successfully\n");
            if ( system(dhclientcmd) == -1 ) {
                fprintf(stderr, "Error while executing dhclient\n");
                error_handle(-2);
            }
            dhcp = 1;
            get_ip();
            if ( init_udp() == -1) {
                error_handle(-2);
            }
            init_daemon();
            alarm(31);
            return;
        case EAP_CODE_FAILURE:
            if ( state == ONLINE || state == AUTHED) {
                fprintf(stdout, "Logout\n");
                pcap_breakloop(handle);
            }
            return;
    }
    fprintf(stderr, "FATAL: Unknown packet[eap_code(%02x), eap_id(%02x), eap_type(%02x)]\n", eap_header->eap_code, eap_header->eap_id, eap_header->eap_type);
    fprintf(stderr, "Waring: I won't respond to this unknown packet\n");
    return;
}
Пример #15
0
int qtrun(struct qtproto* p) {
	if (getconf("DEBUG")) debug = 1;
	struct qtsession session;
	session.poll_timeout = -1;
	session.protocol = *p;

	if (init_udp(&session) < 0) return -1;
	int sfd = session.fd_socket;

	session.sendnetworkpacket = qtsendnetworkpacket;

	if (init_tuntap(&session) < 0) return -1;
	int ttfd = session.fd_dev;

	char protocol_data[p->protocol_data_size];
	memset(protocol_data, 0, p->protocol_data_size);
	session.protocol_data = &protocol_data;
	if (p->init && p->init(&session) < 0) return -1;

	if (drop_privileges() < 0) return -1;

	fprintf(stderr, "The tunnel is now operational!\n");

	struct pollfd fds[2];
	fds[0].fd = ttfd;
	fds[0].events = POLLIN;
	fds[1].fd = sfd;
	fds[1].events = POLLIN;

	int pi_length = 0;
	if (session.use_pi == 2) pi_length = 4;

	char buffer_raw_a[p->buffersize_raw + pi_length];
	char buffer_enc_a[p->buffersize_enc];
	char* buffer_raw = buffer_raw_a;
	char* buffer_enc = buffer_enc_a;

	while (1) {
		int len = poll(fds, 2, session.poll_timeout);
		if (len < 0) return errorexitp("poll error");
		else if (fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) return errorexit("poll error on tap device");
		else if (fds[1].revents & (POLLHUP | POLLNVAL)) return errorexit("poll error on udp socket");
		if (len == 0 && p->idle) p->idle(&session);
		if (fds[0].revents & POLLIN) {
			len = read(ttfd, buffer_raw + p->offset_raw, p->buffersize_raw + pi_length);
			if (len < pi_length) errorexit("read packet smaller than header from tun device");
			if (session.remote_float == 0 || session.remote_float == 2) {
				len = p->encode(&session, buffer_raw + pi_length, buffer_enc, len - pi_length);
				if (len < 0) return len;
				if (len == 0) continue; //encoding is not yet possible
				qtsendnetworkpacket(&session, buffer_enc + p->offset_enc, len);
			}
		}
		if (fds[1].revents & POLLERR) {
			int out;
			len = sizeof(out);
			getsockopt(sfd, SOL_SOCKET, SO_ERROR, &out, &len);
			fprintf(stderr, "Received error %d on udp socket\n", out);
		}
		if (fds[1].revents & POLLIN) {
			sockaddr_any recvaddr;
			socklen_t recvaddr_len = sizeof(recvaddr);
			if (session.remote_float == 0) {
			 	len = read(sfd, buffer_enc + p->offset_enc, p->buffersize_enc);
			} else {
				len = recvfrom(sfd, buffer_enc + p->offset_enc, p->buffersize_enc, 0, (struct sockaddr*)&recvaddr, &recvaddr_len);
			}
			if (len < 0) {
				long long out;
				len = sizeof(out);
				getsockopt(sfd, SOL_SOCKET, SO_ERROR, &out, &len);
				fprintf(stderr, "Received end of file on udp socket (error %lld)\n", out);
			} else {
				len = p->decode(&session, buffer_enc, buffer_raw + pi_length, len);
				if (len < 0) continue;
				if (session.remote_float != 0 && !sockaddr_equal(&session.remote_addr, &recvaddr)) {
					char epname[INET6_ADDRSTRLEN + 1 + 2 + 1 + 5]; //addr%scope:port
					sockaddr_to_string(&recvaddr, epname, sizeof(epname));
					fprintf(stderr, "Remote endpoint has changed to %s\n", epname);
					session.remote_addr = recvaddr;
					session.remote_float = 2;
				}
				if (len > 0 && session.use_pi == 2) {
					int ipver = (buffer_raw[p->offset_raw + pi_length] >> 4) & 0xf;
					int pihdr = 0;
#if defined linux
					if (ipver == 4) pihdr = 0x0000 | (0x0008 << 16); //little endian: flags and protocol are swapped
					else if (ipver == 6) pihdr = 0x0000 | (0xdd86 << 16);
#else
					if (ipver == 4) pihdr = htonl(AF_INET);
					else if (ipver == 6) pihdr = htonl(AF_INET6);
#endif
					*(int*)(buffer_raw + p->offset_raw) = pihdr;
				}
				if (len > 0) write(ttfd, buffer_raw + p->offset_raw, len + pi_length);
			}
		}