Basic C tutorial on networking TCP/IP

B

Brian Keogh

Hi,
I'm a student learning TCP/IP networking at University. Although I
understand all about TCP/IP Networking in Java I am expected to understand
the basics of C with regard to these programs as all the examples in my
course notes and Exams refer to C. Can someone please point me in the right
direction to where I might find answers on the web explaining C code
involved with TCP/IP networking and what they mean.
These are quite basic I'm sure.
For example, what is the data type of a socket; or what does char*const host
= "mailserver.uni.ac.uk " or const char * host = "mailserver.uni.ac.uk" or
const char* const host = "mailserver.uni.ac.uk" mean.
Another is, explain the action of a complier upon encountering the
declaration #define PI 3.14159 ; or what would happen if we if we changed
the above declaration to const double PI = 3.14159 ?
I'm ashemed so say I've not got around to learning C yet . Hence.
Any of the books I have on C don't give me much to go on with regard to
explaining Networking in C unfortunately.


Your help here is greatly appreciated
Regards
Brian
 
M

Mark A. Odell

I'm a student learning TCP/IP networking at University.

TCP/IP and networking are not part of the C language. Try in one of the
newsgroups that has the word 'networking' or 'tcpip' in it.
 
C

Case

Brian said:
For example, what is the data type of a socket; or what does char*const host
= "mailserver.uni.ac.uk " or const char * host = "mailserver.uni.ac.uk" or
const char* const host = "mailserver.uni.ac.uk" mean.
Another is, explain the action of a complier upon encountering the
declaration #define PI 3.14159 ; or what would happen if we if we changed
the above declaration to const double PI = 3.14159 ?

The last two questions are about standard C, and have nothing to
do with network programming. I'm afraid that you have to acquire
basic knowledge about C. There are tutorials on the internet, and
there are chapters/pages in the book(s) you do have. We can't
help you any further here.

Good luck,

Case
 
R

Ralmin

Brian Keogh said:
Hi,
I'm a student learning TCP/IP networking at University. Although I
understand all about TCP/IP Networking in Java I am expected to understand
the basics of C with regard to these programs as all the examples in my
course notes and Exams refer to C. Can someone please point me in the right
direction to where I might find answers on the web explaining C code
involved with TCP/IP networking and what they mean.

TCP/IP implementations are typically platform-specific and better discussed
in dedicated newsgroups. They are not part of the C language itself, which
is the only valid topic here.
These are quite basic I'm sure.
For example, what is the data type of a socket; or what does char*const host
= "mailserver.uni.ac.uk " or const char * host = "mailserver.uni.ac.uk" or
const char* const host = "mailserver.uni.ac.uk" mean.

char *const host = "mailserver.uni.ac.uk";
This declares host as a const pointer to char. The pointer cannot be
modified to point elsewhere, but the object pointed to can be modified.
However, since the array that the pointer is initialised to point into is a
string literal, it is undefined behaviour to modify its contents.

char const *host = "mailserver.uni.ac.uk";
This declares host as a pointer to const char. The pointer can be modified
to point elsewhere, but the object pointed to cannot be modified. This makes
sense when used with a string literal, since it is undefined behaviour to
modify a string literal anyway.

const char *const host = "mailserver.uni.ac.uk";
This declares host as a const pointer to const char. The pointer cannot be
modified to point elsewhere, and the object pointed to cannot be modified
either.
Another is, explain the action of a complier upon encountering the
declaration #define PI 3.14159 ;

There should be no semicolon in a preprocessor constant like the above. The
compiler never sees the line above, as it has already been substituted by
the preprocessor before the compiler is run. Your code makes all following
occurrences of the token PI in the source code are textually replaced by the
two tokens 3.14159 ; unless and until a directive to undefine PI is reached.
or what would happen if we if we changed
the above declaration to const double PI = 3.14159 ?

That defines a real run-time object, which has scope (either file-scope or
block-scope, depending where it is declared) and linkage (either external
linkage if declared outside a function or no linkage if declared inside a
function). A preprocessor constant has scope until a matching undefine is
reached, and no linkage since it does not even exist after the preprocessor
has finished.
 
B

Brian Keogh

Many thanks Matt, thats great.
It will give me something to be getting along with regard to my queries

Kind regards,
Brian
 
B

Brian Keogh

Simon,
Thank you for taking the time to answer my questions. This is of great help
to me in trying to understand a few of the basics.

Kind Regards,
Brian
 
M

Malcolm

Brian Keogh said:
I'm ashemed so say I've not got around to learning C yet . Hence.
Any of the books I have on C don't give me much to go on with
regard to explaining Networking in C unfortunately.
You've got two jobs. Firstly you need to learn the basics of the C language,
and secondly you need to learn how to use a sockets / networking library.
Since ANSI C doesn't come with this library don't expect to find the two
things in the same book.
Since you are already familiar with Java neither of these things should be
too difficult. C has similar control structures to Java but also uses
pointers very heavily. I don't know enough about networking to tell you how
common C libraries and Java differ, but they are likely to be quite similar.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,142
Messages
2,570,820
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top