LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-03-2006, 05:46 AM   #1
nickraj
LQ Newbie
 
Registered: Sep 2006
Location: usa
Posts: 25

Rep: Reputation: 15
command line arguments


hi

i have just started learning unix. I an making a client server program in c. two command line arguments argv[2] , argv[3] will have the ip address and port no , i m compiling the programm by gcc -lsocket 127.0.0.1 15000 a binding error is comming. Is there some problem in the following code
server.sin_port=htons(argv[3]);
server.sin_addr=htonl(argv[2]);
i am not able to figure it out

nick
 
Old 09-03-2006, 05:55 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You're supposed to be passing the arguments when you run the program, not when you compile it, surely?
 
Old 09-04-2006, 04:05 AM   #3
nickraj
LQ Newbie
 
Registered: Sep 2006
Location: usa
Posts: 25

Original Poster
Rep: Reputation: 15
command line

Is program mane is also taken as commandline argument
 
Old 09-04-2006, 04:13 AM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Edit: assuming by "program mane", you mean the filename, e.g. "program.c", then yes, of course you need to pass that to gcc. Otherwise, how will it know which file you want to compile?

Last edited by Nylex; 09-04-2006 at 04:31 AM.
 
Old 09-04-2006, 04:47 AM   #5
w3bd3vil
Senior Member
 
Registered: Jun 2006
Location: Hyderabad, India
Distribution: Fedora
Posts: 1,189

Rep: Reputation: 49
lol
you need to first compile the program
gcc -o nickraj filename.c
then
./nickraj 127.0.0.1 15000
 
Old 09-10-2006, 08:03 PM   #6
nickraj
LQ Newbie
 
Registered: Sep 2006
Location: usa
Posts: 25

Original Poster
Rep: Reputation: 15
error

hi
The program work when i give default ip (127.0.0.1) but when i use host name of server at client side(gethostbyname() ) it gives segmentation error while if i use the ip at client , connection error., occur.


i am using INADDR_ANY at server side cant i use server.sin_addr.s_addr=htonl(atoi(argv[1])); where server is struct sockaddr_in type and argv[1] is the ip address of server.
 
Old 09-11-2006, 02:01 PM   #7
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Maybe you should post all your code, so people can check it.
 
  


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
alsamixer command line arguments dereko Debian 3 09-29-2008 03:06 PM
command line arguments containing ( Lotharster Linux - Newbie 3 01-05-2006 09:43 AM
Awk command-line arguments lowpro2k3 Programming 1 03-28-2005 10:09 PM
Help with command line arguments ? synapse Linux - Newbie 2 02-23-2004 03:25 AM
Command line arguments to java program Majjj Programming 3 10-23-2003 06:48 AM


All times are GMT -5. The time now is 11:01 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration