This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Where are the socket libraries?


I'll put in my 2 cents on this one.  First of all I don't think
"333.444.555.6" is a valid IP address.  There may be a conversion problem
w/inet_addr.  Also I suspect your assignments of 'serv'.  It also appears
that you did not setup the transport end point.  You might try this:

#include <sys/socket.h>
#include <netinet/in.h>
#define SvrSocketNo 777
#define SIZE sizeof(struct sockaddr_in)

int sockfd;
char c;

struct sockaddr_in server = {AF_INET, SvrSocketNo};
sockfd = (int)socket(AF_INET, SOCK_STREAM,0);
connect(sockfd, (struct sockaddr *)&server, SIZE);
len = send(sockfd, &c, 1, 0);

Good Luck .. John


The source I have is below:

The error messages I get when trying to gcc this stuff is:

request for member "sin_family" in something not a structure or union
request for member "sin_addr" in something not a structure or union
request for member "sin_port" in something not a structure or union

The only place I can find sin_family and such is on /usr/include/linux/in.h.
I have tried to include <linux/in.h> but it makes no difference.  All help
will be appreciated.  Thanks

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>

 int i,j;
 int sock1;
 char ibuf[BUFSIZ];

 struct sockaddr *serv;

 serv.sin_family = AF_INET;
 serv.sin_addr.s_addr = inet_addr("333.444.555.6");
 serv.sin_port = htons(777);

 if(connect(sock1, (struct sockaddr*) &serv,sizeof(serv)) < 0)
  printf("Error on connect\n");

 i = write(sock1,"This is test1",13);
 i = read(sock1,ibuf,20);
 printf("Ibuf: %s\n",ibuf);

----- Original Message -----
From: "Alexandre Oliva" <>
To: "Robert Nail" <>
Cc: <>
Sent: Thursday, December 07, 2000 10:36 AM
Subject: Re: Where are the socket libraries?

> On Dec  7, 2000, "Robert Nail" <> wrote:
> > I try to link a simple socket program for Linux 6.0 but it can't find
> > SOCKADDR structure.
> This will list the header files you may have to include to get its
> definition:
> grep -l -r SOCKADDR /usr/include
> Then, you may have to link your program with some libraries (!= header
> files) to get definitions of whatever functions you use.
> --
> Alexandre Oliva   Enjoy Guarana', see
> Red Hat GCC Developer                  aoliva@{,}
> CS PhD student at IC-Unicamp        oliva@{,}
> Free Software Evangelist    *Please* write to mailing lists, not to me

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]