Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How can I open a listen socket @port 80?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
vespaman
Guru
Guru


Joined: 28 Aug 2002
Posts: 346
Location: Stockholm, Sweden

PostPosted: Mon Dec 08, 2008 8:20 am    Post subject: How can I open a listen socket @port 80? Reply with quote

I am doing som development work in C (a web server for embedded electronics), but I have some issues with opening the port.
If I instead open a port above 1024, all is fine, but I need to test this at the correct port.

Somewhere else, someone recommended to 'chmod +s' on the program, but this does not work for me. Not sure if I do something wrong, or if this is a Gentoo thing?

It turns out that I cannot even run my program as root, as long as I try to use port 80! It fails at binding the listen socket.

My software uses aliased ethernet devices (10 of them), which I communicate fine over (I start up to 10 instances of my program, and see that each instance communicates fine with the other ones over the aliased devices) so I think the NIC setup in general is working fine.

So this is somehow a rights problem, I think.

But what am I missing?
Back to top
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9523
Location: beyond the rim

PostPosted: Mon Dec 08, 2008 9:29 am    Post subject: Reply with quote

Well, for listening on ports < 1024 you (in general) need superuser priviledges. So make sure that your program runs as uid 0 when it attemtps to open the port. If it still doesn't work you'll have to provide more information, like error messages and the relevant code (if possible).
Back to top
View user's profile Send private message
vespaman
Guru
Guru


Joined: 28 Aug 2002
Posts: 346
Location: Stockholm, Sweden

PostPosted: Mon Dec 08, 2008 9:54 am    Post subject: Reply with quote

Excellent!

Now I have it working after some testing with your input as base.

I have to first 'chown 0:users myprogram'

and then;

'chmod +s myprogram'

in that order and it then works! :D

Is there any way of doing this from within kdevelop? As it is now, each new 'make' erases these settings.
Edit: Actually, it does not seem to work from within kdevelop, I guess, that's because gdb does not pick up the changes I made to the file generated?
Back to top
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9523
Location: beyond the rim

PostPosted: Mon Dec 08, 2008 12:02 pm    Post subject: Reply with quote

Any particular reason you can't run your program from inside a root shell? Setting it SUID like you did, so it always runs as root no matter who starts it, generally isn't such a good idea, and doesn't work when you run your program via another tool like strace or gdb.
Back to top
View user's profile Send private message
vespaman
Guru
Guru


Joined: 28 Aug 2002
Posts: 346
Location: Stockholm, Sweden

PostPosted: Mon Dec 08, 2008 2:42 pm    Post subject: Reply with quote

Hmm :oops:

Not really sure what I am doing.. This morning it would not work just executing using sudo, but now it seams to work just fine.
The only boring thing with this, is that I will have to start all instances with sudo.

I guess I need to start kdevelop with sudo as well, or is there a better way?
Back to top
View user's profile Send private message
easy target
Tux's lil' helper
Tux's lil' helper


Joined: 09 Jan 2008
Posts: 134

PostPosted: Mon Dec 08, 2008 6:02 pm    Post subject: Reply with quote

Why can't you run your application on unpriviledged port, say 8080 during development and only set to 80 when preparing release?
Back to top
View user's profile Send private message
Captain Newbie
Apprentice
Apprentice


Joined: 22 Dec 2006
Posts: 182
Location: Socal

PostPosted: Mon Dec 08, 2008 6:08 pm    Post subject: Reply with quote

easy target wrote:
Why can't you run your application on unpriviledged port, say 8080 during development and only set to 80 when preparing release?

Indeed. I would prefer to not run testing software on well known ports. :)
_________________
/* Nobody will ever see this message :-) */
panic("Cannot initialize video hardware\n");
"As much as it pains me, we hope that developers know what they're doing." - wolf31o2
Back to top
View user's profile Send private message
vespaman
Guru
Guru


Joined: 28 Aug 2002
Posts: 346
Location: Stockholm, Sweden

PostPosted: Mon Dec 08, 2008 7:50 pm    Post subject: Reply with quote

Yes, this is what I have done so far. But I normally like to test software as close to the reality of where it will live already from start. I don't really see any negative in doing that.
But of course, I don't like the su/sudo solution too much either... :)

Thanks

Micael
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21607

PostPosted: Tue Dec 09, 2008 4:26 am    Post subject: Reply with quote

As Genone said, start a root shell. You can then run your program from that shell and it will have root privileges, without the need to use sudo or to set the setuid bit.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum