C
Clement
Please tell me why the follwing program is not working............
client.c
#include<stdio.h>
#include<sys/socket.h>
#include<sys/un.h>
int main()
{
int sd, cd, len, re;
char data[100];
struct sockaddr_un local, remote;
sd = socket(AF_UNIX, SOCK_STREAM, 0);
local.sun_family = AF_UNIX;
strcpy(local.sun_path, "sock");
len = sizeof(local.sun_family) + strlen(local.sun_path);
re = connect(sd, (struct sockaddr *)&local, len);
scanf("%s",data);
send(cd, data, strlen(data)+1, 0);
}
server.c
#include<stdio.h>
#include<sys/socket.h>
#include<sys/un.h>
int main()
{
int sd, cd, len, re;
char data[100];
struct sockaddr_un local, remote;
sd = socket(AF_UNIX, SOCK_STREAM, 0);
local.sun_family = AF_UNIX;
strcpy(local.sun_path, "sock");
unlink(local.sun_path);
len = sizeof(local.sun_family) + strlen(local.sun_path);
re = bind(sd, (struct sockaddr *)&local, len);
listen(sd, 5);
cd = accept(sd, (struct sockaddr*)&remote, &len);
printf("%s",data);
recv(cd, data, 100, 0);
printf("%s\n",data);
}
client.c
#include<stdio.h>
#include<sys/socket.h>
#include<sys/un.h>
int main()
{
int sd, cd, len, re;
char data[100];
struct sockaddr_un local, remote;
sd = socket(AF_UNIX, SOCK_STREAM, 0);
local.sun_family = AF_UNIX;
strcpy(local.sun_path, "sock");
len = sizeof(local.sun_family) + strlen(local.sun_path);
re = connect(sd, (struct sockaddr *)&local, len);
scanf("%s",data);
send(cd, data, strlen(data)+1, 0);
}
server.c
#include<stdio.h>
#include<sys/socket.h>
#include<sys/un.h>
int main()
{
int sd, cd, len, re;
char data[100];
struct sockaddr_un local, remote;
sd = socket(AF_UNIX, SOCK_STREAM, 0);
local.sun_family = AF_UNIX;
strcpy(local.sun_path, "sock");
unlink(local.sun_path);
len = sizeof(local.sun_family) + strlen(local.sun_path);
re = bind(sd, (struct sockaddr *)&local, len);
listen(sd, 5);
cd = accept(sd, (struct sockaddr*)&remote, &len);
printf("%s",data);
recv(cd, data, 100, 0);
printf("%s\n",data);
}