i need to bind socket address and port for ipv6 programming...
i canoot able to bind global ipv6 address by using normal bind command....
help me to bind ipv6 address and port number

which socket library are you using?

linux sockets

so, i guess that means the <sys/socket.h> library?

post the code you're using to bind and we can see whats going on.

i need to bind to the address something like 2001:67::2
srcip="2001:67::2"

sockaddr_in6 local;
local.sin6_family=AF_INET6;
local.sin6_port = htons(port);
local.sin6_flowinfo=0;
if (srcip == NULL) {
        local.sin6_addr=in6addr_any ;
    } else {
        rc=inet_pton(AF_INET6,srcip,&(local.sin6_addr));
    }
       localsock = socket(AF_INET6,SOCK_STREAM,0);
if (bind(localsock,(struct sockaddr*)&local,sizeof(local)) < 0) {
        fprintf(stderr,"Cannot bind to the specified Address/Port\n");
        exit(1);
    }

i need to bind to global address space...but its not working

your code is not compiling without a lot of effort on my end, and hence i havent been able to put much time into this while at work.

is this for a server i assume? do you have any more code along with this?

the problem doesnt seem to be in your code. the problem seems to be that your ip address is refusing the bind.

at least that's the error i get. your's may be different, so try this code and see what error code is returned.

errno=0;
handle = bind(localsock,(struct sockaddr*)&local,sizeof(local));
printf( "bind -- Error #%3d: %s\n", errno, strerror( errno ) );
if (handle < 0) 
{
    fprintf(stderr,"bind command failed\n", errno);
    exit(1);
}

because your code, as written (with the assumption that you included all appropriate headers and gave a meaningful port number) ... the code works. i dont see anything wrong with it.

here was additional debug results from my run:

[jezebel@localhost cprogs]$ ./ipv6test

ipv6 = 2001:0067:0000:0000:0000:0000:0000:0002
inet_pton -- Error #  0: Success

localsock = 4
socket open -- Error #  0: Success

bind -- Error # 13: Permission denied
bind command failed

[jezebel@localhost cprogs]$

so you were able to solve your problem?

because, it makes sense that I would have permission denied trying to bind as a server to your IP (I dont even know the correct port number) .... but was that the same result for you?

the fact that i got a "permission denied" error, tells me that the bind was being performed correctly, just rejected, which I would expect from my end.

did it give you the same error, and were you able to resolve it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.