- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sockaddr_in, sockaddr_in6, sockaddr_storage when u...
Operating System - HP-UX
1819870
Members
2458
Online
109607
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
Discussions
Discussions
Discussions
Forums
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
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
тАО03-30-2008 12:39 PM
тАО03-30-2008 12:39 PM
sockaddr_in, sockaddr_in6, sockaddr_storage when use which ?
Hi all,
I am playing with some socket programming and one thing confuse me. For ipv4 we have struct sockaddr_in which is able to handle everything related to ipv4 sockets. On other side for ipv6 we have struct sockaddr_in6, which do the same thing for ipv6. It is known that ipv6 created with
socket ( AF_INET, SOCK_STREAM,0) is able to accept connections from ipv4 and ipv6 clients if there is not specificaly written IPV6_V6ONLY in declaration of address type.
For me is confusing the structure
sockaddr_storage ( I read that is used to write address family independent code and that is ok ) but if I have some application for which is necessary to accept connection from ipv4 and ipv6 clients then I can use struct sockaddr_in6, and the application with that structure will work ? Do we need struct sockaddr_storage only on server side when we do not have information will our application be running on ipv4 or ipv6 server.
I am sorry, if this post looks confusing but, it is completealy mess for me to understand this. If someone have knowledge and will to share it thanks in advance
Kind regards,
I am playing with some socket programming and one thing confuse me. For ipv4 we have struct sockaddr_in which is able to handle everything related to ipv4 sockets. On other side for ipv6 we have struct sockaddr_in6, which do the same thing for ipv6. It is known that ipv6 created with
socket ( AF_INET, SOCK_STREAM,0) is able to accept connections from ipv4 and ipv6 clients if there is not specificaly written IPV6_V6ONLY in declaration of address type.
For me is confusing the structure
sockaddr_storage ( I read that is used to write address family independent code and that is ok ) but if I have some application for which is necessary to accept connection from ipv4 and ipv6 clients then I can use struct sockaddr_in6, and the application with that structure will work ? Do we need struct sockaddr_storage only on server side when we do not have information will our application be running on ipv4 or ipv6 server.
I am sorry, if this post looks confusing but, it is completealy mess for me to understand this. If someone have knowledge and will to share it thanks in advance
Kind regards,
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2008 09:26 AM
тАО03-31-2008 09:26 AM
Re: sockaddr_in, sockaddr_in6, sockaddr_storage when use which ?
Generally speaking, you allocate something sized/aligned like sockaddr_storage and then use casts to either sockaddr_in or sockaddr_in6. The sockaddr_in* structures both have the "family" field in the same place and of the same size so even if your sockaddr_storage happends to be holding a sockaddr_in6, you can still cast it to a sockaddr_in for the purposes of checking the sin_family field. If that is then AF_INET6 you would then switch to using a sockaddr_in6 cast of the sockaddr_storage.
You might want to get the latest edition of Stevens, Fenner and Rudoff's Unix Network Programming. It will have lots of examples for you.
You might want to get the latest edition of Stevens, Fenner and Rudoff's Unix Network Programming. It will have lots of examples for you.
there is no rest for the wicked yet the virtuous have no pillows
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-01-2008 05:43 AM
тАО04-01-2008 05:43 AM
Re: sockaddr_in, sockaddr_in6, sockaddr_storage when use which ?
Thanks for your answer. I will try to find the book you recommended me. If I have code
struct sockaddr_in saddr;
bzero((char *) &saddr, sizeof(saddr));
saddr.sin_family = AF_INET;
saddr.sin_port = htons((u_short) service);
saddr.sin_addr.s_addr = INADDR_ANY;
I am just wondering how to addapt it using struct sockaddr_storage to be address independent ?
Thanks for answer
struct sockaddr_in saddr;
bzero((char *) &saddr, sizeof(saddr));
saddr.sin_family = AF_INET;
saddr.sin_port = htons((u_short) service);
saddr.sin_addr.s_addr = INADDR_ANY;
I am just wondering how to addapt it using struct sockaddr_storage to be address independent ?
Thanks for answer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-01-2008 09:08 AM
тАО04-01-2008 09:08 AM
Re: sockaddr_in, sockaddr_in6, sockaddr_storage when use which ?
make saddr a pointer to sockaddr_in and then point it at a newly added struct sockaddr_storage foo
struct sockaddr_storage foo;
struct sockaddr_in *saddr;
sadder - (struct sockaddr_in *)&foo;
...
converting the rest of the code with the knowledge that saddr is now a pointer to a struct sockaddr_in.
struct sockaddr_storage foo;
struct sockaddr_in *saddr;
sadder - (struct sockaddr_in *)&foo;
...
converting the rest of the code with the knowledge that saddr is now a pointer to a struct sockaddr_in.
there is no rest for the wicked yet the virtuous have no pillows
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
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP