You are not logged in.

#1 2014-12-04 18:33:29

luckybc
Member
Registered: 2014-04-25
Posts: 55

[SOLVED]Where is "sin_family" in struct sockaddr_in - netinet/in.h ?

Hello everyone

I'm new networking socket in c programming. And I'm trying to make a simple sever - client. The following is what I want to have :

...
//Binding to a port
struct sockaddr_in name;
name.[b]sin_family[/b] = PF_INET;
name.sin_port = (in_port_t)htons(30000);
name.sin_addr.s_addr = htonl(INADDR_ANY);
...

Where is sin_family ? If you are a pro, please tell me know what I need to do.

Last edited by luckybc (2014-12-05 06:15:32)

Offline

#2 2014-12-04 19:18:01

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,353

Re: [SOLVED]Where is "sin_family" in struct sockaddr_in - netinet/in.h ?

ewaller@odin ~ [130]1054 %find /usr/include -exec grep sin_family {} \; -print 2>/dev/null
  vki_sa_family_t       sin_family;     /* Address family               */
/usr/include/valgrind/vki/vki-linux.h
  addr.sin_family = AF_INET;
/usr/include/boost/asio/detail/impl/socket_select_interrupter.ipp
    address.v4.sin_family = BOOST_ASIO_OS_DEF(AF_INET);
      sinptr->sin_family = BOOST_ASIO_OS_DEF(AF_INET);
/usr/include/boost/asio/detail/impl/socket_ops.ipp
struct sockaddr_in4_type { int sin_family;
/usr/include/boost/asio/detail/socket_types.hpp
  data_.v4.sin_family = BOOST_ASIO_OS_DEF(AF_INET);
    data_.v4.sin_family = BOOST_ASIO_OS_DEF(AF_INET);
    data_.v4.sin_family = BOOST_ASIO_OS_DEF(AF_INET);
/usr/include/boost/asio/ip/detail/impl/endpoint.ipp
  __kernel_sa_family_t  sin_family;     /* Address family               */
/usr/include/linux/in.h
ewaller@odin ~ 1055 %

It would appear to be in /usr/include/linux/in.h


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2014-12-04 19:29:10

luckybc
Member
Registered: 2014-04-25
Posts: 55

Re: [SOLVED]Where is "sin_family" in struct sockaddr_in - netinet/in.h ?

excuse me ! What I see you focus to /usr/include/boost/ directory. But the document
http://www.codeproject.com/Articles/586 … orial-in-C

Can you explain what difference between /usr/include/linux/in.h and /usr/include/netinet/in.h ?

Offline

#4 2014-12-04 19:43:23

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,353

Re: [SOLVED]Where is "sin_family" in struct sockaddr_in - netinet/in.h ?

Actually, I just did a search on the include tree.  Boost happens to use sin_family.  Of interesdt in my find command were the last two lines.
I don't know the difference between the files, except that the latter does not define sin_family

To be honest, I have not done socket programming using those headers.  I really cannot answer specific questions.  I just tried to provide a pointer to where sin_family is defined as you asked in your first post.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#5 2014-12-04 20:02:00

luckybc
Member
Registered: 2014-04-25
Posts: 55

Re: [SOLVED]Where is "sin_family" in struct sockaddr_in - netinet/in.h ?

Thank you very much, ewaller!

I until hope someone help me know clearly, thank you.

Offline

#6 2014-12-04 22:58:34

rsmarples
Member
Registered: 2009-05-12
Posts: 287

Re: [SOLVED]Where is "sin_family" in struct sockaddr_in - netinet/in.h ?

man 7 ip

       #include <sys/socket.h>
       #include <netinet/in.h>
       #include <netinet/ip.h> 

           struct sockaddr_in {
               sa_family_t    sin_family; /* address family: AF_INET */
               in_port_t      sin_port;   /* port in network byte order */
               struct in_addr sin_addr;   /* internet address */
           };

           /* Internet address. */
           struct in_addr {
               uint32_t       s_addr;     /* address in network byte order */
           };

Please remember to code for IPv6 as well smile
BTW, these type of questions are probably better served by http://stackoverflow.com/

Last edited by rsmarples (2014-12-04 22:59:32)

Offline

#7 2014-12-05 06:15:06

luckybc
Member
Registered: 2014-04-25
Posts: 55

Re: [SOLVED]Where is "sin_family" in struct sockaddr_in - netinet/in.h ?

Hi guys! I had answser that is:

from http://stackoverflow.com/questions/2730 … 8#27308098

Thank you.

Offline

#8 2014-12-05 09:15:52

rsmarples
Member
Registered: 2009-05-12
Posts: 287

Re: [SOLVED]Where is "sin_family" in struct sockaddr_in - netinet/in.h ?

You got it here also. Thanks anyway roll

Offline

Board footer

Powered by FluxBB