Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > BSD Sockets, Simple Compiling Issue

BSD Sockets, Simple Compiling Issue
Thread Tools
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Dec 6, 2002, 05:09 PM
 
I'm trying to compile some code from a TCP/IP book. It uses the BSD socket API. I get some compiler errors. Here's what I'm executing:

% gcc -o echo TCPEchoClient.c -lsocket
TCPEchoClient.c: In function `main':
TCPEchoClient.c:15: storage size of `echoServAddr' isn't known
TCPEchoClient.c:40: `IPPROTO_TCP' undeclared (first use in this function)

This is likely a linking issue or maybe an incomplete/modified header somewhere. But before I go nuts trying to find stuff I wanted to bring it your eyes in case you see something fishy with the gcc command above.

Below is a code snipplet that includes the includes ;-)

#include <stdio.h> /* for printf() and fprintf() */
#include <sys/socket.h> /* for socket(), connect(), send(), and recv() */
#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
#include <stdlib.h> /* for atoi() and exit() */
#include <string.h> /* for memset() */
#include <unistd.h> /* for close() */

Any tips appreciated.
Thanks!
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Dec 6, 2002, 09:00 PM
 
Got it. I needed to add a header file not in the original source; namely.

#include <netinet/in.h>

It compiled fine afterwards.

Thanks!
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:27 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2