Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2015-08

fprecvfrom for IPv6?

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Klaus Hartnegg

Hello,

How can fprecvfrom work with IPv6?

It returns the address of the sender in a record sockaddr, which only has space for an IPv4 address.
http://www.freepascal.org/docs-html/rtl/sockets/fprecvfrom.html

Is there an undocumented variant in which psockaddr points to sockaddr_in6 instead of sockaddr?

Or is this already the case in the existing fprecvfrom?

One of my programs suddenly claims that fprecvfrom returned an address record with size 28 bytes instead of 16 (in fromlen:pSockLen), when it runs in Redhat (using xinetd) instead of Ubuntu (using openbsd-inetd), when receiving an UDP packet. Interestingly sizeof(sockaddr_in6) is 28. Probably not a coincidence, but I whish it were documented, because I don't want to develop software based on guessing.

Btw. what does fpcrectfrom do when fromlen^ is smaller than the amount of data that it wants to copy to psockaddr^? Buffer overflow?

thanks,
Klaus

Michael Van Canneyt
to Klaus Hartnegg
Klaus Hartnegg wrote 10 lines
Hello, How can fprecvfrom work with IPv6? It returns the address of the sender in a record sockaddr, which only has space for an IPv4 address. http://www.freepascal.org/docs-html/rtl/sockets/fprecvfrom.html Is there an undocumented variant in which psockaddr points to sockaddr_in6 instead of sockaddr?

No.

Or is this already the case in the existing fprecvfrom?

The call itself does not do any checking on the length. You will have to typecast your pointer till we add an overloaded version for IPV6.

Show quoted text 6 lines
One of my programs suddenly claims that fprecvfrom returned an address record with size 28 bytes instead of 16 (in fromlen:pSockLen), when it runs in Redhat (using xinetd) instead of Ubuntu (using openbsd-inetd), when receiving an UDP packet. Interestingly sizeof(sockaddr_in6) is 28. Probably not a coincidence, but I whish it were documented, because I don't want to develop software based on guessing.

Neither do we.

Btw. what does fpcrectfrom do when fromlen^ is smaller than the amount of data that it wants to copy to psockaddr^? Buffer overflow?

It does not do anything. The call will work regardless of the size of the IP address. These parameters are pointers, no checking on length is done by FPC code.

It just means we'll have to make an overloaded version. Please enter a bugreport in the bugtracker, so it is not forgotten.

Michael.