HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Memory fault at run time in C program
Operating System - HP-UX
1828028
Members
1891
Online
109973
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 07:08 AM
05-20-2003 07:08 AM
This code convert a ip address in decimal dot notation to hexadecimal, it work fine in linux but when i test in HP-UX i get "Memory fault". It compiled fine.
#include
#include
main(int argc, char *argv[])
{
struct in_addr *ip;
if (argc!=2)
{ printf("inet_atoh\n");
exit();
}
if (inet_aton(argv[1],ip))
printf("%x\n",ntohl(ip->s_addr));
}
Is there something wrong with the above code?
Thank you in advance for any help.
#include
#include
main(int argc, char *argv[])
{
struct in_addr *ip;
if (argc!=2)
{ printf("inet_atoh
exit();
}
if (inet_aton(argv[1],ip))
printf("%x\n",ntohl(ip->s_addr));
}
Is there something wrong with the above code?
Thank you in advance for any help.
Matias Di Blasi
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 07:50 AM
05-20-2003 07:50 AM
Re: Memory fault at run time in C program
a5:/tmp 103 > cc -O -o xx xx.c
cc: line 14: warning 5004: Uninitialized variable "ip" in function "main" (5004)
a5:/tmp 104 > ./xx 192.193.194.195
0
Exit 2
a5:/tmp 105 > gcc -O -o xx xx.c
xx.c: In function `main':
xx.c:10: error: too few arguments to function `exit'
Exit 1
a5:/tmp 106 >
That it does work in Linux is stranger than that it does not work on HP. Compare to the corrected version:
#include
#include
main (int argc, char *argv[])
{
struct in_addr ip;
unsigned long ul;
if (argc != 2) {
printf ("inet_atoh\n");
exit (1);
}
if (inet_aton (argv[1], &ip)) {
printf ("%x\n", ip.s_addr);
ul = ntohl (ip.s_addr);
printf ("%x\n", ul);
}
} /* main */
Enjoy, have FUN! H.Merijn
cc: line 14: warning 5004: Uninitialized variable "ip" in function "main" (5004)
a5:/tmp 104 > ./xx 192.193.194.195
0
Exit 2
a5:/tmp 105 > gcc -O -o xx xx.c
xx.c: In function `main':
xx.c:10: error: too few arguments to function `exit'
Exit 1
a5:/tmp 106 >
That it does work in Linux is stranger than that it does not work on HP. Compare to the corrected version:
#include
#include
main (int argc, char *argv[])
{
struct in_addr ip;
unsigned long ul;
if (argc != 2) {
printf ("inet_atoh
exit (1);
}
if (inet_aton (argv[1], &ip)) {
printf ("%x\n", ip.s_addr);
ul = ntohl (ip.s_addr);
printf ("%x\n", ul);
}
} /* main */
Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 08:00 AM
05-20-2003 08:00 AM
Solution
Yes there is something terribly wrong with your code. It was only working by accident under linux.
main(int argc, char *argv[])
{
struct in_addr *ip;
if (argc!=2)
{ printf("inet_atoh\n");
exit();
}
if (inet_aton(argv[1],ip))
printf("%x\n",ntohl(ip->s_addr));
}
The exit() w/o args is bad but only kills you if argc != 2. Change that to exit(255) or whatever BUT the real problem is:
struct in_addr *ip;
it should be:
struct in_addr ip;
/* This will actually allocate space for the struct rather than simply for a pointer */
Then:
if (inet_aton(argv[1],ip))
printf("%x\n",ntohl(ip->s_addr));
Should be:
if (inet_aton(argv[1],&ip))
printf("%x\n",ntohl(ip.s_addr));
main(int argc, char *argv[])
{
struct in_addr *ip;
if (argc!=2)
{ printf("inet_atoh
exit();
}
if (inet_aton(argv[1],ip))
printf("%x\n",ntohl(ip->s_addr));
}
The exit() w/o args is bad but only kills you if argc != 2. Change that to exit(255) or whatever BUT the real problem is:
struct in_addr *ip;
it should be:
struct in_addr ip;
/* This will actually allocate space for the struct rather than simply for a pointer */
Then:
if (inet_aton(argv[1],ip))
printf("%x\n",ntohl(ip->s_addr));
Should be:
if (inet_aton(argv[1],&ip))
printf("%x\n",ntohl(ip.s_addr));
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 08:17 AM
05-20-2003 08:17 AM
Re: Memory fault at run time in C program
Thank for your help. Now it work fine.
Matias Di Blasi
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP