How to modify linklocal address of an ethernet interface

Murali Annamneni a.murali at hcl.com
Wed Nov 7 07:44:54 EST 2012


Hi,

I have written a sample code to modify the link-local address of an Ethernet interface.
The code snippet is -

    while(1) {
        printf("\n1.Add Link Local\n2.Modify LinkLocal\n");
        scanf("%d", &ch);
        switch(ch) {
            case 1:
            {
                add_linklocaladdr(fd, NLM_F_CREATE|NLM_F_EXCL);
                break;
            }
            case 2:
            {
                add_linklocaladdr(fd, NLM_F_REPLACE);
                break;
            }
-------------
-------------
void add_linklocaladdr(int fd, int flags)) {
-------------
-------------
    nlh = (struct nlmsghdr *)buf;
    len = MSG_ALIGN(sizeof(struct nlmsghdr));
    nlh->nlmsg_len   = len;
    nlh->nlmsg_type  = RTM_NEWADDR;
    nlh->nlmsg_flags = NLM_F_REQUEST | flag;
    nlh->nlmsg_seq = 1;

    ifadr = nlmsg_put_extra_header(nlh, sizeof(struct ifaddrmsg));
    ifadr->ifa_family    = AF_INET6;
    ifadr->ifa_prefixlen = 0x40 ; /*hardcoded*/
    ifadr->ifa_flags     = IFA_F_PERMANENT;;
    ifadr->ifa_scope     = RT_SCOPE_HOST;
    ifadr->ifa_index     = 2;

    /*Push 'struct nlattr' */
    attr_put(nlh, IFA_ADDRESS, dst);

When I execute case 1 (add link-local), a new ipv6 ip is getting added.
I want to modify an existing link local address in case2, but it's not working.
Can anybody help me correcting this code for case2.


Thanks & Regards
Murali Annamneni



::DISCLAIMER::
----------------------------------------------------------------------------------------------------------------------------------------------------

The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted,
lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The e mail and its contents
(with or without referred errors) shall therefore not attach any liability on the originator or HCL or its affiliates.
Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the
views or opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification,
distribution and / or publication of this message without the prior written consent of authorized representative of
HCL is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately.
Before opening any email and/or attachments, please check them for viruses and other defects.

----------------------------------------------------------------------------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20121107/3c44b5f8/attachment-0001.html 


More information about the Kernelnewbies mailing list