LinuxQuestions.org
Review your favorite Linux distribution.
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 04-25-2012, 03:48 AM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Rep: Reputation: 45
C(pure) Network programming questions


Dear all,
I am reading and programming these days sockets, which I find great.
I have some questions though If anyone wants to share the fun please join


a) I found that the maximum udp packet I can send is of 1607 bytes. A packet of 1608 will make sendto() to return -1. How I can find what are the maximum packet size for UDP and TCP? When the programmer has to care about the fragmentation?

b) I am using eclipse to write c When I start new c projects eclipse "asks" Do you want to use Cross gcc or Linux gcc. Where I can find more info regarding those differences?

c)
Code:
#include <sys/types.h>          /* See NOTES */
       #include <sys/socket.h>
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
I am not sure I fully understand the function definition of bind. The second parameters is a const struct sockaddr. Even though I made it work with (struct sockaddr*)&addr (where addr is struct sockaddr_in addr) I do not understand what is the reason for the constant. If I understand it right constant says I am only declared once and I cannot change (from web: "The const qualifier explicitly declares a data object as something that cannot be changed.")


d) In function prototypes like the c, the *datatype..."means": give me an address. Either by &mydatatype or *pointer=&mydatatype and then pass pointer. Right?

e) When I use funtions like socket, bind e.t.c I use perror to control when something went wrong. Example
Code:
if ((sockfd=socket(domain,type, protocol))==-1)
    	perror("socket initialization error");
If I understand it right perror only prints the error message but does not make the programn to exit. How you should make a c program to exit and with what error code?

f) When setting the port (of a socket) I use
Code:
	struct sockaddr_in addr;
	addr.sin_port= htons(33333);
I have found that htons works while htonl return a number that does not look like a valid port(at least not the one I wanted!) Of course this some mistake I do with the data types. The data type needed is the
Code:
in_port_t      sin_port;   /* port in network byte order */
. I have found that the in_port_t is a 32bit integet (I have read the .h files....) How I know if this should be treated as short or long? (Is that system specific?)


g) A typical thing in c is the number of warning one gets. I am not quite sure which ones you can ignore and which not. For example I found many times the "implicit declaration" ... how do you handle the warnings?

I would like to thank you in advance for the time spent
Regards
Alex
 
Old 04-25-2012, 03:53 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
e) http://pubs.opengroup.org/onlinepubs...ns/perror.html
see example also
 
  


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
Beej's Guide to Network programming (pure C) alaios Programming 16 09-04-2012 01:11 PM
Couple Questions (Squid Proxy + Pure-FTPD) OsiViper Debian 1 10-11-2006 04:36 PM
Network Programming Questions - please help pavgust Programming 2 03-29-2004 02:37 PM
pure-ftpd questions (several from many :) ) Dek Linux - Networking 0 04-29-2003 09:10 PM

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

All times are GMT -5. The time now is 06: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