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.
int main()
{
int j;
int sockfd;
struct sockaddr_in Target;
Target.sin_family=AF_INET;
Target.sin_port=htons(DATA_PORT);
Target.sin_addr.s_addr=inet_addr("192.168.0.3");
if((sockfd=socket(AF_INET,SOCK_DGRAM,0))==-1)
{
printf("\n Socket for data msgs cannot be created\n");
exit(-1);
}
if(bind(sockfd,(struct sockaddr*)&Target,sizeof(Target))==-1)
{
perror("\n Data socket cannot be binded to OS\n");
Exit(-1);
}
Please post all code in code tags ([ code ] this is code [ / code ] -- without the spaces) if you want people to read it (and please don't post anything you don't want people to read). Also, your question is related to programming, so it really belongs in the Programming (sub)forum.
grovel through the headers in decreasing order of relevance to see if they define the relevant struct (sockaddr_in, right?). 'grep -C 4 sockaddr_in <filename>' might come in handy.
int main()
{
int j;
int sockfd;
struct sockaddr_in Target;
Target.sin_family=AF_INET;
Target.sin_port=htons(DATA_PORT);
Target.sin_addr.s_addr=inet_addr("192.168.0.3");
if((sockfd=socket(AF_INET,SOCK_DGRAM,0))==-1)
{
printf("\n Socket for data msgs cannot be created\n");
exit(-1);
}
if(bind(sockfd,(struct sockaddr*)&Target,sizeof(Target))==-1)
{
perror("\n Data socket cannot be binded to OS\n");
Exit(-1);
}
ssize_t recvmsg(int s, struct msghdr *msg, int flags);
<= On your platform, "socklen_t" happens to be unsigned, and the C/C++
standard dictates that an int pointer should be flagged as "incompatible" with
an unsigned int pointer, hence the need to cast (unsigned int *)
Tanks for you very very much for helping me to correct the error in my codes,but when I running this programs (sender&receiver),message appear at the bottom of debugger window:
The debugger can't find symbol list for the library. It's understandable (they take space) and should not cause any harm (only if something fails in that library - debugging may be harder).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.