LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 10-29-2003, 10:38 AM   #1
chabotrobert
LQ Newbie
 
Registered: Oct 2003
Posts: 1

Rep: Reputation: 0
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 !
 
Old 10-29-2003, 12:36 PM   #2
chort
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: Reputation: 76
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.
 
Old 02-20-2024, 02:36 AM   #3
nehapagare
LQ Newbie
 
Registered: Feb 2024
Posts: 1

Rep: Reputation: 0
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;
}
 
Old 02-24-2024, 08:54 PM   #4
elgrandeperro
Member
 
Registered: Apr 2021
Posts: 415
Blog Entries: 2

Rep: Reputation: Disabled
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.
 
Old 02-24-2024, 09:37 PM   #5
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,484

Rep: Reputation: 2649Reputation: 2649Reputation: 2649Reputation: 2649Reputation: 2649Reputation: 2649Reputation: 2649Reputation: 2649Reputation: 2649Reputation: 2649Reputation: 2649
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.
 
Old 02-25-2024, 12:28 AM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,568

Rep: Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865
If you look at the date of the OP it is 2003. Post #3 is new and unrelated to the OP.
 
Old 02-25-2024, 10:30 AM   #7
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,484

Rep: Reputation: 2649Reputation: 2649Reputation: 2649Reputation: 2649Reputation: 2649Reputation: 2649Reputation: 2649Reputation: 2649Reputation: 2649Reputation: 2649Reputation: 2649
Quote:
Originally Posted by michaelk View Post
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.
 
Old 02-25-2024, 04:19 PM   #8
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,099
Blog Entries: 6

Rep: Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot bind to socket: address already in use exfacior Linux - Wireless Networking 0 09-27-2004 12:34 PM
Help me with this socket address bind program. rnice Linux - Networking 0 09-17-2004 07:33 PM
Listening socket not released immediately Xagafinelle Programming 4 08-20-2004 05:28 PM
UDP server with socket listening on all IP addresses XTF Programming 0 06-04-2004 03:19 PM
Why is my socket unable to bind to the port in the C Code. mcp_achindra Programming 10 03-24-2004 08:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration