From: "Venkata Rajesh Velamakanni" <rajesh.venkata@wipro.com>
To: <linux-kernel@vger.kernel.org>
Subject: Faced a problem with rtnetlink socket ( RTM_DELLINK)
Date: Mon, 7 Jan 2002 17:08:24 +0530 [thread overview]
Message-ID: <001b01c1976f$d11da6f0$4e05720a@M3HOM103042> (raw)
[-- Attachment #1: Type: text/plain, Size: 660 bytes --]
Hello All,
I am facing a problem in using rtnetlink sockets and thought that
this mailing list would be the better to place to clarify.
Can anyone calrify my query.
When I tried deleting an interface, I have received message
RTM_NEWLINK (instead of RTM_DELLINK) from kernel.
I have executed the attached program and did "/sbin/ifdown eth0"..
and my program received a messsage RTM_NEWLINK from kernel
instead of RTM_DELLINK.
When I tried adding the interface "/sbin/ifup eth0".. it works fine
and received RTM_NEWLINK.
I would like to know whether anyone has faced this problem or
am I missing something in my program.
Thanks,
Rajesh.
[-- Attachment #2: rtnetlink.c --]
[-- Type: application/octet-stream, Size: 2598 bytes --]
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <bits/sockaddr.h>
#include <linux/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
struct iovec
{
void *iov_base; /* Pointer to data. */
size_t iov_len; /* Length of data. */
};
main()
{
int status;
int ret = 0;
int error;
struct sockaddr_nl bind_addr;
int rtnetlink_sk = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
bind_addr.nl_family = AF_NETLINK;
bind_addr.nl_pad = 0;
bind_addr.nl_pid = getpid();
bind_addr.nl_groups = ~0U;
if (bind(rtnetlink_sk, (struct sockaddr *)&bind_addr,
sizeof(bind_addr)) < 0) {
perror("bind");
}
while (1)
{
char buf[4096];
struct iovec iov = { buf, sizeof buf };
struct sockaddr_nl snl;
struct msghdr msg = { (void*)&snl, sizeof snl, &iov, 1, NULL, 0, 0};
struct nlmsghdr *h;
status = recvmsg (rtnetlink_sk, &msg, 0);
if (status < 0)
{
if (errno == EINTR)
continue;
if (errno == EWOULDBLOCK)
break;
continue;
}
if (status == 0)
{
return -1;
}
if (msg.msg_namelen != sizeof snl)
{
return -1;
}
for (h = (struct nlmsghdr *) buf; NLMSG_OK (h, status);
h = NLMSG_NEXT (h, status))
{
/* Finish of reading. */
if (h->nlmsg_type == NLMSG_DONE)
return ret;
/* Error handling. */
if (h->nlmsg_type == NLMSG_ERROR)
{
struct nlmsgerr *err = (struct nlmsgerr *) NLMSG_DATA (h);
if (h->nlmsg_len < NLMSG_LENGTH (sizeof (struct nlmsgerr)))
{
printf("Received error message that to with invalid length\n");
return ;
}
return ;
}
/* OK we received netlink message. */
switch (h->nlmsg_type)
{
case RTM_NEWLINK:
{
printf("We are in NEWLINK ...\n");
break;
}
case RTM_DELLINK:
{
printf("We are in DELLINK ...\n");
break;
}
default:
break;
}
}
/* After error care. */
if (msg.msg_flags & MSG_TRUNC)
{
continue;
}
if (status)
{
return -1;
}
}
return ret;
}
[-- Attachment #3: Wipro_Disclaimer.txt --]
[-- Type: text/plain, Size: 855 bytes --]
-----------------------------------------------------------------------------------------------------------------------
Information transmitted by this E-MAIL is proprietary to Wipro and/or its Customers and
is intended for use only by the individual or entity to which it is
addressed, and may contain information that is privileged, confidential or
exempt from disclosure under applicable law. If you are not the intended
recipient or it appears that this mail has been forwarded to you without
proper authority, you are notified that any use or dissemination of this
information in any manner is strictly prohibited. In such cases, please
notify us immediately at mailto:mailadmin@wipro.com and delete this mail
from your records.
------------------------------------------------------------------------------------------------------------------------
next reply other threads:[~2002-01-07 11:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-01-07 11:38 Venkata Rajesh Velamakanni [this message]
2002-01-07 13:21 ` Venkata Rajesh Velamakanni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='001b01c1976f$d11da6f0$4e05720a@M3HOM103042' \
--to=rajesh.venkata@wipro.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®