473,786 Members | 2,574 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IPv6 question

I'm not sure if this is a question about python socket support or sockets in
general ...

I have a socket server with which I want to accept incoming connections on
ipv4 and ipv6.
I've found that if I create the listening socket with
sock = socket(AF_INET, SOCK_STREAM)
it will accept connections on ipv4 (only) and if I create it with
sock = socket(AF_INET6 , SOCK_STREAM)
it will accept connections with ipv6 (only)

Is there a way to make a single socket accept connections using both
protocols?
Or do I need create two sockets and listen on them both?
Jul 18 '05 #1
8 2546
"John Burton" <jo*********@jb mail.com> wrote in message
news:9r******** ****@neon.jbmai l.com...
I'm not sure if this is a question about python socket support or sockets in general ...

I have a socket server with which I want to accept incoming connections on
ipv4 and ipv6.
I've found that if I create the listening socket with
sock = socket(AF_INET, SOCK_STREAM)
it will accept connections on ipv4 (only) and if I create it with
sock = socket(AF_INET6 , SOCK_STREAM)
it will accept connections with ipv6 (only)

Is there a way to make a single socket accept connections using both
protocols?
Or do I need create two sockets and listen on them both?


Oops I missed out the point of my question ...

If I need to create an IPv4 socket and IPv6 socket and listen on both that
doesn't
seem to work.

sock4 = socket(AF_INET, SOCK_STREAM)
sock4.bind(('', 12345))
sock6 = socket(AF_INET6 , SOCK_STREAM)
sock6.bind(('', 12345))

I get an error that the address is already in use on the 2nd bind even
though it's to a different
socket type. This is on linux.
Has anyone got this to work? Or am I missing something?
Jul 18 '05 #2
John Burton wrote:
If I need to create an IPv4 socket and IPv6 socket and listen on both that
doesn't
seem to work.

sock4 = socket(AF_INET, SOCK_STREAM)
sock4.bind(('', 12345))
sock6 = socket(AF_INET6 , SOCK_STREAM)
sock6.bind(('', 12345))

I get an error that the address is already in use on the 2nd bind even
though it's to a different
socket type. This is on linux.
Has anyone got this to work? Or am I missing something?


You are missing something important. According to RFC 2553, a PF_INET6
socket can be used for IPv4 communication, by means of IPV4_MAPPED
addresses (::FFFF:<IPv4-address>). So an application openening a
PF_INET6 listening socket will accept both IPv4 and IPv6 incoming
connections.

If you want a socket that listens only on IPv6 connections, you
need to set the IPV6_V6ONLY socket option. In your case, it is
sufficient to just not create the IPv4 socket. When clients connect
through IPv4, you will find that the peername(2) of the socket
is an IPv4-mapped address. You should never ever transmit such
an address over the wire; it is meant for local use only.

Regards,
Martin

Jul 18 '05 #3
Martin v. Löwis" <ma****@v.loewi s.de> wrote in message
news:c0******** *****@news.t-online.com...
John Burton wrote:
If I need to create an IPv4 socket and IPv6 socket and listen on both that doesn't
seem to work.

sock4 = socket(AF_INET, SOCK_STREAM)
sock4.bind(('', 12345))
sock6 = socket(AF_INET6 , SOCK_STREAM)
sock6.bind(('', 12345))

I get an error that the address is already in use on the 2nd bind even
though it's to a different
socket type. This is on linux.
Has anyone got this to work? Or am I missing something?


You are missing something important. According to RFC 2553, a PF_INET6
socket can be used for IPv4 communication, by means of IPV4_MAPPED
addresses (::FFFF:<IPv4-address>). So an application openening a
PF_INET6 listening socket will accept both IPv4 and IPv6 incoming
connections.

If you want a socket that listens only on IPv6 connections, you
need to set the IPV6_V6ONLY socket option. In your case, it is
sufficient to just not create the IPv4 socket. When clients connect
through IPv4, you will find that the peername(2) of the socket
is an IPv4-mapped address. You should never ever transmit such
an address over the wire; it is meant for local use only.


Thank you for your reply. That makes a lot of sense and I've had another
try and it does work as you suggest. (I was thinking that Ipv6 sockets
were not receiving connections via ipv4 because as you say they are
reporting an ipv6 style mapped address)

I've got a horrible feeling it doesn't work like this on windows though
(my python build on windows doesn't seem to support ipv6 so I can't
try it)
Jul 18 '05 #4
John Burton wrote:
I've got a horrible feeling it doesn't work like this on windows though
(my python build on windows doesn't seem to support ipv6 so I can't
try it)


If you want to try IPv6 support on Windows, you can use a Python 2.4
snapshot I built, at

http://www.dcl.hpi.uni-potsdam.de/ho....4.0.12421.msi

If you don't want this snapshot to override file associations, make
sure you check the Advanced dialog.

Regards,
Martin

Jul 18 '05 #5
"Martin v. Löwis" <ma****@v.loewi s.de> wrote in message
news:c0******** *****@news.t-online.com...
John Burton wrote:
I've got a horrible feeling it doesn't work like this on windows though
(my python build on windows doesn't seem to support ipv6 so I can't
try it)


If you want to try IPv6 support on Windows, you can use a Python 2.4
snapshot I built, at

http://www.dcl.hpi.uni-potsdam.de/ho....4.0.12421.msi

If you don't want this snapshot to override file associations, make
sure you check the Advanced dialog.


Thanks! I'll take a look.
Jul 18 '05 #6
"Martin v. Löwis" <ma****@v.loewi s.de> wrote in message
news:c0******** *****@news.t-online.com...
John Burton wrote:
I've got a horrible feeling it doesn't work like this on windows though
(my python build on windows doesn't seem to support ipv6 so I can't
try it)


If you want to try IPv6 support on Windows, you can use a Python 2.4
snapshot I built, at

http://www.dcl.hpi.uni-potsdam.de/ho....4.0.12421.msi


Thanks for this it seems to work well.
It does seem that on windows you need to bind different sockets to the same
address,
one for IPv4 and one for IPv6 whereas on linux the IPv6 socket will receive
connections to both.

I suppose that's not a big problem but a shame.
Jul 18 '05 #7
"John Burton" <jo*********@jb mail.com> writes:
Thanks for this it seems to work well.
It does seem that on windows you need to bind different sockets to the same
address,
one for IPv4 and one for IPv6 whereas on linux the IPv6 socket will receive
connections to both.

I suppose that's not a big problem but a shame.


you can control this using the IPV6_V6ONLY socket option, like so:

s.setsockopt(so cket.IPPROTO_IP V6, socket.IPV6_V6O NLY, 0)

unfortunately python 2.3.3 doesn't yet make that constant available
though it is fixed in cvs. you could glean the value from the headers.

the default setting has been in flux on various platforms recently,
all the more reason to want to always set it explicitly...

-- erno
Jul 18 '05 #8
Erno Kuusela wrote:
you can control this using the IPV6_V6ONLY socket option, like so:

s.setsockopt(so cket.IPPROTO_IP V6, socket.IPV6_V6O NLY, 0)

unfortunately python 2.3.3 doesn't yet make that constant available
though it is fixed in cvs. you could glean the value from the headers.

the default setting has been in flux on various platforms recently,
all the more reason to want to always set it explicitly...


I think the OP would prefer to have a single socket for both protocol
types, in which case he should set it to 1 on windows, right?

Regards,
Martin

Jul 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1795
by: Agent | last post by:
I would like to invite you and your associates to attend the US IPv6 (Internet Protocol version 6) Summit, December 8-11, 2003 in Crystal City, VA, near the Pentagon. This major opportunity to participate in transitioning to the new Internet is in response to both DoD and Industry requests for a concentrated, affordable conference in the Washington, D.C. area. This exciting and informative conference on the Next Generation Internet will...
7
5953
by: Torsten Schmidt | last post by:
Hi, I'm trying to connect to a mysql-Server using PHP's mysql-function mysql_connect. The host on which the mysql-server is running is not the same as the host apache and php are running on. The two computers are connected in an IPv6-network. No matter if I give the hostname (defined in /etc/hosts), the IPv6-address ("fec0::4") or the IPv6-address in square brackets ("") the function mysql_connect always prints "Unknown MYSQL-Server "....
2
6397
by: PaulH | last post by:
I am attempting to write a functon that can perform IPv6 compliant pings. But, Icmp6SendEcho2 causes an access violation whenever it is called: First-chance exception at 0x76d641e8 in mping2.exe: 0xC0000005: Access violation reading location 0x00000000. Unhandled exception at 0x76d641e8 in mping2.exe: 0xC0000005: Access violation reading location 0x00000000. I have been unable to pinpoint the cause of the access violation so far, so I...
2
3026
by: gregory_may | last post by:
First the research links: IPv6 spec (look for 'jumbo payload'): http://www.cs-ipv6.lancs.ac.uk/ipv6/documents/rfcs/archive/rfc1883.txt IPv6 Sample C# Client/Server http://www.codeproject.com/csharp/ipv6.asp I am developing an application where I need to broadcast information to clients. I have hit a 64K limit in UDP broadcasting. I am not exited
8
9942
by: prabhuram.k | last post by:
Can anybody know how to validate IPV4 and IPV6 address in C++
3
6246
by: jiri.juranek | last post by:
Hello, is there any common function for validation if string contains valid ip address(both ipv4 and ipv6)? Or does sb wrote some regular expression for this? thanks J
3
1858
by: Pramod TK | last post by:
Hello All, I have some queries related to python support for IPv6. Can you kindly clarify the doubts which I have - 1. Does python support IPv6? 2. Does it support setting of QoS flags? 3. Does it support tunneling of IPv6 on a IPv4 network? 4. If an IPv4 address is given, does it support this on a IPv6 network? If not can you kindly let me know, Are there any plans for supporting these features in future?
8
8949
by: Giampaolo Rodola' | last post by:
I'm not sure if this is a question about python programming, system administration or sockets in general... I have the FTP server in my signature to which I'd want to add IPv6 support. My hosting company provides me a common IPv4 address. I'd like to set up my workstation (Windows XP or Linux Debian, doesn't really matter) to temporarily use IPv6 for trying to add such feature to my library (I work on both Windows XP and Linux). Could...
14
9298
by: Simon | last post by:
Hi, is there a straight forward way of converting IPv4 to IPv6? I thought that it was just a matter of converting 32 bits to 128 bits, (by adding 96 leading 0s), but that does not seem right in some/most cases. For example, 127.0.0.1, (IPv4 localhost), does not convert ::1, (IPv6 localhost)
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8992
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6748
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.