LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 02-16-2008, 01:05 PM   #1
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Rep: Reputation: 30
simple c help


hello...
I've been trying to solve those warnings, please advise me...
I've tried for hours, I'd appreciate your help!
Thanks and sorry for being a noob./


Code:
zuki @ LookBusy programming] $ gcc main.c
main.c: In function 'main':
main.c:18: warning: incompatible implicit declaration of built-in function 'bzero'
main.c:29: warning: passing argument 3 of 'accept' makes pointer from integer without a cast
Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

int main(int argc,char ** argv[])
{
	int nCheck;

	struct sockaddr_in _saddress, _caddress; // structure containing an internet address

	if (2 != argc)
	{
		printf("USAGE:\n%s port_to_listen",argv[0]);
		return 1;
	}
	int nSocketfd = socket(PF_INET,	SOCK_STREAM,0);
	bzero(&_saddress, sizeof(struct sockaddr_in)); // initializes _saddress to zero
	int nPort = atoi(argv[1]); // convrting the port from a string to integer
	_saddress.sin_addr.s_addr = INADDR_ANY; // initializes to the ip address of the machine on which the server is running
	_saddress.sin_port = htons(nPort); // converts port from host-byte to network-byte
	_saddress.sin_family = AF_INET; // initializes address family to IPv4
	if (bind(nSocketfd, (struct sockaddr *) &_saddress, sizeof(struct sockaddr_in)) < 0) 
	{
		perror("binding error");
		return 1;
	}
	int nLis = listen(nSocketfd, 50);
	int nfdAccept = accept(nSocketfd, (struct sockaddr *) &_saddress, sizeof(struct sockaddr_in));
	return 0;
}

Thanks for helping.
 
Old 02-16-2008, 01:27 PM   #2
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
For the bzero function:

Code:
#include <strings.h>
For the accept problem, man accept gives accepts prototype as:
Code:
 int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
The 3rd argument is a pointer to a "socklen_t". So, I would do this:

Code:
/* Somewhere earlier */
socklen_t addrlen;

...

addrlen = sizeof(struct sockaddr_in);
int nfdAccept = accept(nSocketfd, (struct sockaddr *) &_saddress, &addrlen);
 
  


Reply



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
Need help getting started simple simple shell script dhonnoll78 Programming 6 12-17-2007 05:34 PM
Ubuntu Fluxbox simple question, simple answer? generallimptoes Linux - Software 3 09-26-2005 02:03 PM
problems creating a simple bootable cd to perform a simple task czarherr Linux - Software 1 11-11-2004 05:22 AM
Installing Programs - A simple question from my simple mind jmp875 Linux - Newbie 6 02-18-2004 09:03 PM
simple question seeking simple answer enzo250gto Linux - Newbie 1 10-27-2001 04:08 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:31 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
Open Source Consulting | Domain Registration