P
Peter Rothenbuecher
Hello,
when I try to compile the following code with g++ -o client client.c
#include<sys/socket.h>
#include<stdio.h>
#include<stdlib.h>
#define ADDRESS "mysocket";
#define MAXLEN 200;
int main(int argc, char *argv)
{
int sd;
struct sockaddr_un sa;
int length;
char netmsg[MAXLEN];
if((sd=sock_create(AF_UNIX, SOCK_STREAM, 0))<0){
perror("Cannot create Socket");
exit(1);
}
sa.sun_family=AF_UNIX;
sa.sun_path=ADDRESS;
length=sizeof(sa.sun_family)+strlen(sa.sun_path);
if(bind(sd, (sockaddr_un*)&sa, length)<0){
perror("Couldn´t bind socket");
exit(1);
}
if(connect(sd, (sockaddr_un*)&sa, length)<0){
perror("Cannot connect to server");
exit(1);
}
if(send(sd, (char*) netmsg, MAXLEN)<0, 0){
perror("Cannot send message over network");
exit(1);
}
if(recv(sd, (char*) netmsg, MAXLEN, 0)<0){
perror("Message Receive failed");
exit(1);
}
if(close(sd)<0){
perror("Cannot close socket");
exit(1);
}
}
I get this message from the compiler:
client.c: In function `int main(int, char*)':
client.c:11: error: aggregate `sockaddr_un sa' has incomplete type and
cannot be defined
client.c:13: error: expected primary-expression before "char"
client.c:13: error: expected `;' before "char"
client.c:13: error: expected primary-expression before ']' token
client.c:13: error: expected `;' before ']' token
client.c:15: error: `sock_create' undeclared (first use this function)
client.c:15: error: (Each undeclared identifier is reported only once
for each function it appears in.)
client.c:21: error: `strlen' undeclared (first use this function)
client.c:31: error: `netmsg' undeclared (first use this function)
client.c:31: error: expected `)' before ';' token
client.c:31: error: expected `)' before ';' token
client.c:31: error: expected primary-expression before ')' token
client.c:31: error: expected `;' before ')' token
client.c:35: error: expected `)' before ';' token
client.c:35: error: expected `)' before ';' token
client.c:35: error: expected primary-expression before ',' token
client.c:35: error: expected `;' before ')' token
client.c:39: error: `close' undeclared (first use this function)
Can anybody help me what I have done wrong? I have no idea what to do.
It would be nice if somebody could help me to solve this problem.
Thanks,
Peter
when I try to compile the following code with g++ -o client client.c
#include<sys/socket.h>
#include<stdio.h>
#include<stdlib.h>
#define ADDRESS "mysocket";
#define MAXLEN 200;
int main(int argc, char *argv)
{
int sd;
struct sockaddr_un sa;
int length;
char netmsg[MAXLEN];
if((sd=sock_create(AF_UNIX, SOCK_STREAM, 0))<0){
perror("Cannot create Socket");
exit(1);
}
sa.sun_family=AF_UNIX;
sa.sun_path=ADDRESS;
length=sizeof(sa.sun_family)+strlen(sa.sun_path);
if(bind(sd, (sockaddr_un*)&sa, length)<0){
perror("Couldn´t bind socket");
exit(1);
}
if(connect(sd, (sockaddr_un*)&sa, length)<0){
perror("Cannot connect to server");
exit(1);
}
if(send(sd, (char*) netmsg, MAXLEN)<0, 0){
perror("Cannot send message over network");
exit(1);
}
if(recv(sd, (char*) netmsg, MAXLEN, 0)<0){
perror("Message Receive failed");
exit(1);
}
if(close(sd)<0){
perror("Cannot close socket");
exit(1);
}
}
I get this message from the compiler:
client.c: In function `int main(int, char*)':
client.c:11: error: aggregate `sockaddr_un sa' has incomplete type and
cannot be defined
client.c:13: error: expected primary-expression before "char"
client.c:13: error: expected `;' before "char"
client.c:13: error: expected primary-expression before ']' token
client.c:13: error: expected `;' before ']' token
client.c:15: error: `sock_create' undeclared (first use this function)
client.c:15: error: (Each undeclared identifier is reported only once
for each function it appears in.)
client.c:21: error: `strlen' undeclared (first use this function)
client.c:31: error: `netmsg' undeclared (first use this function)
client.c:31: error: expected `)' before ';' token
client.c:31: error: expected `)' before ';' token
client.c:31: error: expected primary-expression before ')' token
client.c:31: error: expected `;' before ')' token
client.c:35: error: expected `)' before ';' token
client.c:35: error: expected `)' before ';' token
client.c:35: error: expected primary-expression before ',' token
client.c:35: error: expected `;' before ')' token
client.c:39: error: `close' undeclared (first use this function)
Can anybody help me what I have done wrong? I have no idea what to do.
It would be nice if somebody could help me to solve this problem.
Thanks,
Peter