LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-08-2015, 05:44 PM   #1
hnasr2001
Member
 
Registered: Nov 2012
Posts: 98

Rep: Reputation: Disabled
binding socket in centos 6.4 using INADDR_ANY


I used the following code in centos 5.10 and I was able to open a socketa nd read from it.
I upgraded to centos 6.4 and I was not able to read from socket any more.
I had to change one parameter from INADDR_ANY to specified IP address.
Has anyone see the same issue in centos 6.4? Am I missign something in my code?

-----------------------------------------------

bool netclass::InitNet(void)
{
int mode = 0;
int on = 1;

sock = socket(AF_INET, SOCK_DGRAM, 0);
mode = NONBLOCKING; // set for non-blocking
ioctl(sock,FIONBIO,&mode);

setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,(char *)&on, sizeof(on));

memset(&addr, 0, sizeof(addr));
addr.sin_family=AF_INET;
addr.sin_port=htons(MCAST_PORT);
addr.sin_addr.s_addr=htonl(INADDR_ANY);
bind(sock, (struct sockaddr *)&addr, sizeof(addr));

mreq.imr_multiaddr.s_addr=inet_addr(MCAST_GROUP);
// mreq.imr_interface.s_addr=htonl(INADDR_ANY);
mreq.imr_interface.s_addr=inet_addr("192.168.45.57");
setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP,&mreq, sizeof(mreq));

return true;
}//end of init Net
 
Old 02-08-2015, 11:15 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,177

Rep: Reputation: 1272Reputation: 1272Reputation: 1272Reputation: 1272Reputation: 1272Reputation: 1272Reputation: 1272Reputation: 1272Reputation: 1272
What is the return value?
 
Old 02-08-2015, 11:43 PM   #3
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,629

Rep: Reputation: 2652Reputation: 2652Reputation: 2652Reputation: 2652Reputation: 2652Reputation: 2652Reputation: 2652Reputation: 2652Reputation: 2652Reputation: 2652Reputation: 2652
you do know you upgraded to a UNSUPPORTED VERSION
6.4 is past it's End Of Lifeand dose NOT have the last years worth of SECURITY UPDATES AND FIXES

upgrade to the ONLY supported version in the 6 series
CentOS 6.6 ASAP
Code:
su -
yum --releasever=6.6 upgrade
 
Old 02-09-2015, 08:11 AM   #4
hnasr2001
Member
 
Registered: Nov 2012
Posts: 98

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by smallpond View Post
What is the return value?
All functions return 0.
 
Old 02-09-2015, 12:10 PM   #5
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,177

Rep: Reputation: 1272Reputation: 1272Reputation: 1272Reputation: 1272Reputation: 1272Reputation: 1272Reputation: 1272Reputation: 1272Reputation: 1272
Then it succeeded.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
binding to a socket with INADDR_ANY, can i find which ip is being connected to? nkoplm Programming 3 12-06-2009 12:17 AM
Binding to Unix Domain Socket blank87 Programming 1 06-18-2008 06:19 PM
binding a socket blackzone Programming 1 12-21-2004 06:46 AM
socket binding and writing wahhie Programming 0 11-21-2004 08:38 PM
Socket binding to port problems Xris718 Linux - General 0 07-10-2003 01:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration