Solved

error binding try to communicate on IRIX

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
2 Gateways (bandwidth) - One domain 7 75
Cisco 3560 switches not seeing VTP V3 12 54
Cisco Policy based routing 2 41
Nimble Storage 3 69
#Citrix #Citrix Netscaler #HTTP Compression #Load Balance
For many of us, the  holiday season kindles the natural urge to give back to our friends, family members and communities. While it's easy for friends to notice the impact of such deeds, understanding the contributions of businesses and enterprises i…
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…
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…

831 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