All pastes #360581 Raw Edit

secret

public c v1 · immutable
·published 2007-02-17 16:13 UTC
rendered paste body
/* exersam socket() si connect() */#include <stdlib.h>#include <string.h>#include <stdio.h>#include <netinet/in.h>#include <sys/types.h>#include <sys/socket.h>#include <unistd.h>#define INTERNET_PROTOCOL "64.148.37.183" // Tiksi's box :P#define PORT 22int main(void){    int sockfd; // for the else statement    char answer[0];    if((socket(PF_INET, SOCK_STREAM, 0))==-1)    {        printf("Creating the socket has failed!\n");        exit(EXIT_FAILURE);    }    else    {        // and there we go now.. -_-        struct sockaddr_in server;        sockfd=socket(PF_INET, SOCK_STREAM, 0);        // starting to define struct's elements        server.sin_family=AF_INET;        server.sin_port=htons(PORT);        server.sin_addr.s_addr=inet_addr(INTERNET_PROTOCOL);        memset(&(server.sin_zero), '\0', 8);        if((connect(sockfd, (struct sockaddr *)&server, sizeof(struct sockaddr)))==-1)        {            printf("Connecting to server %s failed!\n");            printf("Retry? (y/n) ");            scanf("%s", answer);            if(strcmp(answer, "y")==0)            {                // reia connect-ul                connect(sockfd, (struct sockaddr *)&server, sizeof(struct sockaddr));            }            else if(strcmp(answer, "n")==0)            {                printf("Ok, exiting now...\n");                exit(EXIT_FAILURE);            }            else            {                printf("Please answer with 'y' or 'n'!\n");                exit(EXIT_FAILURE);            }        }        else        {            printf("You have successfully connected to %s !\n", INTERNET_PROTOCOL);            printf("Congrats!\n");            exit(EXIT_SUCCESS);        }    }}