Results 1 to 3 of 3
HI I am starting to learnig network programming using ubuntu.
I have learnt some basic concepts .
I am now trying to build a simple socket.I learnt dat after creating ...
- 09-02-2010 #1Just Joined!
- Join Date
- May 2010
- Posts
- 22
begening network programming in linux
HI I am starting to learnig network programming using ubuntu.
I have learnt some basic concepts .
I am now trying to build a simple socket.I learnt dat after creating a simple socket we have to bind it some socket I have the following code but I cant quite get this
1.wat is bzero function
2.sizeof function
int bind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
/* retrieve the port number for listening
*/
simplePort = atoi(argv[1]);
/* set up the address structure */
/* use INADDR_ANY to bind to all local addresses */
/* note use of htonl() and htons() */
bzero(&simpleServer, sizeof(simpleServer));
simpleServer.sin_family = AF_INET;
simpleServer.sin_addr.s_addr = htonl(INADDR_ANY);
51
Chapter 2
simpleServer.sin_port = htons(simplePort);
/*
bind to the address and port with our socket
*/
returnStatus = bind(simpleSocket,
(struct sockaddr *)&simpleServer,
sizeof(simpleServer));
if (returnStatus == 0) {
fprintf(stderr, "Bind completed!\n");
}
else {
fprintf(stderr, "Could not bind to address!\n");
close(simpleSocket);
exit(1);
}
- 09-02-2010 #2Debian GNU/Linux -- You know you want it.
- 09-20-2010 #3Just Joined!
- Join Date
- Sep 2010
- Posts
- 5
bzero is a function that initializes the structure to zero.
sizeof is the another function which calculates the size of the structure.


Reply With Quote
