int main(void) { WSADATA Data; SOCKADDR_IN recvSockAddr; SOCKET recvSocket; int status; int numrcv = 0; struct hostent * remoteHost; char * ip; const char * host_name = "pb-homework.appspot.com"; char * buffer = malloc(sizeof(char) * MAXBUFLEN);; memset(buffer,0,MAXBUFLEN); // Initialize Windows Socket DLL status = WSAStartup(MAKEWORD(2, 2), &Data); if(status != 0) { printf("ERROR: WSAStartup unsuccessful\r\n"); return 0; } // Get IP address from host name remoteHost = gethostbyname(host_name); ip = inet_ntoa(*(struct in_addr *)*remoteHost->h_addr_list); printf("IP address is: %s.\n", ip); memset(&recvSockAddr, 0, sizeof(recvSockAddr)); // zero the sockaddr_in structure recvSockAddr.sin_port=htons(PORT); // specify the port portion of the address recvSockAddr.sin_family=AF_INET; // specify the address family as Internet recvSockAddr.sin_addr.s_addr= inet_addr(ip); // specify ip address // Create socket recvSocket = socket_new(); // Connect connect_to_server(recvSocket, recvSockAddr); // Send request send_initial_request(recvSocket, host_name); receive_response(recvSocket, buffer); // Receieve printf("%s\r\n", buffer); send_secret_request(recvSocket, host_name, buffer); // Get and make free(buffer); buffer = malloc(sizeof(char) * MAXBUFLEN); receive_response(recvSocket, buffer); printf("%s\r\n", buffer); inverse_str(buffer); // Send send_post(recvSocket, host_name, buffer); // Get answer free(buffer); buffer = malloc(sizeof(char) * MAXBUFLEN); receive_response(recvSocket, buffer); printf("\nServer response:\n\n%s\n", buffer); closesocket(recvSocket); getchar(); // Print out receieved socket data system("pause"); return 0; }
int notification_handler_func(void *handler_context) { int r = 0; deferred_handler_context_t *context = (deferred_handler_context_t*)handler_context; static const char *exclude_list[] = {NULL}; /* Maybe later */ char *json_envp = openvpn_envp_to_json((const char **)context->envp, exclude_list); PLUGIN_DEBUG("START - notification_handler_func."); PLUGIN_DEBUG("Data to post: %s. To URL: %s.", json_envp, context->handler_url); send_post(context->handler_url, json_envp); PLUGIN_DEBUG("END - notification_handler_func."); return r; }
inline void send_code(struct ir_remote *remote,ir_code code, int repeat) { if(!repeat || !(remote->flags&NO_HEAD_REP)) send_header(remote); send_lead(remote); send_pre(remote); send_data(remote,code,remote->bits,remote->pre_data_bits); send_post(remote); send_trail(remote); if(!repeat || !(remote->flags&NO_FOOT_REP)) send_foot(remote); if(!repeat && remote->flags&NO_HEAD_REP && remote->flags&CONST_LENGTH) { send_buffer.sum-=remote->phead+remote->shead; } }
int auth_user_pass_verify_handler_func(void *handler_context) { int r = 0; int http_code; deferred_handler_context_t *context = (deferred_handler_context_t*)handler_context; const char *auth_control_file = get_openvpn_env( "auth_control_file", (const char**)(context->envp)); const char *username = get_openvpn_env("username", (const char**)(context->envp)); /* I do not see any reasons why web server should know auth_control_file * to auth user. */ static const char *exclude_list[] = {"auth_control_file", NULL}; char *json_envp = openvpn_envp_to_json((const char **)context->envp, exclude_list); if (!username) username = ""; PLUGIN_DEBUG("START - auth_user_pass_verify_handler_func."); PLUGIN_DEBUG("Data to post: %s. To URL: %s. auth_control_file: %s.", json_envp, context->handler_url, auth_control_file); http_code = send_post(context->handler_url, json_envp); PLUGIN_DEBUG("HTTP Response code: %d.", http_code); if (http_code == 200) { PLUGIN_LOG("Auth for user %s SUCCESS.", username); write_auth_control_file(auth_control_file, 1); } else { PLUGIN_LOG("Auth for user %s FAILED.", username); write_auth_control_file(auth_control_file, 0); } free(json_envp); PLUGIN_DEBUG("END - auth_user_pass_verify_handler_func."); return r; }