AKB Forums

Go Back   AKB Forums > Technical sections > Algorithms
Home Register Blogs FAQ Members List Calendar Downloads Arcade Mark Forums Read

Algorithms The source of algorithms for your project

Troubles when posting message? Click here! :: Проблемы с отправлением сообщения? Нажмите сюда!

Reply
 
LinkBack Thread Tools Display Modes
Old Jan 15, 2006, 16:30   #1
Авик
 
CyberJoe's Avatar
 
Join Date: Jul 2002
Location: Yerevan
Posts: 1,347
Rep Power: 6
Reputation: 19
Send a message via ICQ to CyberJoe
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 : Jan 15, 2006 at 18:27.
CyberJoe is offline   Reply With Quote Quote selected
Old Jan 15, 2006, 16:53   #2
Easy rider
 
Silver's Avatar
 
Join Date: Nov 2005
Location: tristeza
Posts: 1,087
Rep Power: 3
Reputation: 10
Send a message via ICQ to Silver
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 '[root@localhost]#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
Silver is offline   Reply With Quote Quote selected
Old Jan 15, 2006, 18:11   #3
Easy rider
 
Silver's Avatar
 
Join Date: Nov 2005
Location: tristeza
Posts: 1,087
Rep Power: 3
Reputation: 10
Send a message via ICQ to Silver
Re: BSD Sockets

Uh, my wrong, regarding the 2nd part of my post.
Replace 'try to '[root@localhost]#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?).
Silver is offline   Reply With Quote Quote selected
Old Jan 15, 2006, 18:21   #4
Авик
 
CyberJoe's Avatar
 
Join Date: Jul 2002
Location: Yerevan
Posts: 1,347
Rep Power: 6
Reputation: 19
Send a message via ICQ to CyberJoe
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
__________________
вот собственно все, что я хотел сказать.
CyberJoe is offline   Reply With Quote Quote selected
Old Jan 15, 2006, 20:19   #5
Дикообраз-безобраз
 
AvDav's Avatar
 
Join Date: Jul 2004
Location: У самого синего моря
Posts: 2,508
Rep Power: 4
Reputation: 44
Send a message via ICQ to AvDav
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.
__________________
Forza Alb-Violeţii.
AvDav is offline   Reply With Quote Quote selected
Old Jan 15, 2006, 21:07   #6
Easy rider
 
Silver's Avatar
 
Join Date: Nov 2005
Location: tristeza
Posts: 1,087
Rep Power: 3
Reputation: 10
Send a message via ICQ to Silver
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.
Silver is offline   Reply With Quote Quote selected
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
sockets in php no1 Web Development 1 Nov 12, 2003 15:37
ASP sockets hov Web Development 0 Mar 24, 2003 08:09
ASP Sockets question Rust Web Development 1 Oct 17, 2002 18:26
sockets & port 23 z0mbie Languages, Compilers and Interpreters 6 Apr 23, 2002 05:33


All times are GMT. The time now is 12:22.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
This board was founded on September 29, 2001
Powered by Viper Internet

Affordable Web Hosting | ParevNet

Buy text link