View previous topic :: View next topic |
Author |
Message |
vespaman Guru
Joined: 28 Aug 2002 Posts: 346 Location: Stockholm, Sweden
|
Posted: Mon Dec 08, 2008 8:20 am Post subject: How can I open a listen socket @port 80? |
|
|
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 |
|
|
Genone Retired Dev
Joined: 14 Mar 2003 Posts: 9523 Location: beyond the rim
|
Posted: Mon Dec 08, 2008 9:29 am Post subject: |
|
|
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 |
|
|
vespaman Guru
Joined: 28 Aug 2002 Posts: 346 Location: Stockholm, Sweden
|
Posted: Mon Dec 08, 2008 9:54 am Post subject: |
|
|
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!
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 |
|
|
Genone Retired Dev
Joined: 14 Mar 2003 Posts: 9523 Location: beyond the rim
|
Posted: Mon Dec 08, 2008 12:02 pm Post subject: |
|
|
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 |
|
|
vespaman Guru
Joined: 28 Aug 2002 Posts: 346 Location: Stockholm, Sweden
|
Posted: Mon Dec 08, 2008 2:42 pm Post subject: |
|
|
Hmm
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 |
|
|
easy target Tux's lil' helper
Joined: 09 Jan 2008 Posts: 134
|
Posted: Mon Dec 08, 2008 6:02 pm Post subject: |
|
|
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 |
|
|
Captain Newbie Apprentice
Joined: 22 Dec 2006 Posts: 182 Location: Socal
|
Posted: Mon Dec 08, 2008 6:08 pm Post subject: |
|
|
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 |
|
|
vespaman Guru
Joined: 28 Aug 2002 Posts: 346 Location: Stockholm, Sweden
|
Posted: Mon Dec 08, 2008 7:50 pm Post subject: |
|
|
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 |
|
|
Hu Moderator
Joined: 06 Mar 2007 Posts: 21607
|
Posted: Tue Dec 09, 2008 4:26 am Post subject: |
|
|
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 |
|
|
|