Armenian Knowledge Base  

Go Back   Armenian Knowledge Base > Technical sections > Languages, Compilers, Interpreters > Algorithms
Register

Reply
 
LinkBack Thread Tools
Old 15.01.2006, 17:30   #1
Авик
 
CyberJoe's Avatar
 
Join Date: 07 2002
Location: Yerevan
Age: 30
Posts: 1,348
Downloads: 2
Uploads: 0
Reputation: 9 | 0
Question BSD Sockets

Я пишу следующий код:

Code:
 	
#include <sys/types.h>
#include <sys/socket.h>

int main(){
int sockets;
socketpair(AF_INET, SOCK_STREAM, 0, sockets);

return 0;
}
В папке SYS нет файла socket.h

естественно выдаеться ошибка об отсуствии сего файла.

Мне нужно написать программу работающую с сокетами Беркли. кто нибудь может посоветовать Литературу, и вообще откуда сей socket.h берецца? в найденном мною мануале вышенаписанный код должен был работать...
Если не ошибаюсь это вполне скомпилировалось бы под *nix но мне нужно именно под Win и именно BSD а не WinSock.

спасибо.

Last edited by CyberJoe; 15.01.2006 at 19:27.
Reply With Quote
Old 15.01.2006, 17:53   #2
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 32
Posts: 1,082
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Lightbulb Re: BSD Sockets

Definitely the best book on the subject:
UNIX Network Programming by famous Richard Stevens. There are pretty good russian editions of the book available in our local stores, just look for Network Programming by Stevens.

Definitely the best online tutorial on the subject:
Beej's Guide To Network Programming

For deeper understanding of the subject, try TCP/IP Illustrated by the same Stevens guy, amazing 3 volumes at first glance (I never actually got to really read those)

Unfortunately, my Internet is semidead, or I'd provide Amazon links with the books.

And there must be built-in manuals in BSD for quick access to function declarations and all. Start with man socket. Shouldn't be a problem!
-------------------
Regarding your problem:

I'm not exactly a UNIX expert, but perhaps you can try to '[[email protected]]#slocate socket.h' and see where it is, afterwards replacing your code to include the appropriate directory? It is not likely that there is absolutely no socket.h on your system
Reply With Quote
Old 15.01.2006, 19:11   #3
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 32
Posts: 1,082
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default Re: BSD Sockets

Uh, my wrong, regarding the 2nd part of my post.
Replace 'try to '[[email protected]]#slocate socket.h'' with 'try to 'Start > Search > For Files and Folders > socket.h > Search Now''

And make sure that the directory where your 3rd-party socket.h is has a higher priority than the default include directory for your compiler, coz otherwise Winsock may get included instead (was it even called socket.h for Winsock?).
Reply With Quote
Old 15.01.2006, 19:21   #4
Авик
 
CyberJoe's Avatar
 
Join Date: 07 2002
Location: Yerevan
Age: 30
Posts: 1,348
Downloads: 2
Uploads: 0
Reputation: 9 | 0
Default Re: BSD Sockets

Thanx Silver, but can you explain me, how realize this with Visual Studio 6.0:


Some MPE/iX include files expect certain variables to be defined. For example, <types.h.sys> expects SOCKET_SOURCE to be defined. Defines are declared in a C program by using #define; however, instead of modifying source code, a define can be declared at runtime.
The following example shows how to compile the program:

Code:
:ccxl sourcepg,obj,listing;info="-Aa &
   -D_SOCKET_SOURCE -D_POSIX_SOURCE"
The following example shows how to link the program:

Code:
:link from=obj;rl=^rllist;to=prog
The following RLLIST file was used in linking the above program:

socketrl.net.sys
libcinit.lib.sys

Note: Ensure that you link with the POSIX library (/lib/libc.a) instead of libcinit.lib.sys for POSIX programs. If you are using fork(), you need to link with PH capabilities.


P.S
and, I have no socket.h on my computer
I want to use Berkeleys Sockets, because they will work with win32 and *nix
__________________
вот собственно все, что я хотел сказать.
Reply With Quote
Old 15.01.2006, 21:19   #5
The splendid
 
AvDav's Avatar
 
Join Date: 07 2004
Location: Pure thoughts
Age: 36
Posts: 3,408
Downloads: 22
Uploads: 0
Reputation: 222 | 3
Default Re: BSD Sockets

You can build using cygwin but have to either redistribute the cygwin1.dll or force static linkage through MinGW compiler using -mno-cygwin switch (could be painful). Or have a look at the one of cross-platform libs like http://www.datareel.com.
Reply With Quote
Old 15.01.2006, 22:07   #6
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 32
Posts: 1,082
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default Re: BSD Sockets

Well, I have no idea what does that 'ccx1' stuff mean.

However.

If your goal is to write a program that compiles in both Windows and Unix, you may simply use Winsock (which is based on BSD sockets) under Windows and the same calls with the same arguments I believe will work under Linux as well. Just use receive() instead of WSAReceive() and so on. Minor differences between the platforms (like the include files, specific initialization routines and anything else) you can fix using #ifdef..#endif. I'm not sure about this, but I get a feeling like it's gonna work.
Simple encapsulation of your network functionality (if you're doing C++) might help, too.
Reply With Quote
Sponsored Links
Reply

Thread Tools


На правах рекламы:
реклама

All times are GMT. The time now is 19:39.


Powered by vBulletin® Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.