PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Noms de domaine > comp.protocols.tcp-ip > [Socket API] Create local server socket without specifying a set port number?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.protocols.tcp-ip TCP and IP network protocols.

[Socket API] Create local server socket without specifying a set port number?

Réponse
 
LinkBack Outils de la discussion
Vieux 02/05/2006, 13h48   #1
antred
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut [Socket API] Create local server socket without specifying a set port number?

Hi all,

I need to emulate the socketpair() function on a platform that doesn't
provide this function natively. I intend to achieve this by creating a
local server socket, then connecting to it via another socket and
finally accepting the incoming connection attempt. This would give me a
pair of connected sockets, just like the socketpair() function.
Now the question I have is this. In order to be able to connect() to my
server socket, I first need to bind() it to a set port number and then
specify that port number in my connect() call. But since both the
server socket and the connecting socket exist on the same computer (and
even in the same process) it isn't really necessary to have some "well
known" port number (and run the risk of that port number already being
occupied by some other application). So .... is there are way to let
the system assign an arbitrary port number to my server socket and then
calling some function to find out about that port number so I can
specify in my connect() call?
Thanks in advance for any useful replies!

Regards,

Markus

  Réponse avec citation
Vieux 02/05/2006, 17h28   #2
Phil Frisbie, Jr.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [Socket API] Create local server socket without specifying aset port number?

antred wrote:

> Hi all,
>
> I need to emulate the socketpair() function on a platform that doesn't
> provide this function natively. I intend to achieve this by creating a
> local server socket, then connecting to it via another socket and
> finally accepting the incoming connection attempt. This would give me a
> pair of connected sockets, just like the socketpair() function.
> Now the question I have is this. In order to be able to connect() to my
> server socket, I first need to bind() it to a set port number and then
> specify that port number in my connect() call. But since both the
> server socket and the connecting socket exist on the same computer (and
> even in the same process) it isn't really necessary to have some "well
> known" port number (and run the risk of that port number already being
> occupied by some other application). So .... is there are way to let
> the system assign an arbitrary port number to my server socket and then
> calling some function to find out about that port number so I can
> specify in my connect() call?


Bind to port '0' to get a system assigned port, then call getsockname() to find
out the port number.

--
Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com
  Réponse avec citation
Vieux 02/05/2006, 19h25   #3
antred
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Create local server socket without specifying a set port number?

Excellent, just what I wanted. Thanks!

  Réponse avec citation
Vieux 03/05/2006, 06h03   #4
Barry Margolin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [Socket API] Create local server socket without specifying a set port number?

In article <1146574102.483134.320630@i39g2000cwa.googlegroups .com>,
"antred" <NutJob@gmx.net> wrote:

> Hi all,
>
> I need to emulate the socketpair() function on a platform that doesn't
> provide this function natively. I intend to achieve this by creating a
> local server socket, then connecting to it via another socket and
> finally accepting the incoming connection attempt. This would give me a
> pair of connected sockets, just like the socketpair() function.
> Now the question I have is this. In order to be able to connect() to my
> server socket, I first need to bind() it to a set port number and then
> specify that port number in my connect() call. But since both the
> server socket and the connecting socket exist on the same computer (and
> even in the same process) it isn't really necessary to have some "well
> known" port number (and run the risk of that port number already being
> occupied by some other application). So .... is there are way to let
> the system assign an arbitrary port number to my server socket and then
> calling some function to find out about that port number so I can
> specify in my connect() call?
> Thanks in advance for any useful replies!


Why do you need port numbers at all? Shouldn't socketpair() use
Unix-domain sockets rather than Internet sockets?

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
  Réponse avec citation
Vieux 03/05/2006, 10h15   #5
antred
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Create local server socket without specifying a set port number?

Well, like I said, I cannot use the actual socketpair() function since
it's not available on Windows. Therefore I'm writing my own fake
socketpair() function. If you know a better way of doing this than the
one I mentioned I'm all ears. ;-)

  Réponse avec citation
Vieux 03/05/2006, 13h41   #6
Sam Mason
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Create local server socket without specifying a set port number?

antred wrote:
> Well, like I said, I cannot use the actual socketpair() function since
> it's not available on Windows. Therefore I'm writing my own fake
> socketpair() function. If you know a better way of doing this than the
> one I mentioned I'm all ears. ;-)


Cygwin uses TCP/IP sockets. If you're writing GPL compatible code then
you could look at their code for ideas.


Sam
  Réponse avec citation
Vieux 04/05/2006, 00h33   #7
Barry Margolin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Create local server socket without specifying a set port number?

In article <1146647709.499208.283310@v46g2000cwv.googlegroups .com>,
"antred" <NutJob@gmx.net> wrote:

> Well, like I said, I cannot use the actual socketpair() function since
> it's not available on Windows. Therefore I'm writing my own fake
> socketpair() function. If you know a better way of doing this than the
> one I mentioned I'm all ears. ;-)


You said the platform doesn't have socketpair(), you never said it
doesn't have Unix-domain sockets.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
  Réponse avec citation
Vieux 04/05/2006, 02h53   #8
Vernon Schryver
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Create local server socket without specifying a set port number?

In article <barmar-0CCCAB.19333803052006@comcast.dca.giganews.com>,
Barry Margolin <barmar@alum.mit.edu> wrote:

>> Well, like I said, I cannot use the actual socketpair() function since
>> it's not available on Windows. Therefore I'm writing my own fake
>> socketpair() function. If you know a better way of doing this than the
>> one I mentioned I'm all ears. ;-)

>
>You said the platform doesn't have socketpair(), you never said it
>doesn't have Unix-domain sockets.


Why should the other person care about UNIX domain sockets? The
question was about socketpair(), which can work with more protocol
families than PF_UNIX (or PF_LOCAL in the new world order, except that
isn't PF_UNIX the new order and AF_UNIX the original?).

What do UNIX domain sockets offer, other than
1. an obscure way to do something very similar to the pipe() system call
on modern BSD flavors that have bidirectional pipes.
2. names in the file system instead of IP addresses
3. more throughput than loopback TCP or UDP on some systems, and less
on other systems
4. some hard to fix races in how applications handle deleting the file
system nodes
5. some access control or authorization mechanisms not available
with TCP or UDP sockets, except on operating systems with some
sort of MAC (Mandatory Access Control, not network Media Access
Controller) on port numbers. Such systems are mostly sold to
spooky government agencies because they're too much useless hassle
in the real world.

I count all except #2 and maybe #5 as problems instead of advantages.

I think a socketpair() work-alike to what a nearby `man socketpair` says
int socketpair(int d, int type, int protocol, int *sv);
for d=PF_INET should need only a handful of lines. What am I missing?

You might even handle d=PF_UNIX. I think I recall implementing a
libc user-space socketpair() on top of some flavor of UNIX pipes
for a commercial UNIX system a couple of decades ago.


Vernon Schryver vjs@rhyolite.com
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 14h24.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14524 seconds with 16 queries