Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   how to know local port used in an udp client ? (http://www.velocityreviews.com/forums/t708456-how-to-know-local-port-used-in-an-udp-client.html)

Greg2fs 12-12-2009 08:12 AM

how to know local port used in an udp client ?
 
Hello, I know the port used by my udp client to forward it using upnp.
How to do ?

Thanks

Kenny McCormack 12-12-2009 10:52 AM

Re: how to know local port used in an udp client ?
 
In article <920a5816-48ea-430a-b1ea-a8c2709f8f97@k17g2000yqh.googlegroups.com>,
Greg2fs <greg2fs@gmail.com> wrote:
>Hello, I know the port used by my udp client to forward it using upnp.
>How to do ?
>
>Thanks


Off topic. Not portable. Cant discuss it here. Blah, blah, blah.

--
Useful clc-related links:

http://en.wikipedia.org/wiki/Aspergers
http://en.wikipedia.org/wiki/Clique
http://en.wikipedia.org/wiki/C_programming_language


Greg2fs 12-12-2009 04:05 PM

Re: how to know local port used in an udp client ?
 
On 12 déc, 11:52, gaze...@shell.xmission.com (Kenny McCormack) wrote:
> In article <920a5816-48ea-430a-b1ea-a8c2709f8...@k17g2000yqh.googlegroups..com>,
>
> Greg2fs *<greg...@gmail.com> wrote:
> >Hello, I know the port used by my udp client to forward it using upnp.
> >How to do ?

>
> >Thanks

>
> Off topic. *Not portable. *Cant discuss it here. *Blah, blah, blah.
>
> --
> Useful clc-related links:
>
> * *http://en.wikipedia.org/wiki/Aspergers
> * *http://en.wikipedia.org/wiki/Clique
> * *http://en.wikipedia.org/wiki/C_programming_language


Isn't it a c group ? I don't understand...

Kenny McCormack 12-12-2009 04:32 PM

Re: how to know local port used in an udp client ?
 
In article <6ca6c384-697c-450b-990a-857a3e91314d@d20g2000yqh.googlegroups.com>,
Greg2fs <greg2fs@gmail.com> wrote:
>On 12 déc, 11:52, gaze...@shell.xmission.com (Kenny McCormack) wrote:
>> In article

><920a5816-48ea-430a-b1ea-a8c2709f8...@k17g2000yqh.googlegroups.com>,
>>
>> Greg2fs *<greg...@gmail.com> wrote:
>> >Hello, I know the port used by my udp client to forward it using upnp.
>> >How to do ?

>>
>> >Thanks

>>
>> Off topic. *Not portable. *Cant discuss it here. *Blah, blah, blah.
>>
>> --
>> Useful clc-related links:
>>
>> * *http://en.wikipedia.org/wiki/Aspergers
>> * *http://en.wikipedia.org/wiki/Clique
>> * *http://en.wikipedia.org/wiki/C_programming_language

>
>Isn't it a c group ? I don't understand...


It was a pre-emptive strike. As you will soon find out, this newsgroup
has been taken over by a bunch of buttheads who have this totally weird
notion about what the C language is. They will be along any second now
to tell you the same thing I just told you, but in much more patronizing
and juvenile tones.

In other words, I was joking. They will not be.

And, welcome to CLC. We hope you enjoy your stay!


Barry Schwarz 12-12-2009 04:45 PM

Re: how to know local port used in an udp client ?
 
On Sat, 12 Dec 2009 08:05:57 -0800 (PST), Greg2fs <greg2fs@gmail.com>
wrote:

>On 12 déc, 11:52, gaze...@shell.xmission.com (Kenny McCormack) wrote:
>> In article <920a5816-48ea-430a-b1ea-a8c2709f8...@k17g2000yqh.googlegroups.com>,
>>
>> Greg2fs *<greg...@gmail.com> wrote:
>> >Hello, I know the port used by my udp client to forward it using upnp.
>> >How to do ?

>>
>> >Thanks

>>
>> Off topic. *Not portable. *Cant discuss it here. *Blah, blah, blah.
>>
>> --
>> Useful clc-related links:
>>
>> * *http://en.wikipedia.org/wiki/Aspergers
>> * *http://en.wikipedia.org/wiki/Clique
>> * *http://en.wikipedia.org/wiki/C_programming_language

>
>Isn't it a c group ? I don't understand...


If you hang around long enough you will learn two things at least:

Who enjoys being obnoxious and disruptive.

That this is group about the C language, not about how to use
programs written in C or how to use extensions to the language to
perform system specific tasks. Since the C language as defined in the
ISO standard has no support for ports, udp, or upnp, your question
falls into the latter category. You will get much better responses if
you post the question in a group that deals with upnp.

--
Remove del for email

Antoninus Twink 12-12-2009 05:36 PM

Re: how to know local port used in an udp client ?
 
On 12 Dec 2009 at 8:12, Greg2fs wrote:
> Hello, I know the port used by my udp client to forward it using upnp.
> How to do ?


Use getsockname(2).

Or, choose which port to bind to yourself instead of letting the socket
layer choose an available ephemeral port.

Please ignore the trolls who seek to disrupt this newsgroup by
restricting discussion of valid C programming topics like networking.


Antoninus Twink 12-12-2009 05:42 PM

Re: how to know local port used in an udp client ?
 
On 12 Dec 2009 at 17:36, Richard wrote:
> This group is about all C related programming as defined in its
> founding charter.


Exactly.

It is interesting that none of the topicality taliban have the courage
of their convictions to set up comp.lang.iso-c or comp.lang.c.iso and
see just how popular a group restricted to ISO C would be...


Seebs 12-12-2009 06:32 PM

Re: how to know local port used in an udp client ?
 
On 2009-12-12, Greg2fs <greg2fs@gmail.com> wrote:
> Isn't it a c group ? I don't understand...


The C language doesn't have sockets. Some specific implementations have
sockets, but the way you use sockets varies widely from one system to another,
so there's no generic answer. If you're on a Unix-derived system, you can
probably get good answers in comp.unix.programmer, but those same answers will
be worthless to you if you're on Windows...

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!

Antoninus Twink 12-12-2009 06:43 PM

Re: how to know local port used in an udp client ?
 
On 12 Dec 2009 at 18:32, Seebs wrote:
> The C language doesn't have sockets.


Nonsense.

Are you trying to argue that

int socket(int domain, int type, int protocol);

is not a C API? If so, I call bullshit.

My advice would be to leave that sort of stupidity to Heathfield and
Thomson.

> If you're on a Unix-derived system, you can probably get good answers
> in comp.unix.programmer, but those same answers will be worthless to
> you if you're on Windows...


This is nonsense. Sockets are very portable - Windows also uses
Berkeley sockets.

This is a great example of something that is indisputably better
discussed in a more general group like clc, because it *isn't* specific
to Windows or to *nix.


Kaz Kylheku 12-12-2009 06:47 PM

Re: how to know local port used in an udp client ?
 
On 2009-12-12, Antoninus Twink <nospam@nospam.invalid> wrote:
> On 12 Dec 2009 at 8:12, Greg2fs wrote:
>> Hello, I know the port used by my udp client to forward it using upnp.
>> How to do ?

>
> Use getsockname(2).


Note that getsockname may return zero for an empehemeral socket.
It's not a portable way of finding the actual port obtained.

> Or, choose which port to bind to yourself instead of letting the socket
> layer choose an available ephemeral port.


It's best to implement you write your own loop to scan the port space
for an available port, if you want a de-facto ephemeral port /and/ know
what it is in a portable way rather than relying on getsockname.
Moreover, you can control the allocation range this way, which you must
do if your client is to have any hope of getting out through some
firewalls.


All times are GMT. The time now is 12:05 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.