Solved

error binding try to communicate on IRIX

Posted on 1997-09-01
1
260 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Comware OS Simulator and GNS3 5 225
help Skype for Business keeps dropping 7 96
Migrating to Exchange 2016 - AD/DNS question 8 72
Move WSUS to Server 2016 3 39
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
When it comes to security, there are always trade-offs between security and convenience/ease of administration. This article examines some of the main pros and cons of using key authentication vs password authentication for hosting an SFTP server.
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

734 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