Note that there are some explanatory texts on larger screens.

plurals
  1. POundefined reference to _red
    text
    copied!<p>I am writing a simple client program "socket programming" when compiling the code using cygwin I got this error "undefined reference to '_red' The code is below. I have been compiling with this statement gcc client.c I really do not understand why I am getting this error. I could really use some help. The code is below.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;sys/types.h&gt; #include &lt;sys/socket.h&gt; #include &lt;netdb.h&gt; #include &lt;stdlib.h&gt; #include &lt;strings.h&gt; #include &lt;netinet/in.h&gt; #define SERVER_TCP_PORT 2000 #define BUFLEN 256 int main(int argc,char **argv) { int n,bytes_to_read; int sd,port; struct hostent *hp; struct sockaddr_in server; char *host,*bp,rbuf[BUFLEN],sbuf[BUFLEN]; switch(argc) { case 2: host = argv[1]; port = atoi(argv[2]); break; default: fprintf(stderr,"Usage: %s host[port] \n",argv[0]); exit(1); } /*Create a streamm socket*/ if ((sd=socket(AF_INET,SOCK_STREAM,0))==-1){ fprintf(stderr,"Can't create a socket\n"); exit(1); } bzero ((char *)&amp;server,sizeof(struct sockaddr_in)); server.sin_family = AF_INET; server.sin_port = htons(port); if((hp = gethostbyname(host))==NULL){ fprintf (stderr,"Can't get server's address\n"); exit(1); } //bcopy(hp-&gt;h_addr,(char *)&amp;server.sin_addr,hp-&gt;h_length); /*connecting to the server*/ if (connect (sd,(struct sockaddr *)&amp;server,sizeof(server))==-1){ fprintf(stderr,"Can't connect \n"); exit(1); } printf("Connected:server's address is %s\n",hp-&gt;h_name); printf("Transmit: \n"); gets(sbuf); /*get user's text*/ write (sd,sbuf,BUFLEN); /*send it out*/ printf("Receive: \n"); bp = rbuf; bytes_to_read = BUFLEN; while ((n=red(sd,bp,bytes_to_read))&gt;0){ bp+=n; bytes_to_read -=n; } printf("%s\n",rbuf); close(sd); return(0); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload