HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: socket ioctl help
Operating System - HP-UX
1833329
Members
3774
Online
110051
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
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
02-04-2002 03:41 AM
02-04-2002 03:41 AM
socket ioctl help
Hi,
I am getting a "reinterpret_cast" warning while compiling the following
C++ program. In the program I am making socket ioctl call to get the
network mask.
Looks like there is no way I can get over this warning, the "ifreq"
structure has no member of type "sockaddr_in". Is there anything wrong
that I am doing here which gives out this warning ?
$ aCC -AA main1.C
Warning 749: "main1.C", line 24 # The cast from 'sockaddr *' to
'sockaddr_in
*' is performed as a 'reinterpret_cast'. This operation is
non-portable
and potentially unsafe.
s_addr = (struct sockaddr_in *)(&ifr.ifr_addr);
^^^^^^^^^^^^^^^^^^^^^^
Program:
--------
#include
using namespace std;
#include
#include
#include
#include
#include
#include
int main(){
struct ifreq ifr;
int skfd;
struct sockaddr_in *s_addr;
// open system socket
if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0)
{
strcpy(ifr.ifr_name, "lan0");
if (ioctl(skfd, SIOCGIFNETMASK, &ifr) >= 0)
{
s_addr = (struct sockaddr_in *)(&ifr.ifr_addr);
cout<<"Network mask is "<sin_addr)< }
close(skfd);
}
}
regards,
I am getting a "reinterpret_cast" warning while compiling the following
C++ program. In the program I am making socket ioctl call to get the
network mask.
Looks like there is no way I can get over this warning, the "ifreq"
structure has no member of type "sockaddr_in". Is there anything wrong
that I am doing here which gives out this warning ?
$ aCC -AA main1.C
Warning 749: "main1.C", line 24 # The cast from 'sockaddr *' to
'sockaddr_in
*' is performed as a 'reinterpret_cast'. This operation is
non-portable
and potentially unsafe.
s_addr = (struct sockaddr_in *)(&ifr.ifr_addr);
^^^^^^^^^^^^^^^^^^^^^^
Program:
--------
#include
using namespace std;
#include
#include
#include
#include
#include
#include
int main(){
struct ifreq ifr;
int skfd;
struct sockaddr_in *s_addr;
// open system socket
if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0)
{
strcpy(ifr.ifr_name, "lan0");
if (ioctl(skfd, SIOCGIFNETMASK, &ifr) >= 0)
{
s_addr = (struct sockaddr_in *)(&ifr.ifr_addr);
cout<<"Network mask is "<
close(skfd);
}
}
regards,
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2002 05:50 AM
02-04-2002 05:50 AM
Re: socket ioctl help
Hi,
Your cast is legal; aCC is just concerned your code may be non-portable. I have three suggestions to make the warning go away:
1) See if aCC prefers you use "reinterpret_cast" over the C-style cast "(struct sockaddr_in *)". It may be that aCC thinks you don't realize it is a reinterpret_cast.
2) See if aCC supports a means of disabling certain warnings, such as through #pragma.
3) Finally, there is always the compiler option to disable all warnings (this has obvious disadvantages). It may be different with aCC, but the switch is usually -w.
For what it's worth, your code compiles without error under g++, even with the -Wall option.
Best of luck to you :)
Your cast is legal; aCC is just concerned your code may be non-portable. I have three suggestions to make the warning go away:
1) See if aCC prefers you use "reinterpret_cast
2) See if aCC supports a means of disabling certain warnings, such as through #pragma.
3) Finally, there is always the compiler option to disable all warnings (this has obvious disadvantages). It may be different with aCC, but the switch is usually -w.
For what it's worth, your code compiles without error under g++, even with the -Wall option.
Best of luck to you :)
[Insert humorous and/or inspirational quote here]
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
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP