![]() |
| | #1 |
| Registered User Join Date: Oct 2009
Posts: 6
| c program on ssh client 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);
}
|
| shawon is offline | |
| | #2 |
| Registered User Join Date: Oct 2009 Location: While(1)
Posts: 316
| It is working on my client here can u please attach the errors also |
| RockyMarrone is offline | |
| | #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);
}
}
|
| shawon is offline | |
![]() |
| Tags |
| ssh linux to windows |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Socket Programming Problem!!!! | bobthebullet990 | Networking/Device Communication | 2 | 02-21-2008 07:36 PM |
| Inserting text into MDI program | Rutabega | Windows Programming | 0 | 12-23-2005 11:25 AM |
| Please could someone help me with my 8-function calculator program? | Geeth Asokan | C Programming | 2 | 05-10-2002 04:16 PM |
| Most Secure (SSH) Telnet Client for Programming | kuphryn | A Brief History of Cprogramming.com | 0 | 02-14-2002 08:49 PM |
| My program, anyhelp | @licomb | C Programming | 14 | 08-14-2001 10:04 PM |