do i just declare as normal?
http://img100.imageshack.us/img100/9362/ipheaderki6.jpg
do i just declare as normal?
http://img100.imageshack.us/img100/9362/ipheaderki6.jpg
I'm not sure what your question is, but declarations of structures are identical whether they are in a header-file or not. Your image is a bit hard to read on my machine, because of the dark brown text being hard to read against a black background - I expect you have less room -light than I do.
You need to include the appropriate header-file in any other file that uses the structure [or include it in a header-file before the header-file that uses the structure, but that's less flexible and puts more strain on the programmer to make sure all header files are always in the right order - correctly written header files should only allow themselves to be included once by using include-guards].
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
A good practice to get used to is, like matsp already mentioned, using include guards. This makes sure that the include file is only included once. Like so:
Ofcourse you would replace FILENAME with the actual name of the include file.#ifndef FILENAME_H
#define FILENAME_H
/* definitions and declarations go here. */
#endif /* FILENAME_H */
sorry only had a minute to post the thread.. i did a print scree and pasted it in paint, probably why its so dark..
so anyway, i've declared the filename as:
#include<netinet/ip> //ip.h which contains the structure "struct ip" and its contents "struct in_addr ip_dst ip_src" i am after.
im after the method to declare the structure ip or has it already been declared?
i want to access the contents so would it be like this?
main()
{
ip *ip_hdr;
or
When you declare an instance of a structure in C (C++ is different), you have to use the struct keyword.
Unless typedef or some such is used, then you need not.Code:struct s_t { int x; }; struct s_t thestruct;
Since there's no typedef in your structure definition, you'll need the "struct" keyword.Code:typedef struct { int x; } s_t; s_t thestruct;
Are you sure you're ready for socket/networking programming? It can be tougher than it looks, and if you don't know how to declare structures . . . .
Perhaps you should look at these.
Structures tutorial: http://www.cprogramming.com/tutorial/c/lesson7.html
Introduction to sockets: http://beej.us/guide/bgnet/
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
well its for my assignment that im working on. yes im rusty on my c, yes i don't know everything..
so far i've been able to retrieve the mac address(source and destination), type.
.. i know how to declare structures:
http://img355.imageshack.us/my.php?image=structjg3.jpg
and access them:
http://img210.imageshack.us/my.php?image=struct2bw1.jpg
im JUST wondering if its any different or not. when the structure is in the headerfile how do i declare the structure. just in the main function? or above even though the members have already been made in the headerfile.
i haven't had time to fiddle around a lot yet.