Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-29-2003, 11:38 AM
|
#1
|
LQ Newbie
Registered: Oct 2003
Posts: 1
Rep:
|
Could not bind listening socket
RedHat 9
vsftpd running ok through xinetd
verified that listening on port 21
On any client when ftp <servername> with any allowed user we get :
"500 OOPS Could not bind listening socket"
Tried all kind of searches with (usually responsive) Google but got nothing explaining/correcting. If it happened on the server i would understand, the daemon may not be able to start on port 21 if something else is on it etc.... but when trying to connect from another machine ???
Any ideas would be welcomed !
|
|
|
10-29-2003, 01:36 PM
|
#2
|
Senior Member
Registered: Jul 2003
Location: Silicon Valley, USA
Distribution: OpenBSD 4.6, OS X 10.6.2, CentOS 4 & 5
Posts: 3,660
Rep:
|
Hmmm, the only thing I can think of is that it's using Active Mode FTP by default, which uses port 20 for data. It might be trying to bind to port 20 locally, but if your daemon has dropped root privilages it won't be able to open a port < 1024. Have the clients try the "PASV" or "passive" command immediately after connecting. That *should* use a high port and ought to be able to bind OK.
|
|
|
02-20-2024, 03:36 AM
|
#3
|
LQ Newbie
Registered: Feb 2024
Posts: 1
Rep:
|
error binding port
I have used this code but showing error binding port for all ports please help me with this
/* A simple server in the internet domain using TCP
The port number is passed as an argument */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
void error(const char *msg)
{
perror(msg);
exit(1);
}
int main(int argc, char *argv[])
{
int sockfd, newsockfd, portno;
socklen_t clilen;
char buffer[256];
struct sockaddr_in serv_addr, cli_addr;
int n;
if (argc < 2) {
fprintf(stderr,"ERROR, no port provided\n");
exit(1);
}
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
error("ERROR opening socket");
bzero((char *) &serv_addr, sizeof(serv_addr));
portno = atoi(argv[1]);
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(portno);
if (bind(sockfd, (struct sockaddr *) &serv_addr,
sizeof(serv_addr)) < 0)
error("ERROR on binding");
listen(sockfd,5);
clilen = sizeof(cli_addr);
newsockfd = accept(sockfd,
(struct sockaddr *) &cli_addr,
&clilen);
if (newsockfd < 0)
error("ERROR on accept");
bzero(buffer,256);
n = read(newsockfd,buffer,255);
if (n < 0) error("ERROR reading from socket");
printf("Here is the message: %s\n",buffer);
n = write(newsockfd,"I got your message",18);
if (n < 0) error("ERROR writing to socket");
close(newsockfd);
close(sockfd);
return 0;
}
|
|
|
02-24-2024, 09:54 PM
|
#4
|
Member
Registered: Apr 2021
Posts: 433
Rep: 
|
I assume your test is a non-privileged user binding to a port >1024 as a daemon? Do you run selinux? If so, I believe you have to add a rule to bind to the port.
|
|
|
02-24-2024, 10:37 PM
|
#5
|
LQ Guru
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 6,081
|
And just for the record, I hope you mean RHEL 9 and not RedHat 9.
As I recall RH9 went out of support in 2001 or 2002, while RHEL9 was just released in 2022.
|
|
|
02-25-2024, 01:28 AM
|
#6
|
Moderator
Registered: Aug 2002
Posts: 26,520
|
If you look at the date of the OP it is 2003. Post #3 is new and unrelated to the OP.
|
|
|
02-25-2024, 11:30 AM
|
#7
|
LQ Guru
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 6,081
|
Quote:
Originally Posted by michaelk
If you look at the date of the OP it is 2003. Post #3 is new and unrelated to the OP.
|
Did not look for that, and now I just feel silly! ;-) Thank you michaelk.
|
|
|
02-25-2024, 05:19 PM
|
#8
|
LQ Guru
Registered: Oct 2004
Distribution: Arch
Posts: 5,361
|
Post #3. How about not posting a mess that no one can read.
BindPort.c
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
void error(const char *msg) {
perror(msg);
exit(1);
}
int main(int argc, char *argv[])
{
int sockfd, newsockfd, portno;
socklen_t clilen;
char buffer[256];
struct sockaddr_in serv_addr, cli_addr;
int n;
if (argc < 2) {
fprintf(stderr,"ERROR, no port provided\n");
exit(1);
}
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
error("ERROR opening socket");
bzero((char *) &serv_addr, sizeof(serv_addr));
portno = atoi(argv[1]);
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(portno);
if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
error("ERROR on binding");
listen(sockfd,5);
clilen = sizeof(cli_addr);
newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
if (newsockfd < 0)
error("ERROR on accept");
bzero(buffer,256);
n = read(newsockfd,buffer,255);
if (n < 0)
error("ERROR reading from socket");
printf("Here is the message: %s\n",buffer);
n = write(newsockfd,"I got your message",18);
if (n < 0) error("ERROR writing to socket");
close(newsockfd);
close(sockfd);
return 0;
}
//gcc BindPort.c -o BindPort
That appears to work.
Code:
./BindPort 8100
ss -tuna
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
tcp LISTEN 0 5 0.0.0.0:8100 0.0.0.0:*
tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
tcp LISTEN 0 128 [::]:22 [::]:*
And when making a request on the port.
Code:
./BindPort 8100
Here is the message: GET / HTTP/1.1
Host: 127.0.0.1:8100
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 17_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/119.0.6045.109 Mobile/15E148 Safari/604.1
|
|
|
All times are GMT -5. The time now is 05:02 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|