LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 10-29-2002, 10:45 AM   #1
pfpalmer
LQ Newbie
 
Registered: Oct 2002
Posts: 2

Rep: Reputation: 0
netstat doesn't show tcp sockets in Redhat 7.2


The following program, taken straight out of a
book does not provide the expected result which is to display the created socket.
The program works fine in Redhat 6.1. Has anyone else
seen this problem and does anyone know if this works
in Redhat 8.0.

If RH 8.0 works I will just upgrade.
If someone can point me to howto concerning the correct method to FTPing the ISO files that would be a big help.
I have successfully downloaded the files and burned the CDs
but when I try to boot it doesn't seem to work.
I'm not sure if the problem is with the download method or the boot procedure.

Any and all comments welcome.

/* inetaton.c:
*
* Example using inet_aton(3) :
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

/*
* This function reports the error and
* exits back to the shell :
*/
static void
bail(const char *on_what) {
fputs(on_what,stderr);
fputc('\n',stderr);
exit(1);
}

int
main(int argc,char **argv) {
int z;
struct sockaddr_in adr_inet;/* AF_INET */
int len_inet; /* length */
int sck_inet; /* Socket */

/* Create a Socket */
sck_inet = socket(AF_INET,SOCK_STREAM,0);

if ( sck_inet == -1 )
bail("socket()");

/* Establish address */
memset(&adr_inet,0,sizeof adr_inet);

adr_inet.sin_family = AF_INET;
adr_inet.sin_port = htons(9000);

if ( !inet_aton("127.0.0.23",
&adr_inet.sin_addr) )
bail("bad address.");

len_inet = sizeof adr_inet;

/* Bind it to the socket */
z = bind(sck_inet,
(struct sockaddr *)&adr_inet,
len_inet);

if ( z == -1 )
bail("bind()");

/* Display our socket address */
system("netstat -pa --tcp 2>/dev/null"
"| grep inetaton");

return 0;
}
 
Old 10-30-2002, 11:31 AM   #2
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 46
That's because you haven't fully put the socket in the listening state yet. Add the following line after the bind:

listen(sck_inet, 5);
 
Old 10-30-2002, 12:44 PM   #3
pfpalmer
LQ Newbie
 
Registered: Oct 2002
Posts: 2

Original Poster
Rep: Reputation: 0
I added "listen(sck_inet,5)" to the program but it seems to have no effect.
If I modify the netstat parms I can see the other sockets.
I have Redhat 6.1 on my other PC and the identical prgram works as expected.
At the moment I am downloading Redhat 8.0 and hope that when I upgrade this problem will go away.
I am working through some socket programming tutorials and so this problem is holding me back.

Thankyou for taking the time to respond.

Paul
 
Old 10-31-2002, 04:04 AM   #4
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 46
Well I don't actually have any Redhat machines here to test it on. I tested it on Suse. But what kind of line is displayed when you run it in Redhat 6.2? Particularly what state it's in. It shouldn't be in the listen state yet. Is the executable named inetaton otherwise the grep part wouldn't really work.
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Netstat issues 'warning, got duplicate tcp line' English_Man Linux - Networking 5 04-13-2009 04:07 AM
TCP Network Sockets Rakoon Red Hat 1 08-04-2005 01:36 AM
sockets & netstat Ikebo Programming 1 07-11-2004 11:19 PM
netstat, how to show what address are connected? trey85stang Slackware 2 12-30-2003 03:56 PM
Maximum TCP-Sockets Quis Linux - Networking 2 01-17-2003 04:55 AM


All times are GMT -5. The time now is 10:26 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration