Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

error binding try to communicate on IRIX

Posted on 1997-09-01
1
Medium Priority
?
263 Views
Last Modified: 2013-12-23
You ask...
              What am I doing wrong ? My code is :

              include <fcntl.h>
              #include <unistd.h>
              #include <stdio.h>
              #include <stdlib.h>
              #include <sys/types.h>
              #include <stdio.h>
              #include <stdlib.h>
              #include <sys/types.h>
              #include <sys/uio.h>
              #include <bstring.h>
              #include <sys/time.h>
              #include <netinet/in.h>
              #include <sys/socket.h>
              #include <string.h>
              #include <iostream.h>
              #include <errno.h>
              extern "C" {
              extern unsigned int inet_addr(char *string);
              }

              void main()
              {
              int SockFd,Rc,NewFd,len,lis;
              int Port = 9989;
              char addr[20] = "192.114.248.101";
              struct sockaddr_in in;

              //init sockaddr_in fields
              in.sin_family = AF_INET;
              cout << "in.sin_family = " << in.sin_family << "\n";
              in.sin_addr.s_addr = inet_addr(addr);
              cout << "in.sin_addr.s_addr = " << in.sin_addr.s_addr <<
              "\n";
              in.sin_port = htons(Port);
              cout << "in.sin_port = " << in.sin_port << "\n";

              // create socket
              SockFd = socket(AF_INET,SOCK_STREAM,0);
              cout << "SockFd is : " << SockFd << "\n";

              // make the binding
              //fcntl(SockFd,F_SETFL,FNDELAY);
              //unlink(sin.sa_data);
              Rc = bind(SockFd,(struct sockaddr_in *)&in
              ,sizeof(sockaddr_in));
              cout << "Rc is : " << Rc << "\n";
              cout << "Error is : " << strerror(errno) << "\n";

              close(SockFd);
              }



              The result I get is :

              n.sin_family = 2
              in.sin_addr.s_addr = 3228760165
              in.sin_port = 9989
              SockFd is : 3
              Rc is : -1
              Error is : Cannot assign requested address


              what should i do.
0
Comment
Question by:hanan
1 Comment
 

Accepted Solution

by:
bkc earned 200 total points
ID: 1582392
This will only work if you're running this program on hds1.mta.ac.il [192.114.248.101]

Unless your system is multi-homed, its best to specify INADDR_ANY
as the sin_addr.s_addr, allowing your OS to assign the local
endpoint IP Address. INADDR_ANY is usually = 0.

If you are multi-homed, you must be certain that the address you
are requesting is assigned to a valid and active interface on your system.

Also, you may need to ntohl() the s_addr value. I don't think you
do, but you can try that if you're certain the IP address you're
trying to use is valid for your system.

Note also that if this is the server-side of a future connection,
and you're planning to call getsockname() to find out what
IP address has been assigned (if you're multi-homed), you really
can't call getsockname until a socket has been connected, and
you must call getsockname on that newly accepted socket, not
the listening socket.

Summary: Use INADDR_ANY as the s_addr value, not a specific value.

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most of the applications these days are on Cloud. Cloud is ubiquitous with many service providers in the market. Since it has many benefits such as cost reduction, software updates, remote access, disaster recovery and much more.
This article explains the fundamentals of industrial networking which ultimately is the backbone network which is providing communications for process devices like robots and other not so interesting stuff.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question