Solved

error binding try to communicate on IRIX

Posted on 1997-09-01
1
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
bkc earned 100 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This article is a collection of issues that people face from time to time and possible solutions to those issues. I hope you enjoy reading it.
During and after that shift to cloud, one area that still poses a struggle for many organizations is what to do with their department file shares.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month7 days, 5 hours left to enroll

623 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