mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Faced a problem with rtnetlink socket ( RTM_DELLINK)
@ 2002-01-07 11:38 Venkata Rajesh Velamakanni
  2002-01-07 13:21 ` Venkata Rajesh Velamakanni
  0 siblings, 1 reply; 2+ messages in thread
From: Venkata Rajesh Velamakanni @ 2002-01-07 11:38 UTC (permalink / raw)
  To: linux-kernel

[-- 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.
------------------------------------------------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Faced a problem with rtnetlink socket ( RTM_DELLINK)
  2002-01-07 11:38 Faced a problem with rtnetlink socket ( RTM_DELLINK) Venkata Rajesh Velamakanni
@ 2002-01-07 13:21 ` Venkata Rajesh Velamakanni
  0 siblings, 0 replies; 2+ messages in thread
From: Venkata Rajesh Velamakanni @ 2002-01-07 13:21 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1063 bytes --]

Please ignore the previous mail. I came to know that
in both cases kernel sends  RTM_NEWLINK and one can
differentiate it using the flags ( IFF_RUNNING).

Thanks,
Rajesh.
----- Original Message ----- 
From: "Venkata Rajesh Velamakanni" <rajesh.venkata@wipro.com>
To: <linux-kernel@vger.kernel.org>
Sent: Monday, January 07, 2002 5:08 PM
Subject: Faced a problem with rtnetlink socket ( RTM_DELLINK)


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: 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.
------------------------------------------------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-01-07 13:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-07 11:38 Faced a problem with rtnetlink socket ( RTM_DELLINK) Venkata Rajesh Velamakanni
2002-01-07 13:21 ` Venkata Rajesh Velamakanni

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®