int main(int argc, char *argv[]) { char buffWrite [BUFFSIZE]; unsigned short port1, port2; if(argc!=3) { fprintf(stderr, "Uso: %s <Port1> <Port2>\n",argv[0]); exit(1); } port1=atoi(argv[1]); port2=atoi(argv[2]); init_1(port1); init_2(port2); while(1) { fflush(stdout); fgets(buffWrite, BUFFSIZE, stdin); //Es necesario quitarle el ultimo caracter porque es un enter '\n' buffWrite[strlen(buffWrite)-1] = '\0'; if(strcmp("FIN", buffWrite)==0) break; } cerrarSocket_1(); cerrarSocket_2(); return 0; }
int fightPlayer (getThetaFunction (*init_1)(const Game, void *), getThetaFunction (*init_2)(const Game, void *), void * arg1, void * arg2, char isGUI) { srand(clock()); Game game = game_new_game (); char newTheta_1, newTheta_2; clock_t delay, t = clock (); if (isGUI) initGUI (); getThetaFunction getTheta1 = init_1 (game, arg1); getThetaFunction getTheta2 = init_2 (game, arg2); while (!game->won) { if (isGUI && getEvent () == -1) break; newTheta_1 = (*getTheta1) (game, arg1); newTheta_1 = (newTheta_1 > 0 ? 1 : newTheta_1 == 0 ? 0 : -1); newTheta_2 = (*getTheta2) (game, arg2); newTheta_2 = (newTheta_2 > 0 ? 1 : newTheta_2 == 0 ? 0 : -1); game_update_game (game, newTheta_1, newTheta_2); if (isGUI) { delay = clock(); if ((delay - t) * IMAGES_PER_SEC < CLOCKS_PER_SEC) { struct timespec ts = {0, (1000 / IMAGES_PER_SEC - (delay - t) * 1000 / CLOCKS_PER_SEC) * 1000000}; nanosleep (&ts, NULL); } draw (game); t = clock (); } } int r = game->won; if (isGUI) quitGUI (); game_free_game (game); return r; }
unsigned char main_loop(char *av[], char *envp[]) { int ret[2]; char *choice; t_all *all; long long exit; static int run = 0; init(ret, &choice, &envp, &all); init_2(&exit); while (ret[1] != 0 && (!choice || exit == -2)) { prompt(ret[0]); ft_strdel(&choice); ret[1] = get_next_line(0, &choice); all = make_all(ft_strdup(choice), av, envp); (CL_SCR) ? cl_screen(all) : 0; (!IS_EXIT && !CL_SCR) ? (ret[0] = manage_choice(all)) : 0; manage_env(&all, &envp, &run, &exit); } prepare_exit(&envp, &all, &choice, ret[1]); exit = (exit == -2 || exit == -1) ? 0 : exit; return ((unsigned char)exit); }
static kadm5_ret_t init_any(krb5_context context, char *client_name, enum init_type init_type, char *pass, krb5_ccache ccache_in, char *service_name, kadm5_config_params *params_in, krb5_ui_4 struct_version, krb5_ui_4 api_version, char **db_args, void **server_handle) { int fd = -1; krb5_boolean iprop_enable; int port; rpcprog_t rpc_prog; rpcvers_t rpc_vers; krb5_ccache ccache; krb5_principal client = NULL, server = NULL; kadm5_server_handle_t handle; kadm5_config_params params_local; int code = 0; generic_ret *r; initialize_ovk_error_table(); /* initialize_adb_error_table(); */ initialize_ovku_error_table(); if (! server_handle) { return EINVAL; } if (! (handle = malloc(sizeof(*handle)))) { return ENOMEM; } memset(handle, 0, sizeof(*handle)); if (! (handle->lhandle = malloc(sizeof(*handle)))) { free(handle); return ENOMEM; } handle->magic_number = KADM5_SERVER_HANDLE_MAGIC; handle->struct_version = struct_version; handle->api_version = api_version; handle->clnt = 0; handle->client_socket = -1; handle->cache_name = 0; handle->destroy_cache = 0; handle->context = 0; *handle->lhandle = *handle; handle->lhandle->api_version = KADM5_API_VERSION_4; handle->lhandle->struct_version = KADM5_STRUCT_VERSION; handle->lhandle->lhandle = handle->lhandle; handle->context = context; if(client_name == NULL) { free(handle); return EINVAL; } /* * Verify the version numbers before proceeding; we can't use * CHECK_HANDLE because not all fields are set yet. */ GENERIC_CHECK_HANDLE(handle, KADM5_OLD_LIB_API_VERSION, KADM5_NEW_LIB_API_VERSION); memset(¶ms_local, 0, sizeof(params_local)); if ((code = kadm5_get_config_params(handle->context, 0, params_in, &handle->params))) { free(handle); return(code); } #define REQUIRED_PARAMS (KADM5_CONFIG_REALM | \ KADM5_CONFIG_ADMIN_SERVER | \ KADM5_CONFIG_KADMIND_PORT) if ((handle->params.mask & REQUIRED_PARAMS) != REQUIRED_PARAMS) { free(handle); return KADM5_MISSING_KRB5_CONF_PARAMS; } code = krb5_parse_name(handle->context, client_name, &client); if (code) goto error; /* * Get credentials. Also does some fallbacks in case kadmin/fqdn * principal doesn't exist. */ code = get_init_creds(handle, client, init_type, pass, ccache_in, service_name, handle->params.realm, &server); if (code) goto error; /* If the service_name and client_name are iprop-centric, use the iprop * port and RPC identifiers. */ iprop_enable = (service_name != NULL && strstr(service_name, KIPROP_SVC_NAME) != NULL && strstr(client_name, KIPROP_SVC_NAME) != NULL); if (iprop_enable) { port = handle->params.iprop_port; rpc_prog = KRB5_IPROP_PROG; rpc_vers = KRB5_IPROP_VERS; } else { port = handle->params.kadmind_port; rpc_prog = KADM; rpc_vers = KADMVERS; } code = connect_to_server(handle->params.admin_server, port, &fd); if (code) goto error; handle->clnt = clnttcp_create(NULL, rpc_prog, rpc_vers, &fd, 0, 0); if (handle->clnt == NULL) { code = KADM5_RPC_ERROR; #ifdef DEBUG clnt_pcreateerror("clnttcp_create"); #endif goto error; } handle->client_socket = fd; handle->lhandle->clnt = handle->clnt; handle->lhandle->client_socket = fd; /* now that handle->clnt is set, we can check the handle */ if ((code = _kadm5_check_handle((void *) handle))) goto error; /* * The RPC connection is open; establish the GSS-API * authentication context. */ code = setup_gss(handle, params_in, (init_type == INIT_CREDS) ? client : NULL, server); if (code) goto error; /* * Bypass the remainder of the code and return straightaway * if the gss service requested is kiprop */ if (iprop_enable) { code = 0; *server_handle = (void *) handle; goto cleanup; } r = init_2(&handle->api_version, handle->clnt); if (r == NULL) { code = KADM5_RPC_ERROR; #ifdef DEBUG clnt_perror(handle->clnt, "init_2 null resp"); #endif goto error; } /* Drop down to v3 wire protocol if server does not support v4 */ if (r->code == KADM5_NEW_SERVER_API_VERSION && handle->api_version == KADM5_API_VERSION_4) { handle->api_version = KADM5_API_VERSION_3; r = init_2(&handle->api_version, handle->clnt); if (r == NULL) { code = KADM5_RPC_ERROR; goto error; } } /* Drop down to v2 wire protocol if server does not support v3 */ if (r->code == KADM5_NEW_SERVER_API_VERSION && handle->api_version == KADM5_API_VERSION_3) { handle->api_version = KADM5_API_VERSION_2; r = init_2(&handle->api_version, handle->clnt); if (r == NULL) { code = KADM5_RPC_ERROR; goto error; } } if (r->code) { code = r->code; goto error; } *server_handle = (void *) handle; goto cleanup; error: /* * Note that it is illegal for this code to execute if "handle" * has not been allocated and initialized. I.e., don't use "goto * error" before the block of code at the top of the function * that allocates and initializes "handle". */ if (handle->destroy_cache && handle->cache_name) { if (krb5_cc_resolve(handle->context, handle->cache_name, &ccache) == 0) (void) krb5_cc_destroy (handle->context, ccache); } if (handle->cache_name) free(handle->cache_name); if(handle->clnt && handle->clnt->cl_auth) AUTH_DESTROY(handle->clnt->cl_auth); if(handle->clnt) clnt_destroy(handle->clnt); if (fd != -1) close(fd); kadm5_free_config_params(handle->context, &handle->params); cleanup: krb5_free_principal(handle->context, client); krb5_free_principal(handle->context, server); if (code) free(handle); return code; }