I think I'm dealing with a bug in a library or some weird problem. The
following code compiles and works as I'd expect on Linux and cygwin, but on
the machine that matters (HP PA64, HPUX 11.11) it identifies the peer as
0.0.0.0 in both the accept() and getpeername() return vals, also identifies
the peer port as 0. I'm using gcc 4.1.2, downloaded from HP's site,
compiling with 'gcc sockprob.c -o sockprob', then running it with
'./sockprob.c MY.I.P.ADD 7890', then connect to the server socket with
'telnet MY.I.P.ADD 7890'. Cygwin and Linux show the ip and port of the
connector, but HPUX is showing 0.0.0.0. I run a 'netstat -n' and it shows
the correct ip/port for the server and client. I just don't get it. Does
anyone have any advice?
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
char* ipstring;
int port1;
void parseargs(int, char**);
int main(int argc, char* args[])
{ struct sockaddr_in adr1; /* address for the server */
int ss1, as1; /* file descriptors for server socket, active
socket */
struct sockaddr_in from1; /* address for peer */
socklen_t from1_len;
parseargs(argc, args);
if((ss1 = socket(PF_INET, SOCK_STREAM, 0)) < 0)
{ perror("socket failed");
return 1;
}
memset(&adr1, 0, sizeof(adr1));
adr1.sin_family = AF_INET;
adr1.sin_port = htons(port1);
if(!inet_aton(ipstring, (struct in_addr*)&(adr1.sin_addr)))
{ perror("inet_aton failed");
return 1;
}
if(bind(ss1, (struct sockaddr*) &adr1, sizeof(adr1)))
{ perror("bind failed");
return 1;
}
if(listen(ss1, 1) < 0)
{ perror("listen failed");
return 1;
}
from1_len = sizeof(from1);
memset(&from1, 0, sizeof(from1));
from1.sin_family = AF_INET;
if((as1 = accept(ss1, (struct sockaddr*) &from1, &from1_len)) == -1)
{ perror("Error accepting");
return 1;
}
printf("peer address from accept() is %s %d\n",
inet_ntoa(from1.sin_addr), ntohs(from1.sin_port));
if(getpeername(as1, (struct sockaddr*) &from1, &from1_len))
{ perror("getpeername failed");
return 1;
}
printf("peer add/port from getpeername() is %s %d\n",
inet_ntoa(from1.sin_addr), ntohs(from1.sin_port));
return 0;
}
void parseargs(int argc, char* args[])
{
/* command line is sockprob ip port */
ipstring = args[1];
sscanf(args[2], "%d", &port1);
return;
} 5 4907
Mike King wrote:
I think I'm dealing with a bug in a library or some weird problem.
[...]
Whatever bug or weird problem confronts you, it is not a
problem with the C language or the way C is used. It may
surprise you to learn that C's networking support is rather
limited. In fact, it consists entirely of the following list
of headers, types, and functions:
Yes, that's the complete list; you didn't miss anything.
Try your question on a newsgroup devoted to HPUX, or at
least to Unix. It isn't about C.
--
Eric Sosman es*****@acm-dot-org.invalid
10-4
No it doesn't suprise me. I know how small the c language is. I thought
maybe you all had some advice on tracking down library bugs, like
identifying the actual executable the linker uses, typical problems with
non-native compilers, etc.
#include<sincere/apology.h>
Mike
"Eric Sosman" <es*****@acm-dot-org.invalidwrote in message
news:Vs******************************@comcast.com. ..
Mike King wrote:
>I think I'm dealing with a bug in a library or some weird problem.
[...]
Whatever bug or weird problem confronts you, it is not a
problem with the C language or the way C is used. It may
surprise you to learn that C's networking support is rather
limited. In fact, it consists entirely of the following list
of headers, types, and functions:
Yes, that's the complete list; you didn't miss anything.
Try your question on a newsgroup devoted to HPUX, or at
least to Unix. It isn't about C.
--
Eric Sosman es*****@acm-dot-org.invalid
On Mon, 26 Feb 2007 19:36:02 -0600, "Mike King" <wm***@cox.netwrote:
>I think I'm dealing with a bug in a library or some weird problem. The following code compiles and works as I'd expect on Linux and cygwin, but on the machine that matters (HP PA64, HPUX 11.11) it identifies the peer as 0.0.0.0 in both the accept() and getpeername() return vals, also identifies the peer port as 0. I'm using gcc 4.1.2, downloaded from HP's site, compiling with 'gcc sockprob.c -o sockprob', then running it with './sockprob.c MY.I.P.ADD 7890', then connect to the server socket with 'telnet MY.I.P.ADD 7890'. Cygwin and Linux show the ip and port of the connector, but HPUX is showing 0.0.0.0. I run a 'netstat -n' and it shows the correct ip/port for the server and client. I just don't get it. Does anyone have any advice?
As others have pointed out, your question is off-topic. Regardless,
the best advice I can give is to use a debugger. Doesn't HP PA64, HPUX
11.11 have a debugger?
If this were Windows, I'd use the Microsoft Visual Studio debugger to
nail down the problem (probably in minutes, if not seconds). I've used
Eclipse on Linux to nail down similar problems with 64-bit
platforms--maybe you can use Eclipse (which uses gdb)?
Best regards
--
jay
It was a type mismatch - socklen_t is defined as size_t, defined as long,
which is 8 bytes with the compiler I was using. The library code was
expecting a 4 byte int even though the header file says socklen_t. When I
added a 32 bit left shift to the socklen_t variable, it worked. The
functions had been getting the 4 high bytes which were all 0, so the
function didn't populate my sockaddr struct because it didn't think they
were big enough.
Sorry again for the off topic post - you won't hear from me any more.
Thanks,
Mike
"jaysome" <ja*****@hotmail.comwrote in message
news:0c********************************@4ax.com...
On Mon, 26 Feb 2007 19:36:02 -0600, "Mike King" <wm***@cox.netwrote:
>>I think I'm dealing with a bug in a library or some weird problem. The following code compiles and works as I'd expect on Linux and cygwin, but on the machine that matters (HP PA64, HPUX 11.11) it identifies the peer as 0.0.0.0 in both the accept() and getpeername() return vals, also identifies the peer port as 0. I'm using gcc 4.1.2, downloaded from HP's site, compiling with 'gcc sockprob.c -o sockprob', then running it with './sockprob.c MY.I.P.ADD 7890', then connect to the server socket with 'telnet MY.I.P.ADD 7890'. Cygwin and Linux show the ip and port of the connector, but HPUX is showing 0.0.0.0. I run a 'netstat -n' and it shows the correct ip/port for the server and client. I just don't get it. Does anyone have any advice?
As others have pointed out, your question is off-topic. Regardless,
the best advice I can give is to use a debugger. Doesn't HP PA64, HPUX
11.11 have a debugger?
If this were Windows, I'd use the Microsoft Visual Studio debugger to
nail down the problem (probably in minutes, if not seconds). I've used
Eclipse on Linux to nail down similar problems with 64-bit
platforms--maybe you can use Eclipse (which uses gdb)?
Best regards
--
jay
"Mike King" <wm***@cox.netwrites:
It was a type mismatch - socklen_t is defined as size_t, defined as long,
which is 8 bytes with the compiler I was using.
[snip]
Please don't top-post. See: http://www.caliburn.nl/topposting.html http://www.cpax.org.uk/prg/writings/topposting.php
size_t is guaranteed to be an unsigned type. It can't be defined as
long; it might be defined as unsigned long.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister" This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Paul Oakfleet |
last post by:
The script below will disable Submit button until user accept terms,
and will redirect user to another page after clicking on Submit
button.
The script seems to work fine on my PC (Windows XP,...
|
by: Blatwurst |
last post by:
I'm trying to implement a simple server in C#. I want to do the classic thing of spinning off a thread that just blocks in a Socket.Accept() call until a request comes in. At that point, the...
|
by: PengYu.UT |
last post by:
I'm wondering whether the operator can accept more than 1 arguments
Suppose I have a object which is essentially a 2 dimensional array, I
want to use operator to access the data. I don't what...
|
by: Jim |
last post by:
Need some comments from anyone willing to help, please. See the code
included below. This compiles with GCC on FreeBSD 4.7. The only
point of it is to accept a socket connection. Nothing else...
|
by: DarkLotus |
last post by:
Code:
--------------------
BOOL IsIPRight(char *ip)
{
unsigned long TheIP;
TheIP ip;
TheIP = inet_addr("66.55.44.33");
|
by: lisaj |
last post by:
I'm having huge difficulties producing a script for this:
Write a javascript programme that will prompt for, and accept from the user, an input string which contains at least 8 characters. It...
|
by: lbelkova |
last post by:
Hello,
I've created a custom DataGridViewColumn. Everything work well, except
for some reason the column doesn't accept some of the chars: "q", "."
and "'". Did anybody have a similar problem?...
|
by: 7stud |
last post by:
I have the following two identical clients
#test1.py:-----------
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = 'localhost'
port = 5052 #server port
|
by: Riccardo Di Meo |
last post by:
Hi everyone,
I'm practicing with embedding python into C code and i have encountered
a very strange problem: I'm unable to call the "accept" method of a
(correctly created) server socket without...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |