You are not logged in.
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
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
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
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
Thank you very much, ewaller!
I until hope someone help me know clearly, thank you.
Offline
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
BTW, these type of questions are probably better served by http://stackoverflow.com/
Last edited by rsmarples (2014-12-04 22:59:32)
Offline
Offline
You got it here also. Thanks anyway
Offline