Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to know local port used in an udp client ?

2 views
Skip to first unread message

Greg2fs

unread,
Dec 12, 2009, 3:12:56 AM12/12/09
to
Hello, I know the port used by my udp client to forward it using upnp.
How to do ?

Thanks

Kenny McCormack

unread,
Dec 12, 2009, 5:52:55 AM12/12/09
to

Greg2fs

unread,
Dec 12, 2009, 11:05:57 AM12/12/09
to
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...

Richard Heathfield

unread,
Dec 12, 2009, 11:18:40 AM12/12/09
to
In
<6ca6c384-697c-450b...@d20g2000yqh.googlegroups.com>,
Greg2fs wrote:

> On 12 d�c, 11:52, gaze...@shell.xmission.com (Kenny McCormack)

What Kenny is trying to tell you in as objectionable a way as possible
is that your question is actually about the Berkeley sockets API
rather than about the C language. He's right - which is a novel
experience for him - but he could have been infinitely more gracious
about it. Your best bet is probably comp.unix.programmer - even if
you're developing under Win32, for a sockets question you're more
likely to get a good answer in c.u.p than elsewhere.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within

Kenny McCormack

unread,
Dec 12, 2009, 11:32:25 AM12/12/09
to
In article <6ca6c384-697c-450b...@d20g2000yqh.googlegroups.com>,
Greg2fs <gre...@gmail.com> wrote:

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!

Richard

unread,
Dec 12, 2009, 11:36:30 AM12/12/09
to
gaz...@shell.xmission.com (Kenny McCormack) writes:

Indeed.

But first we need to see some of your code using malloc and the
definition of main().

--
"Avoid hyperbole at all costs, its the most destructive argument on
the planet" - Mark McIntyre in comp.lang.c

Barry Schwarz

unread,
Dec 12, 2009, 11:45:35 AM12/12/09
to
On Sat, 12 Dec 2009 08:05:57 -0800 (PST), Greg2fs <gre...@gmail.com>
wrote:

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

Richard

unread,
Dec 12, 2009, 12:36:21 PM12/12/09
to
Barry Schwarz <schw...@dqel.com> writes:

> On Sat, 12 Dec 2009 08:05:57 -0800 (PST), Greg2fs <gre...@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

Wrong. This group is about all C related programming as defined in its
founding charter.

There is no better group to learn about using C and assocated tools and
methods : there a many people with cross platform skills here whereas
"specific" groups tend to be filled with pedantic nit pickers with a
very blinkered view.

> perform system specific tasks. Since the C language as defined in the
> ISO standard has no support for ports, udp, or upnp, your question

What nonsense. These things are written in C more often than not and
more often than not are used using C.

> falls into the latter category. You will get much better responses if
> you post the question in a group that deals with upnp.

Would you like to name a few?

To the OP : if its C related post here. If no one knows then you can
look further afield.

Antoninus Twink

unread,
Dec 12, 2009, 12:36:25 PM12/12/09
to
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

unread,
Dec 12, 2009, 12:42:55 PM12/12/09
to
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...

Richard

unread,
Dec 12, 2009, 1:06:03 PM12/12/09
to
Antoninus Twink <nos...@nospam.invalid> writes:

Indeed.

I often wonder why I am unable to see "ISO" in the group's name. It must
be there. Surely.

Seebs

unread,
Dec 12, 2009, 1:32:12 PM12/12/09
to
On 2009-12-12, Greg2fs <gre...@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...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!

Antoninus Twink

unread,
Dec 12, 2009, 1:43:45 PM12/12/09
to
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

unread,
Dec 12, 2009, 1:47:34 PM12/12/09
to
On 2009-12-12, Antoninus Twink <nos...@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.

Richard

unread,
Dec 12, 2009, 1:47:37 PM12/12/09
to
Antoninus Twink <nos...@nospam.invalid> writes:

Is this Seebs guy a Heathfield sock? He has all the mannerisms and
annoying starchiness.

Kenny McCormack

unread,
Dec 12, 2009, 1:50:35 PM12/12/09
to
In article <slrnhi7p31...@nospam.invalid>,

Antoninus Twink <nos...@nospam.invalid> wrote:
>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.

To be fair, their position *is* consistent and logical, given their
definition(s). It's just that their definition(s) is/are ludicrous.

Kenny McCormack

unread,
Dec 12, 2009, 1:53:18 PM12/12/09
to
In article <hg0oga$lgb$1...@news.eternal-september.org>,
Richard <rgr...@gmail.com> wrote:
...

>Is this Seebs guy a Heathfield sock? He has all the mannerisms and
>annoying starchiness.

To be fair, I don't *think* he is a sock. But he (Petey) certainly has
found a friend...!

I think it is fairly well documented that they suffer from the same (or
very similar) neuroses.

Message has been deleted

Nobody

unread,
Dec 12, 2009, 3:29:48 PM12/12/09
to
On Sat, 12 Dec 2009 18:43:45 +0000, Antoninus Twink wrote:

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

Windows has something which looks superficially similar to the BSD
socket functions.

However, BSD sockets aren't a stand-alone API, but extensions to the Unix
API. The value returned from socket() (and accept()) is a file descriptor
(a small, non-negative integer, so you can use it as an array index),
which can be passed to read(), write(), fdopen(), close(), dup() etc.

Greg2fs

unread,
Dec 12, 2009, 3:59:06 PM12/12/09
to
I don't use to talk on newsgroups from long but with all these answers
I think I will continue, and it seems than this newsgroup correspond
to my request as I get answers...

I din't know I could use bind for a client, but it works, this way I
choose the port I want, thanks !

Kenny McCormack

unread,
Dec 12, 2009, 4:07:28 PM12/12/09
to
In article <hg0pll$os0$1...@news.eternal-september.org>,
Beej Jorgensen <be...@beej.us> wrote:
>Note the size of this "keep it on topic" subthread compared to that of
>the subthread that contains the actual answer.
>
>With a cure like this, who needs a disease?
>
>-Beej
>

That's exactly my point. First of all, by posting my little thing that
started the sub-thread, I was just doing, virtually word-for-word, what
the regs would do. So, I am simply performing a service; saving them
the trouble. Second, that's how it always happens. Search the
archives. You will find innumerable, virtually endless, threads about
topicality. On and on.

Their stated goal is to minimize the traffic. Yet, they pretend to be
blithely unaware of the fact that if they either a) just ignored the
threads they don't wish to respond to or b) just gave the d*** answer,
the traffic would be much less. Preferably the later, of course, but
certainly the former is preferable to these topicality rants.

Richard Heathfield

unread,
Dec 12, 2009, 4:15:28 PM12/12/09
to

> On 2009-12-12, Greg2fs <gre...@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...

Actually, that's not the case. Windows supports the Berkeley Sockets
API so closely that it only takes a few lines of abstraction to fix
it up completely.

Keith Thompson

unread,
Dec 12, 2009, 4:07:32 PM12/12/09
to
Greg2fs <gre...@gmail.com> writes:
> I don't use to talk on newsgroups from long but with all these answers
> I think I will continue, and it seems than this newsgroup correspond
> to my request as I get answers...

As several people have tried to tell you, on the particular topic
you're asking about you're likely to get more and better answers
in comp.unix.programmer.

Your question really isn't about the C language, which is what we
(try to) discuss here. There are C implementations that don't
support sockets, and there are implementations of sockets for
languages other than C.

[...]

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Keith Thompson

unread,
Dec 12, 2009, 4:20:52 PM12/12/09
to
Keith Thompson <ks...@mib.org> writes:
> Greg2fs <gre...@gmail.com> writes:
>> I don't use to talk on newsgroups from long but with all these answers
>> I think I will continue, and it seems than this newsgroup correspond
>> to my request as I get answers...
>
> As several people have tried to tell you, on the particular topic
> you're asking about you're likely to get more and better answers
> in comp.unix.programmer.

Richard Heathfield says that Windows has good support for the
Berkeley Sockets API, so comp.os.ms-windows.programmer.win32 might
also be a good source of information.

Richard

unread,
Dec 12, 2009, 4:24:11 PM12/12/09
to
Richard Heathfield <r...@see.sig.invalid> writes:

> In <slrnhi7oee.4ve...@guild.seebs.net>, Seebs wrote:
>
>> On 2009-12-12, Greg2fs <gre...@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...
>
> Actually, that's not the case. Windows supports the Berkeley Sockets
> API so closely that it only takes a few lines of abstraction to fix
> it up completely.

So in some ways Seebs was right. You will get wrong answers here. But
as usual from the ones telling people not to ask here ....

Hint to the topic Nazis : if you cant help then don't. Shut up and let
others if they so wish.

Chad

unread,
Dec 12, 2009, 5:14:27 PM12/12/09
to
On Dec 12, 10:43 am, Antoninus Twink <nos...@nospam.invalid> wrote:
> 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.
>

Let me quote Dr. Richtie

"C offers only straightforward, single-thread control flow: tests,
loops, grouping, and subprograms, but not multiprogramming, parallel
operations, synchronization, or coroutines."

Chad

unread,
Dec 12, 2009, 5:16:56 PM12/12/09
to

Eeerrr Dr. Ritchie.

Antoninus Twink

unread,
Dec 12, 2009, 5:20:17 PM12/12/09
to
On 12 Dec 2009 at 21:07, Keith Thompson wrote:
> As several people have tried to tell you, on the particular topic
> you're asking about you're likely to get more and better answers
> in comp.unix.programmer.

A false assertion doesn't magically become true by dint of repetition ad
nauseam, Kiki.

The OP's question has been answered in detail here - why should he
listen to your unwelcoming and unhelpful "recommendations"?

> There are C implementations that don't support sockets, and there are
> implementations of sockets for languages other than C.

There are C implementations that don't support printf, and there are
implementations of printf for languages other than C. Are we to infer
that printf is "off topic" in your opinion?

Richard

unread,
Dec 12, 2009, 5:22:35 PM12/12/09
to
Chad <cda...@gmail.com> writes:

So what? What has that got to do with an API you moron?

It also doesn't have linked lists.

What is your point?

Chad

unread,
Dec 12, 2009, 5:29:28 PM12/12/09
to
On Dec 12, 2:22 pm, Richard <rgrd...@gmail.com> wrote:

> Chad <cdal...@gmail.com> writes:
> > On Dec 12, 10:43 am, Antoninus Twink <nos...@nospam.invalid> wrote:
> >> 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.
>
> > Let me quote Dr. Richtie
>
> > "C offers only straightforward, single-thread control flow: tests,
> > loops, grouping, and subprograms, but not multiprogramming, parallel
> > operations, synchronization, or coroutines."
>
> So what? What has that got to do with an API you moron?
>
> It also doesn't have linked lists.
>
> What is your point?
>

It seems like Dr. Ritchie doesn't seem to include API's in his
(original) definition of the C Programming Language.

Chad

unread,
Dec 12, 2009, 5:30:30 PM12/12/09
to

And yes, my grammar bites.

Flash Gordon

unread,
Dec 12, 2009, 5:39:23 PM12/12/09
to
Beej Jorgensen wrote:
> Note the size of this "keep it on topic" subthread compared to that of
> the subthread that contains the actual answer.
>
> With a cure like this, who needs a disease?

The people who complain that posts pointing out that something is
off-topic are adding noise to the group always fail to realise that they
are adding noise themselves.
--
Flash Gordon

Phil Carmody

unread,
Dec 12, 2009, 6:03:19 PM12/12/09
to
Beej Jorgensen <be...@beej.us> writes:
> Note the size of this "keep it on topic" subthread compared to that of
> the subthread that contains the actual answer.
>
> With a cure like this, who needs a disease?

Which is why I'm pretty sure most of such questions are trolls.

Phil
--
Any true emperor never needs to wear clothes. -- Devany on r.a.s.f1

Seebs

unread,
Dec 12, 2009, 6:28:31 PM12/12/09
to
On 2009-12-12, Chad <cda...@gmail.com> wrote:
> On Dec 12, 10:43�am, Antoninus Twink <nos...@nospam.invalid> wrote:
>> On 12 Dec 2009 at 18:32, Seebs wrote:

>> > The C language doesn't have sockets.

>> Nonsense.

(Interestingly, while he presumably actually wrote the word, you can also
treat this as a metasyntactic summary of Twink's post.)

>> Are you trying to argue that

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

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

> Let me quote Dr. Richtie
>
> "C offers only straightforward, single-thread control flow: tests,
> loops, grouping, and subprograms, but not multiprogramming, parallel
> operations, synchronization, or coroutines."

To put it another way:

static int raw_to_hex(FILE *fp);

is also a C API. So's:

void parse(char *s);

Doesn't mean that they're part of the C language, or that C has those
particular features.

Richard

unread,
Dec 12, 2009, 8:00:27 PM12/12/09
to
Flash Gordon <sm...@spam.causeway.com> writes:

And those that lecture people on topicality invariably make more noise
than those asking "off topic" questions.

I am not surprised you don't see the difference between some big headed
net nanny telling people to fuck off and the people that say, no YOU
fuck off, and we ARE open to a wider variety of questions.

Greg2fs

unread,
Dec 13, 2009, 2:30:50 AM12/13/09
to
Thanks for all the message, I will add comp.os.ms-
windows.programmer.win32 and comp.unix.programmer to my newsgroup for
next times, I'm new and I didn't know them.
0 new messages