Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Send "connect" control message

0 views
Skip to first unread message

serena zanetta

unread,
Apr 6, 2010, 11:32:40 AM4/6/10
to freeb...@freebsd.org
Hi,
I want to send a connect control message from an ng_hub node to the followin
ng_ksocket node.

I've tired by filling within the ng_hub node the sockaddr_in structure named
connect_addr:

connect_addr->sin_len = 16;
connect_addr->sin_family = AF_INET;
connect_addr->sin_port = htons(55056);
connect_addr->sin_addr.s_addr = htonl(IP_REMOTE);

And send it to the following node as:
*(struct sockaddr_in *)msg->data = connect_addr;
NG_MKMESSAGE(msg,NGM_GINSOCKET_COOKIE,NGM_GINSOCKET_CONNECT,sizeof(struct
sockaddr_in),M_NOWAIT);
NG_SEND_MSG_HOOK(error,node,msg,hook2,0);

But first of all, I don't know how I can convert the IP_REMOTE, which is
currently IP_REMOTE = "10.0.0.90", into a in_addr structure...

Does anyone can suggest me how to fix it?

Thank you,

Serena

Chuck Swiger

unread,
Apr 6, 2010, 1:41:43 PM4/6/10
to serena zanetta, freeb...@freebsd.org
Hi--

On Apr 6, 2010, at 8:32 AM, serena zanetta wrote:
> But first of all, I don't know how I can convert the IP_REMOTE, which is
> currently IP_REMOTE = "10.0.0.90", into a in_addr structure...

To convert a string to an IP address kept as an in_addr, you want inet_aton(), used like so:

const char *ipstr = "127.0.0.1";
struct in_addr ip;

if (!inet_aton(ipstr, &ip))
errx(1, "can't parse IP address %s", ipstr);

[ Example borrowed from "man gethostbyaddr" ]

Regards,
--
-Chuck

0 new messages