hi,
i've recently started to deal a little bit with tcp/ip-socket-programming
(linux).
Now i've written a little test-program (as displayed further down).
When i'm trying to compile it the gcc-compiler return "parse error in
l.23/.24 before token '='. "
the line before those two ( host_addr.sin_f amily = AF_INET;) is acepted
without any problems.
I'd be happy if anybody could tell me where's my fault.
Thanks a lot.
I'm sorry for mistakes in my english.
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#define host_IP = "127.0.0.1" ; //IP only for test purpose
#define host_PORT = 1024; //port number only for test purpose
int main(void)
{
int sock;
struct sockaddr_in host_addr;
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == -1)
printf("couldn' t establish socket.\n");
else
printf("socket created.\n");
host_addr.sin_f amily = AF_INET;
// l. 23// host_addr.sin_p ort = htons(host_PORT );
//l. 24// host_addr.sin_a ddr.s_addr = inet_addr(host_ IP);
if (connect(sock, (struct sockaddr *)&host_addr,si zeof(&host_addr )) != -1)
printf("connect ed to server.\n");
else
printf("couldn' t connect.\n");
close(sock);
printf("socket closed.\n");
}
i've recently started to deal a little bit with tcp/ip-socket-programming
(linux).
Now i've written a little test-program (as displayed further down).
When i'm trying to compile it the gcc-compiler return "parse error in
l.23/.24 before token '='. "
the line before those two ( host_addr.sin_f amily = AF_INET;) is acepted
without any problems.
I'd be happy if anybody could tell me where's my fault.
Thanks a lot.
I'm sorry for mistakes in my english.
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#define host_IP = "127.0.0.1" ; //IP only for test purpose
#define host_PORT = 1024; //port number only for test purpose
int main(void)
{
int sock;
struct sockaddr_in host_addr;
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == -1)
printf("couldn' t establish socket.\n");
else
printf("socket created.\n");
host_addr.sin_f amily = AF_INET;
// l. 23// host_addr.sin_p ort = htons(host_PORT );
//l. 24// host_addr.sin_a ddr.s_addr = inet_addr(host_ IP);
if (connect(sock, (struct sockaddr *)&host_addr,si zeof(&host_addr )) != -1)
printf("connect ed to server.\n");
else
printf("couldn' t connect.\n");
close(sock);
printf("socket closed.\n");
}
Comment