Thread: c program on ssh client

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    6

    c program on ssh client

    my following program runs successfully on linux server but when i want compile/run this program on windows machine using ssh client it doesn't works ...
    the errors occurs in including header files. can any one help me on this..
    it's really very urgent

    code:

    Code:
    /*  Make the necessary includes and set up the variables.  */
    
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <stdio.h>
    #include <sys/un.h>
    #include <unistd.h>
    
    int main()
    {
        int sockfd;
        int len;
        struct sockaddr_un address;
        int result;
        char ch = 'A';
    
    /*  Create a socket for the client.  */
    
        sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
    
    /*  Name the socket, as agreed with the server.  */
    
        address.sun_family = AF_UNIX;
        strcpy(address.sun_path, "server_socket");
        len = sizeof(address);
    
    /*  Now connect our socket to the server's socket.  */
    
        result = connect(sockfd, (struct sockaddr *)&address, len);
    
        if(result == -1) {
            perror("oops: client1");
            exit(1);
        }
    
    /*  We can now read/write via sockfd.  */
    
        write(sockfd, &ch, 1);
        read(sockfd, &ch, 1);
        printf("char from server = %c\n", ch);
        close(sockfd);
        exit(0);
    }

  2. #2
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    It is working on my client here
    can u please attach the errors also

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    6
    actually this file associated with a file server1.c. the server1.c will run on linux machine and the client1.c will run in linux throw SSH Secure Shell Client software on windown machine by connecting to that linux machine where server1.c is running. after running the client program when we type anything on this it will be sent to server & server will show that text.

    The server1.c file contains...
    Code:
    /*  Make the necessary includes and set up the variables.  */
    
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <stdio.h>
    #include <sys/un.h>
    #include <unistd.h>
    
    int main()
    {
        int server_sockfd, client_sockfd;
        int server_len, client_len;
        struct sockaddr_un server_address;
        struct sockaddr_un client_address;
    
    /*  Remove any old socket and create an unnamed socket for the server.  */
    
        unlink("server_socket");
        server_sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
    
    /*  Name the socket.  */
    
        server_address.sun_family = AF_UNIX;
        strcpy(server_address.sun_path, "server_socket");
        server_len = sizeof(server_address);
        bind(server_sockfd, (struct sockaddr *)&server_address, server_len);
    
    /*  Create a connection queue and wait for clients.  */
    
        listen(server_sockfd, 5);
        while(1) {
            char ch;
    
            printf("server waiting\n");
    
    /*  Accept a connection.  */
    
            client_len = sizeof(client_address);
            client_sockfd = accept(server_sockfd, 
                (struct sockaddr *)&client_address, &client_len);
    
    /*  We can now read/write to client on client_sockfd.  */
    
            read(client_sockfd, &ch, 1);
            ch++;
            write(client_sockfd, &ch, 1);
            close(client_sockfd);
        }
    }
    please help me it's very urgent now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Socket Programming Problem!!!!
    By bobthebullet990 in forum Networking/Device Communication
    Replies: 2
    Last Post: 02-21-2008, 07:36 PM
  2. Inserting text into MDI program
    By Rutabega in forum Windows Programming
    Replies: 0
    Last Post: 12-23-2005, 11:25 AM
  3. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  4. Most Secure (SSH) Telnet Client for Programming
    By kuphryn in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 02-14-2002, 08:49 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

Tags for this Thread