int main(int argc, char* argv[]) { schd = create_scheduler(); initialize_scheduler(schd, NULL); session_1 = create_session(); initialize_session(session_1, "222.214.218.237", 6601, "1299880", 0); set_session_index(session_1, 0); add_session(schd, session_1); session_2 = create_session(); initialize_session(session_2, "222.214.218.237", 6601, "1299880", 1); set_session_index(session_2, 1); add_session(schd, session_2); set_surface_mode(schd->surface, mode_2); scheduler_start(schd); session_start(session_1); session_start(session_2); scheduler_wait(schd); session_stop(session_1); session_stop(session_2); destroy_session(session_1); destroy_session(session_2); return 0; }
bool server_start(int port) { bool success = _create_socket(port) && _bind_to_socket(port) && _listen_on_socket(); if (!success){ _close_socket(); return false; } log_trace("Accepting connections on port %d", port); while(success){ int acceptedfd; success = _accept_on_socket(&acceptedfd); if (success){ session_start(acceptedfd); } else{ break; } } log_print(LOG_INFO, "Stopped accepting connections on port %d", port); _close_socket(); return true; }
int p_session_start( /* + */ value v_session, type t_session, /* + */ value v_username, type t_username, /* + */ value v_host, type t_host, /* + */ value v_password, type t_password, /* + */ value v_opts, type t_opts ) { session_t * session; Get_Typed_Object(v_session,t_session,&session_handle_tid,session); Check_String(t_username); Check_String(t_host); Check_String(t_password); Check_Structure(t_opts); if ( session_start( session, StringStart(v_username), StringStart(v_host), StringStart(v_password), v_opts) ) Bip_Error(dbi_errno); Succeed; }
int session_mgr_new_session(session_mgr_t *mgr, session_param_t *param) { if (mgr == NULL || param == NULL) { LOG_ERROR("Invalid session mgr or param"); return ZISS_ERROR; } session_t *session = NULL; if (session_new(&session, param) == ZISS_ERROR) { LOG_ERROR("Fail to new session"); return ZISS_ERROR; } if (session_start(session) == ZISS_ERROR) { LOG_ERROR("Fail to start session"); return ZISS_ERROR; } if (mgr->session_list == NULL) { mgr->session_list = session; } else { session_t *tail = mgr->session_list; while (tail->next != NULL) tail = tail->next; tail->next = session; } return ZISS_OK; }
int main(int ac, char **av, char **env) { t_sess server; pid_t child; if (ac != 2) usage(av[0]); init_all(&server, atoi(av[1])); while (77) { server.client.sock = accept(server.sock, \ (struct sockaddr*)&server.client.csin, &server.client.cslen); child = secure_fork(); if (child == 0) { server.client.ip = inet_ntoa(server.client.csin.sin_addr); display_hour(); printf("\nConnection from : %s\n", server.client.ip); session_start(server.dir_root, &server); } } close(server.client.sock); close(server.sock); return (0); }
int brainfuck_make_asm(FILE *_output, FILE *_input, output_t _type, size_t stacksize) { output = _output; input = _input; type = _type; assert(type != NONE); assert(stacksize > 0); /* Create header */ session_start(); define_put(); define_get(); define_start(stacksize); /* Transpile brainfuck to asm */ memset(stack, 0, TRANSPILER_STACK_SIZE); ptr = 0; int queued_op = 0; int num_queued = 0; int op; while ((op = fgetc(input)) != EOF) { if (strchr(".,+-><[]", op) == NULL) continue; if (queued_op != 0) { if (queued_op == op) { ++num_queued; continue; } handle_queued_ops(queued_op, num_queued); queued_op = 0; num_queued = 0; } switch (op) { case '.': op_put(); break; case ',': op_get(); break; case '+': /* FALLTHROUGH */ case '-': /* FALLTHROUGH */ case '>': /* FALLTHROUGH */ case '<': queued_op = op; num_queued = 1; break; case '[': op_tag(stack, ptr); break; case ']': op_jmp(stack, ptr); break; } } handle_queued_ops(queued_op, num_queued); /* Create clean exit */ define_exit(); return 0; }
static void regular_main(void) { puts("Accepting sessions on serial link."); /* Open the session for the serial control. */ session_start(); while(1) { kloader_service_essential_kmsg(); serial_service(); } }
int main(void) { setlocale(LC_CTYPE, ""); const char *config_file = "avm-motion-trigger.conf"; struct config c = get_config(config_file); char *session_id = session_start(c.avm.hostname, c.avm.username, c.avm.password); size_t max_ains = 32; char* ains[max_ains]; int found = switches_list(c.avm.hostname, session_id, ains, max_ains); if (0 == found) { printf(" * No switches found!\n"); } else { for(short i = 0; i < found; i++) { char *name = switch_name(c.avm.hostname, session_id, ains[i]); printf(" * Found: %s\n", ains[i]); printf(" * Name: %s\n", name); if (SWITCH_PRESENT == switch_present(c.avm.hostname, session_id, ains[i])) { printf(" * Present: yes (connected)\n"); } else { printf(" * Present: no (not connected)\n"); } if (SWITCH_STATE_ON == switch_state(c.avm.hostname, session_id, ains[i])) { printf(" * State: on\n"); } else { printf(" * State: off\n"); } if (i < found-1) { printf("\n"); } free(name); free(ains[i]); } } session_end(c.avm.hostname, session_id); free_config(&c); return 0; }
static void reset_serial_session(int signal) { int i; session_end(); if(signal) { /* Signal end-of-session inband with zero length packet. */ for(i=0;i<4;i++) uart_write(0x5a); for(i=0;i<4;i++) uart_write(0x00); } session_start(); }
int login(struct config *c) { if (NULL == session_id) { session_id = session_start(c->avm.hostname, c->avm.username, c->avm.password); if (SESSION_INVALID == session_id_chk(session_id)) { utlog(LOG_ERR, "%s\n%s %s\n", "Failed to login while starting a session.", "Maybe the username/password is wrong or could not contact the", "FRITZ!Box.\n"); free(session_id); session_id = NULL; return 1; } } return 0; }
int32_t _assign_direct( struct iolayer * layer, uint8_t index, evsets_t sets, struct task_assign * task ) { int32_t rc = 0; void * local = NULL; struct session_manager * manager = _get_manager( layer, index ); if ( layer->localfunc != NULL ) { local = layer->localfunc( layer->localdata, index ); } // 会话管理器分配会话 struct session * session = session_manager_alloc( manager ); if ( unlikely( session == NULL ) ) { syslog(LOG_WARNING, "%s(fd:%d, host:'%s', port:%d) failed .", __FUNCTION__, task->fd, task->host, task->port ); close( task->fd ); return -1; } // 回调逻辑层, 确定是否接收这个会话 rc = task->cb( task->context, local, session->id, task->host, task->port ); if ( rc != 0 ) { // 逻辑层不接受这个会话 session_manager_remove( manager, session ); close( task->fd ); return 1; } session_set_iolayer( session, layer ); session_set_endpoint( session, task->host, task->port ); session_start( session, eSessionType_Once, task->fd, sets ); return 0; }
int cgiMain() { int result; #ifdef DEBUG fprintf(stderr, "========== LED.CGI Start ===========.\n"); #endif // 初始化 session session_start(g_session_datadir); do { if (session_get("USERNAME") != NULL) { if (strcmp(session_get("USERNAME"), g_login_username) == 0) { result = control_process(); break; } } result = login_process(); } while (0); #ifdef DEBUG fprintf(cgiOut, "========== LED.CGI End ===========.\n"); #endif return result; }
void DEFAULT_CC scp_v1_process(struct SCP_CONNECTION *c, struct SCP_SESSION *s) { long data; int display; int retries; int current_try; enum SCP_SERVER_STATES_E e; struct SCP_DISCONNECTED_SESSION *slist; struct session_item *sitem; int scount; SCP_SID sid; retries = g_cfg->sec.login_retry; current_try = retries; data = auth_userpass(s->username, s->password); /*LOG_DBG("user: %s\npass: %s", s->username, s->password);*/ while ((!data) && ((retries == 0) || (current_try > 0))) { LOG_DBG("data %d - retry %d - currenttry %d - expr %d", data, retries, current_try, ((!data) && ((retries == 0) || (current_try > 0)))); e = scp_v1s_request_password(c, s, "Wrong username and/or password"); switch (e) { case SCP_SERVER_STATE_OK: /* all ok, we got new username and password */ data = auth_userpass(s->username, s->password); /* one try less */ if (current_try > 0) { current_try--; } break; default: /* we check the other errors */ parseCommonStates(e, "scp_v1s_list_sessions()"); scp_session_destroy(s); return; //break; } } if (!data) { scp_v1s_deny_connection(c, "Login failed"); log_message( LOG_LEVEL_INFO, "Login failed for user %s. Connection terminated", s->username); scp_session_destroy(s); return; } /* testing if login is allowed*/ if (0 == access_login_allowed(s->username)) { scp_v1s_deny_connection(c, "Access to Terminal Server not allowed."); log_message(LOG_LEVEL_INFO, "User %s not allowed on TS. Connection terminated", s->username); scp_session_destroy(s); return; } //check if we need password change /* list disconnected sessions */ slist = session_get_byuser(s->username, &scount, SESMAN_SESSION_STATUS_DISCONNECTED); if (scount == 0) { /* no disconnected sessions - start a new one */ log_message(LOG_LEVEL_DEBUG, "No disconnected sessions for this user" "- we create a new one"); if (0 != s->client_ip) { log_message(LOG_LEVEL_INFO, "++ created session (access granted): username %s, ip %s", s->username, s->client_ip); } else { log_message(LOG_LEVEL_INFO, "++ created session (access granted): username %s", s->username); } if (SCP_SESSION_TYPE_XVNC == s->type) { log_message(LOG_LEVEL_INFO, "starting Xvnc session..."); display = session_start(s->width, s->height, s->bpp, s->username, s->password, data, SESMAN_SESSION_TYPE_XVNC, s->domain, s->program, s->directory, s->client_ip); } else { log_message(LOG_LEVEL_INFO, "starting X11rdp session..."); display = session_start(s->width, s->height, s->bpp, s->username, s->password, data, SESMAN_SESSION_TYPE_XRDP, s->domain, s->program, s->directory, s->client_ip); } e = scp_v1s_connect_new_session(c, display); switch (e) { case SCP_SERVER_STATE_OK: /* all ok, we got new username and password */ break; default: /* we check the other errors */ parseCommonStates(e, "scp_v1s_connect_new_session()"); break; } } else { /* one or more disconnected sessions - listing */ e = scp_v1s_list_sessions(c, scount, slist, &sid); switch (e) { /*case SCP_SERVER_STATE_FORCE_NEW:*/ /* we should check for MaxSessions */ case SCP_SERVER_STATE_SELECTION_CANCEL: log_message( LOG_LEVEL_INFO, "Connection cancelled after session listing"); break; case SCP_SERVER_STATE_OK: /* ok, reconnecting... */ sitem = session_get_bypid(sid); if (0 == sitem) { e = scp_v1s_connection_error(c, "Internal error"); log_message(LOG_LEVEL_INFO, "Cannot find session item on the chain"); } else { display = sitem->display; /*e=scp_v1s_reconnect_session(c, sitem, display);*/ e = scp_v1s_reconnect_session(c, display); if (0 != s->client_ip) { log_message(LOG_LEVEL_INFO, "++ reconnected session: username %s, display :%d.0, session_pid %d, ip %s", s->username, display, sitem->pid, s->client_ip); } else { log_message(LOG_LEVEL_INFO, "++ reconnected session: username %s, display :%d.0, session_pid %d", s->username, display, sitem->pid); } g_free(sitem); } break; default: /* we check the other errors */ parseCommonStates(e, "scp_v1s_list_sessions()"); break; } g_free(slist); } /* resource management */ if ((e == SCP_SERVER_STATE_OK) && (s->rsr)) { /* here goes scp resource sharing code */ } /* cleanup */ scp_session_destroy(s); auth_end(data); }
void DEFAULT_CC scp_v0_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s) { int display = 0; tbus data; struct session_item* s_item; tc_mutex_lock(session_creation_lock); data = auth_userpass(NULL, s->username, s->password); #ifdef CHECK_PREMIUM_EDITION bool valid = true; if (get_module_version(get_module_name()) & PREMIUM_EDITION) { printf("%s %i %i %i \n", __FUNCTION__, g_time3(), last_time_premium_edition_check, CHECK_INTERVAL); if (((g_time3() - last_time_premium_edition_check) > CHECK_INTERVAL) || last_time_premium_edition_check == 0) { printf("%s FOFOFOOF\n", __FUNCTION__); valid = check_premium_edition(); } } if (!valid) { data = 0; scp_v0s_deny_connection(c, "Unable to launch the session\nInvalid License\nPlease contact your administrator\n"); tc_mutex_unlock(session_creation_lock); return; } #endif if (data == 0) { log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "User %s failed to authenticate", s->username); scp_v0s_deny_connection(c, "Your username or \nyour password is invalid"); tc_mutex_unlock(session_creation_lock); return; } lock_chain_acquire(); s_item = session_get_bydata(s->username); lock_chain_release(); if (s_item != 0) { log_message(&(g_cfg->log), LOG_LEVEL_INFO, "A session for User %s already exist", s->username); display = s_item->display; if (s_item->status == SESMAN_SESSION_STATUS_TO_DESTROY) { log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "Session for user %s is in destroy, unable to initialize a new session", s->username); scp_v0s_deny_connection(c, "Your last session is currently \nended, retry later"); } else { session_update_status_by_user(s_item->name, SESMAN_SESSION_STATUS_ACTIVE); log_message(&(g_cfg->log), LOG_LEVEL_INFO, "switch from status DISCONNECTED to ACTIVE"); session_switch_resolution(s->width, s->height, display); session_add_client_pid(s_item->name, s->client_pid); scp_v0s_allow_connection(c, display); } auth_end(data); tc_mutex_unlock(session_creation_lock); return; } log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "No session already started for the user %s", s->username); if (access_login_allowed(s->username) == 0) { log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "User %s is not allow to start session", s->username); display = 0; scp_v0s_deny_connection(c, "You are not allowed\nto start a session\n"); auth_end(data); tc_mutex_unlock(session_creation_lock); return; } log_message(&(g_cfg->log), LOG_LEVEL_INFO, "granted TS access to user %s", s->username); if (SCP_SESSION_TYPE_XVNC == s->type) { log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting Xvnc session for the user %s ...", s->username); display = session_start(s->width, s->height, s->bpp, s->username, s->password, data, SESMAN_SESSION_TYPE_XVNC, s->domain, s->program, s->directory, s->keylayout, s->client_pid, s->use_scim); } else { log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting X11rdp session for the user %s ...", s->username); display = session_start(s->width, s->height, s->bpp, s->username, s->password, data, SESMAN_SESSION_TYPE_XRDP, s->domain, s->program, s->directory, s->keylayout, s->client_pid, s->use_scim); } auth_end(data); if (display == 0) { data = 0; scp_v0s_deny_connection(c, "Unable to launch the session\nPlease contact\nyour administrator\n"); } else { scp_v0s_allow_connection(c, display); } tc_mutex_unlock(session_creation_lock); }
void DEFAULT_CC scp_v0_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s) { int display = 0; tbus data; struct session_item* s_item; data = auth_userpass(s->username, s->password); if (data) { s_item = session_get_bydata(s->username, s->width, s->height, s->bpp, s->type); if (s_item != 0) { display = s_item->display; if (0 != s->client_ip) { log_message(&(g_cfg->log), LOG_LEVEL_INFO, "++ reconnected session: username %s, display :%d.0, session_pid %d, ip %s", s->username, display, s_item->pid, s->client_ip); } else { log_message(&(g_cfg->log), LOG_LEVEL_INFO, "++ reconnected session: username %s, display :%d.0, session_pid %d", s->username, display, s_item->pid); } auth_end(data); /* don't set data to null here */ } else { LOG_DBG(&(g_cfg->log), "pre auth"); if (1 == access_login_allowed(s->username)) { if (0 != s->client_ip) { log_message(&(g_cfg->log), LOG_LEVEL_INFO, "++ created session (access granted): username %s, ip %s", s->username, s->client_ip); } else { log_message(&(g_cfg->log), LOG_LEVEL_INFO, "++ created session (access granted): username %s", s->username); } if (SCP_SESSION_TYPE_XVNC == s->type) { log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting Xvnc session..."); display = session_start(s->width, s->height, s->bpp, s->username, s->password, data, SESMAN_SESSION_TYPE_XVNC, s->domain, s->program, s->directory, s->client_ip); } else { log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting X11rdp session..."); display = session_start(s->width, s->height, s->bpp, s->username, s->password, data, SESMAN_SESSION_TYPE_XRDP, s->domain, s->program, s->directory, s->client_ip); } } else { display = 0; } } if (display == 0) { auth_end(data); scp_v0s_deny_connection(c); } else { scp_v0s_allow_connection(c, display); } } else { scp_v0s_deny_connection(c); } }
void DEFAULT_CC scp_v0_process(struct SCP_CONNECTION *c, struct SCP_SESSION *s) { int display = 0; tbus data; struct session_item *s_item; int errorcode = 0 ; data = auth_userpass(s->username, s->password,&errorcode); if (s->type == SCP_GW_AUTHENTICATION) { /* this is just authentication in a gateway situation */ /* g_writeln("SCP_GW_AUTHENTICATION message received"); */ if (data) { if (1 == access_login_allowed(s->username)) { /* the user is member of the correct groups. */ scp_v0s_replyauthentication(c, errorcode); log_message(LOG_LEVEL_INFO, "Access permitted for user: %s", s->username); /* g_writeln("Connection allowed"); */ } else { scp_v0s_replyauthentication(c, 32+3); /* all first 32 are reserved for PAM errors */ log_message(LOG_LEVEL_INFO, "Username okey but group problem for " "user: %s", s->username); /* g_writeln("user password ok, but group problem"); */ } } else { /* g_writeln("username or password error"); */ log_message(LOG_LEVEL_INFO, "Username or password error for user: %s", s->username); scp_v0s_replyauthentication(c, errorcode); } auth_end(data); } else if (data) { s_item = session_get_bydata(s->username, s->width, s->height, s->bpp, s->type); if (s_item != 0) { display = s_item->display; if (0 != s->client_ip) { log_message( LOG_LEVEL_INFO, "++ reconnected session: username %s, " "display :%d.0, session_pid %d, ip %s", s->username, display, s_item->pid, s->client_ip); } else { log_message(LOG_LEVEL_INFO, "++ reconnected session: username %s, " "display :%d.0, session_pid %d", s->username, display, s_item->pid); } session_reconnect(display, s->username); auth_end(data); /* don't set data to null here */ } else { LOG_DBG("pre auth"); if (1 == access_login_allowed(s->username)) { if (0 != s->client_ip) { log_message(LOG_LEVEL_INFO, "++ created session (access granted): " "username %s, ip %s", s->username, s->client_ip); } else { log_message(LOG_LEVEL_INFO, "++ created session (access granted): " "username %s", s->username); } if (SCP_SESSION_TYPE_XVNC == s->type) { log_message( LOG_LEVEL_INFO, "starting Xvnc session..."); display = session_start(s->width, s->height, s->bpp, s->username, s->password, data, SESMAN_SESSION_TYPE_XVNC, s->domain, s->program, s->directory, s->client_ip); } else { log_message(LOG_LEVEL_INFO, "starting X11rdp session..."); display = session_start(s->width, s->height, s->bpp, s->username, s->password, data, SESMAN_SESSION_TYPE_XRDP, s->domain, s->program, s->directory, s->client_ip); } } else { display = 0; } } if (display == 0) { auth_end(data); scp_v0s_deny_connection(c); } else { scp_v0s_allow_connection(c, display); } } else { scp_v0s_deny_connection(c); } }
void session_report(struct session * s, char type){ if(s->need_report==0){ return; } s->need_report = 0; struct msg_report rp; rp.buffer = msgpack_sbuffer_new(); rp.pk = msgpack_packer_new(rp.buffer, msgpack_sbuffer_write); rp.count = 0; // 15 < keys < 65535 // https://github.com/msgpack/msgpack/blob/master/spec.md#formats-map // +--------+--------+--------+~~~~~~~~~~~~~~~~~+ // | 0xde |YYYYYYYY|YYYYYYYY| N*2 objects | // +--------+--------+--------+~~~~~~~~~~~~~~~~~+ msgpack_pack_map(rp.pk, 20); report_add_pair(&rp, "@class", "http-scope"); report_add_pair_int(&rp, "@time", s->start_time); report_add_pair(&rp, "method", http_method_str(s->method)); report_add_pair(&rp, "host", s->host); report_add_pair(&rp, "host", s->host); report_add_pair(&rp, "path", s->path); report_add_pair(&rp, "node", config.node); report_add_pair_int(&rp, "code", s->status_code); //print_data(rp.buffer->data, rp.buffer->size); report_add_pair(&rp, "server", int_ntoa(s->tcp->addr.daddr)); report_add_pair_int(&rp, "server-port", s->tcp->addr.dest); report_add_pair(&rp, "client", int_ntoa(s->tcp->addr.saddr)); // report_add_pair_int(&rp, "loat_packet", s->lost_packets); // report_add_pair_int(&rp, "total_packets", s->packets); // /* report_add_packet_int(&rp, "packets", "%d/%d",s->lost_packets, s->packets);*/ report_add_pair(&rp, "status", close_status(type)); report_add_pair_int(&rp, "req-bytes", s->tcp->server.count); report_add_pair_int(&rp, "rep-bytes", s->tcp->client.count); report_add_pair_float(&rp, "net-req-time", s->req_time/1000000.0); report_add_pair_float(&rp, "server-time", s->server_time/1000000.0); report_add_pair_float(&rp, "net-rep-time", s->rep_time/1000000.0); if(s->referer){ report_add_pair(&rp, "referer", s->referer); char * referer_host = strstr(s->referer, "//"); if(referer_host){ referer_host+=2; char *p = strstr(referer_host, "/"); if(p) *p = 0; report_add_pair(&rp, "referer-host", referer_host); } } struct kv *p = s->proplist; while(p){ urldecode(p->value); report_add_pair(&rp, kv_type_string(p->type, p->key), p->value); p = p->next; } if(s->is_catch_response_body && s->response_body_size<65535){ report_add_pair_int(&rp, "body-captured-size", s->response_body_size); report_add_key(&rp, "body-captured"); msgpack_pack_raw(rp.pk, s->response_body_size); struct body_buf *b = s->response_body_first; int size_pushed = 0; while(b){ msgpack_pack_raw_body(rp.pk, b->data, b->size); size_pushed += b->size; b = b->next; } } //print_data(rp.buffer->data, rp.buffer->size); char *cp = rp.buffer->data; cp = cp + 1; *cp = rp.count >> 8; cp = cp + 1; *cp = rp.count % 256; //printf("rp.buffer->size=%d\n", rp.count); rp.routing_key = malloc(ROUTING_KEY_BUF_SIZE); bzero(rp.routing_key, ROUTING_KEY_BUF_SIZE); snprintf(rp.routing_key, ROUTING_KEY_BUF_SIZE, "http-scope.%s.%dxx.%d", s->host, s->status_code / 100 ,s->status_code); send_report(&rp); //print_data(rp.buffer->data, rp.buffer->size); free(rp.routing_key); msgpack_sbuffer_free(rp.buffer); msgpack_packer_free(rp.pk); session_log(s); session_clean(s); session_start(s); }
static void global_cb(EV_P_ ev_io *w, int revents) { global_context *gc = (global_context *)w->data; static int count = 0; int ret = 0; struct sockaddr_storage local_addr; socklen_t local_addr_size = sizeof(local_addr); log_debug("global_cb fds: %d,%d revents: 0x%02x count: %d", w->fd, gc->listen_fd.fd, revents, count); count++; ret = getsockname(gc->listen_fd.fd, (struct sockaddr *)&local_addr, &local_addr_size); if (ret < 0) { log_error("getsockname() failed errno=%d", ret, errno); return; } /* Read all the incoming packets waiting on listen_fd, and create a session for each one */ for (;;) { mbedtls_net_context client_fd; session_context *sc; struct sockaddr_storage client_addr; socklen_t client_addr_size = sizeof(client_addr); unsigned char first_packet[MBEDTLS_SSL_MAX_CONTENT_LEN]; size_t first_packet_len = 0; ret = recvfrom(gc->listen_fd.fd, first_packet, sizeof(first_packet), 0, (struct sockaddr *)&client_addr, &client_addr_size); if (ret < 0) { int save_errno = errno; if ((save_errno == EAGAIN) || (save_errno == EWOULDBLOCK)) { /* We finished reading everything that was available so far */ return; } log_error("recvfrom failed on listening socket (fd=%d), errno=%d", gc->listen_fd.fd, save_errno); return; } else if (ret == 0) { log_error("recvfrom() returned 0, this shouldn't happen"); continue; } first_packet_len = ret; /* We have a new client! Connect the client_fd socket to that peer */ ret = connect_to_new_client(&client_fd, &client_addr, client_addr_size, &local_addr, local_addr_size); if (ret != 0) { log_error("connect_to_new_client failed"); continue; } if (active_session_context != NULL) { session_free(EV_A_ active_session_context); active_session_context = NULL; } sc = calloc(1, sizeof(session_context)); session_init(gc, sc, &client_fd, (unsigned char *)&client_addr, client_addr_size, first_packet, first_packet_len); if (session_connected(sc) != 0) { log_error("can't init client connection"); free(sc); continue; } active_session_context = sc; /* Start listening for network events on the new client fd */ session_start(sc, EV_A); log_debug("global_cb - session_start - client_fd %d", sc->client_fd.fd); /* Trigger the FSM drive and start DTLS negotiation to backend, and * during this time, we just silently drop the first packet from * vpn client. */ ev_feed_fd_event(EV_A_ sc->backend_fd.fd, EV_READ); } }