ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language 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.
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.
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;
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.