473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

bind() and SIGSEGV when usign UDP

Hi, i got problem

when i bind in this way:

local_addr.sin_family = AF_INET;
local_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
local_addr.sin_port = htons(CLIENT_PORT);

i can easly bind port without any SIGSEGV (segmentation fault) but MSDN
wrote:

"If an application does not care what local address is assigned, specify
the manifest constant value ADDR_ANY for the sa_data member of the name
parameter. This allows the underlying service provider to use any
appropriate network address, potentially simplifying application
programming in the presence of multihomed hosts (that is, hosts that
have more than one network interface and address)."

so how write this? What is diference betwean ADDR_ANY and INADDR_ANY?

Thiese lines are wrong cause makes SIGSEGV:

local_addr.sin_addr.s_addr = htonl(ADDR_ANY);
local_addr.sin_addr.s_addr = htons(ADDR_ANY);
local_addr.sin_addr.s_addr = htonl(INADDR_ANY);
local_addr.sin_addr.s_addr = htons(INADDR_ANY);
local_addr.sin_addr.s_addr = INADDR_ANY;
local_addr.sin_addr.s_addr = ADDR_ANY;

Plz help me...
Jul 30 '05 #1
7 8942
USUN_TO wrote:
[redacted]


You're OT here. Ask in comp.unix.programmer.

Jul 30 '05 #2
USUN_TO wrote:
Hi, i got problem

when i bind in this way:

local_addr.sin_family = AF_INET;
local_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
local_addr.sin_port = htons(CLIENT_PORT);

i can easly bind port without any SIGSEGV (segmentation fault) but MSDN
wrote:

"If an application does not care what local address is assigned, specify
the manifest constant value ADDR_ANY for the sa_data member of the name
parameter. This allows the underlying service provider to use any
appropriate network address, potentially simplifying application
programming in the presence of multihomed hosts (that is, hosts that
have more than one network interface and address)."

so how write this? What is diference betwean ADDR_ANY and INADDR_ANY?

Thiese lines are wrong cause makes SIGSEGV:

local_addr.sin_addr.s_addr = htonl(ADDR_ANY);
local_addr.sin_addr.s_addr = htons(ADDR_ANY);
local_addr.sin_addr.s_addr = htonl(INADDR_ANY);
local_addr.sin_addr.s_addr = htons(INADDR_ANY);
local_addr.sin_addr.s_addr = INADDR_ANY;
local_addr.sin_addr.s_addr = ADDR_ANY;

Plz help me...


Your posting appears to be from a Windows machine.
If you're asking about the bind() found in the Windows
Winsock lib ("Windows Sockets 2"), then you might get help
in a Windows newsgroup. If you're asking about the socket
bind() in Unix or Linux networking, then you'll have to
ask for help in a newsgroup for the appropriate OS.

Regards,
Larry
Jul 30 '05 #3
USUN_TO wrote:
Hi, i got problem

when i bind in this way:

local_addr.sin_family = AF_INET;
local_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
local_addr.sin_port = htons(CLIENT_PORT);

i can easly bind port without any SIGSEGV (segmentation fault) but MSDN
wrote:

"If an application does not care what local address is assigned, specify
the manifest constant value ADDR_ANY for the sa_data member of the name
parameter. This allows the underlying service provider to use any
appropriate network address, potentially simplifying application
programming in the presence of multihomed hosts (that is, hosts that
have more than one network interface and address)."

so how write this? What is diference betwean ADDR_ANY and INADDR_ANY?

Thiese lines are wrong cause makes SIGSEGV:

local_addr.sin_addr.s_addr = htonl(ADDR_ANY);
local_addr.sin_addr.s_addr = htons(ADDR_ANY);
local_addr.sin_addr.s_addr = htonl(INADDR_ANY);
local_addr.sin_addr.s_addr = htons(INADDR_ANY);
local_addr.sin_addr.s_addr = INADDR_ANY;
local_addr.sin_addr.s_addr = ADDR_ANY;

Plz help me...

Below is a function extracted from one of my older C++
libs for Windows. Ignore the calls to IsOpen() and Close(),
they reside elsewhere, but the code may still help you
find your problem. Remember to add '#include <winsock.h>'
in your code.
int
ServerIpSocket::BindToPort(int port, int queueSize)
{
SOCKADDR_IN serverSockAddr;
int status;

// if already associated with a port, close
if (IsOpen())
Close();

/* MANDATORY - zero the sockaddr_in structure */
memset (&serverSockAddr, 0, sizeof (serverSockAddr));

/* specify the port portion of the address */
serverSockAddr.sin_port = htons ((u_short)port);

/* specify the address family as Internet */
serverSockAddr.sin_family = AF_INET;

/* specify that the address does not matter */
serverSockAddr.sin_addr.s_addr = htonl (INADDR_ANY);

/* create a socket */
theSocket = socket (AF_INET, SOCK_STREAM, 0);
if (theSocket == INVALID_SOCKET)
{
cerr << "ERROR: socket unsuccessful"
<< endl;

return (-1);
}

/* associate the socket with the address */
status = bind (theSocket,
(LPSOCKADDR) & serverSockAddr,
sizeof (serverSockAddr));
if (status == SOCKET_ERROR)
{
cerr << "ERROR: bind unsuccessful" << endl;

// close theSocket opened by the above socket() call
Close();

return (-1);
}

// allow the socket to take connections.
// specify a waiting connection queue size
status = listen (theSocket, queueSize);
if (status == SOCKET_ERROR)
{
cerr << "ERROR: listen unsuccessful" << endl;

// close theSocket opened by the above socket() call
Close();

return (-1);
}

// NOTE: For this socket class, we are NEVER connected to a client.
// ConnectToClient() will create/return a NEW socket to handle
// each client connection. Therefore we NEVER set "isConn" to
// non-zero for this class (ie: IsConnected() always returns
// zero)

return 0;
}

Regards,
Larry
Jul 30 '05 #4
Larry I Smith napisał(a):
USUN_TO wrote:


Thx a lot Larry but the same code under linux works fine and the same
(of course changing to WinSock spec. ) when i bind UDP i got SIGSEGV
(segmentation fault) but when i continue program works fine (not always
stable - so i tracking errors)
Jul 31 '05 #5
USUN_TO wrote:
Larry I Smith napisał(a):
USUN_TO wrote:


Thx a lot Larry but the same code under linux works fine and the same
(of course changing to WinSock spec. ) when i bind UDP i got SIGSEGV
(segmentation fault) but when i continue program works fine (not always
stable - so i tracking errors)


Is the return value of bind() WSAEACCES?
If it is, then (from the MSDN ref for Winsock), this might be
the problem:

<quote>
Attempt to connect datagram socket to broadcast address failed
because setsockopt() option SO_BROADCAST is not enabled.
</quote>

To use datagrams you have to enable SO_BROADCAST by calling
setsocketopt() before doing the bind().
See the MSDN Winsock docs for setsocketopt() for details.

http://msdn.microsoft.com/library/de...tsockopt_2.asp

Regards,
Larry
Jul 31 '05 #6
USUN_TO wrote:
Larry I Smith napisał(a):
USUN_TO wrote:


Thx a lot Larry but the same code under linux works fine and the same
(of course changing to WinSock spec. ) when i bind UDP i got SIGSEGV
(segmentation fault) but when i continue program works fine (not always
stable - so i tracking errors)


This is OT, but...

The other thing under Winsock is to make damn sure you call WSAStartup.
Jul 31 '05 #7
> The other thing under Winsock is to make damn sure you call WSAStartup.

I use Bcc32 5.5 and Newes MiniGW (from Dev-Cpp 4.9.9.2 with update) and
got thesame SIGSEGV :

http://republika.pl/aao_auth/UDP.rar

there is the source

and plz use GDB as debugger
Jul 31 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dieter Maurer | last post by:
Python 2.3.3, Linux 2.4.x: It looks as if a SIGSEGV in a thread of a multi threaded application does not kill the complete process under some circumstances but only one thread (unrelated to the...
0
by: Paffko | last post by:
What are the possibilities of getting SIGBUS and SIGSEGV errors in the following scenario? There is a program (C/C++/Pro*C) that was running fine under HP-UX 11.x and Oracle8i (8.1.6). Oracle...
4
by: junky_fellow | last post by:
what is the difference between signals SIGBUS and SIGSEGV ? when does an application program receive SIGBUS and in which cases SIGSEGV ? thanx in advance for any help ...
13
by: vashwath | last post by:
Hi all, In my current project I am using signals for error handling. Since I cannot show full code, I have just shown important piece of code which is relevant. void sigsegenv() {...
0
by: Nancy | last post by:
Hi, I'm running 2.4 Python. I have an extension program that calls C funcs. Actually I have a C prog that calls python that calls C. In a python to C function call I get a SIGSEGV and this stack...
4
by: subirs | last post by:
Hi, I am encountering SIGSEGV if I am opeing and closing a file in a do-while loop. i am including the part of the code where I have used fscanf....
11
by: guy | last post by:
I am able to use the Server Explorer to create a dataset containing tables in my database. I am able to bind a table to my combobox and set a filter by including a where clause. But I am unable to...
5
by: Joakim Hove | last post by:
Hello, in my application I have a typedefed struct: typedef struct { double d1; int i1; /* I have simplified the object here. */ } data_ptr_type;
1
by: krazedkid | last post by:
I am trying to get my code to handle SIGSEGV multiple times, it will handle one of them but then nothing else. void sigHandler( int signum ) { if ( signum == SIGSEGV ) { printf("got a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.