Does Winsock support IPv6 extension headers? - winsock

Is it possible to look at (and modify) IPv6 extension headers with Winsock using C/ C++? What API's allow us to do that?

IPv6 headers are not received using Raw Sockets on Winsock. As this MSDN page says
For IPv6 (address family of AF_INET6), an application receives
everything after the last IPv6 header in each received datagram
regardless of the IPV6_HDRINCL socket option. The application does not
receive any IPv6 headers using a raw socket.
In other words, it's not possible to receive and modify IPv6 headers (or extension headers) using Winsock.

Related

What's the difference of HTTP Programming and Socket Programming? [duplicate]

What is the difference between socket programming and Http programming? can anyone help please?
HTTP is an application protocol. It basically means that HTTP itself can't be used to transport information to/from a remote end point. Instead it relies on an underlying protocol which in HTTP's case is TCP.
You can read more about OSI layers if you are interested.
Sockets on the other hand are an API that most operating systems provide to be able to talk with the network. The socket API supports different protocols from the transport layer and down.
That means that if you would like to use TCP you use sockets. But you can also use sockets to communicate using HTTP, but then you have to decode/encode messages according to the HTTP specification (RFC2616). Since that can be a huge task for most developers we also got ready clients in our developer frameworks (like .NET), for instance the WebClient or the HttpWebRequest classes.
With HTTP you use high-level HTTP protocol(that works on top of a socket). It's session-less which means you send text request like GET google.com and receive text or binary data in return, after that connection is closed(in HTTP 1.1 persistent connections are available)
MSDN example:
public static void Main (string[] args)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create (args[0]);
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
Console.WriteLine ("Content length is {0}", response.ContentLength);
Console.WriteLine ("Content type is {0}", response.ContentType);
// Get the stream associated with the response.
Stream receiveStream = response.GetResponseStream ();
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);
Console.WriteLine ("Response stream received.");
Console.WriteLine (readStream.ReadToEnd ());
response.Close ();
readStream.Close ();
}
With sockets you go on the level lower and actually control the connection and send/receive raw bytes.
Example:
var remoteEndpoint=new IPEndPoint(IPAddress.Loopback, 2345);
var socket = new Socket(remoteEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(remoteEndpoint);
socket.Send(new byte[] {1, 2, 3, 4});
HTTP Connection
HTTP connection is a protocol that runs on a socket.
HTTP connection is a higher-level abstraction of a network connection.
With HTTP connection the implementation takes care of all these higher-level details and simply send HTTP request (some header
information) and receive HTTP response from the server.
Socket Connection
Socket is used to transport data between systems. It simply connects two systems together, an IP address is the address of the
machine over an IP based network.
With socket connection you can design your own protocol for network connection between two systems.
With Socket connection you need to take care of all the lower-level details of a TCP/IP connection.
for two endpoints to be able to talk to each other they should both follow a set of rules. in computer these set of rules is called protocol.
for example for an endpoint like browser and for another like a web server they should both follow a set of rules or protocol called http to be able to communicate and trade information . so in the world wide web and this kind of communications only those who talk based on this http protocol could successfully talk to each other.
socket is just an endpoint. it could follow http protocol to come in a communication in www as a client requesting a page or it could act as a server listening to connections. or maybe it could follow another set of rules or protocols like ssh, ftp and communicate in other ways.
now in socket programming you could make a socket , bind it to an ip address and a port number to act as a port number and tell it to follow http , ssh ,ftp or whatever you want based on the communications that you want to use your socket for.
HTTP programming or HTTP request is used for loosely coupling and platform-neutral language technology communication where as socket programming is used where system has language specification protocol
Socket programming is a kind of middleware, residing between the application layer and the TCP layer. It's able to carry anything present in the application layer; even HTTP data.

Does INADDR_ANY care about new interface?

From reading from other posts
understanding INADDR_ANY for socket programming - c
INADDR_ANY is used when you don't need to bind a socket to a specific
IP. When you use this value as the address when calling bind(), the
socket accepts connections to all the IPs of the machine
http://trac.pjsip.org/repos/wiki/IPAddressChange
by default we bind transports to INADDRANY/0.0.0.0, so when sending
outgoing (UDP) packets, we rely on the OS to select the correct
interface for us, based on what interfaces are currently online and
the OS's internal routing table. In other words, we just call sendto()
and let the OS "do the right thing". In case of IP address change, we
are also relying on the OS to switch the interface from one interface
to the new one for our UDP transmissions
Supposed that previously I have 2 interface A, B when binding my socket using IADDR_ANY. After that I have interface C available (This is the case on mobile device, when user turns on 3G, Wifi)
Will this socket accept connections from C
If I turn off A, B, will this socket use C to send packets ?
P/S: Answers targeting iOS and Android (both SDK and NDK socket) are more appreciated

difference between socket programming and Http programming

What is the difference between socket programming and Http programming? can anyone help please?
HTTP is an application protocol. It basically means that HTTP itself can't be used to transport information to/from a remote end point. Instead it relies on an underlying protocol which in HTTP's case is TCP.
You can read more about OSI layers if you are interested.
Sockets on the other hand are an API that most operating systems provide to be able to talk with the network. The socket API supports different protocols from the transport layer and down.
That means that if you would like to use TCP you use sockets. But you can also use sockets to communicate using HTTP, but then you have to decode/encode messages according to the HTTP specification (RFC2616). Since that can be a huge task for most developers we also got ready clients in our developer frameworks (like .NET), for instance the WebClient or the HttpWebRequest classes.
With HTTP you use high-level HTTP protocol(that works on top of a socket). It's session-less which means you send text request like GET google.com and receive text or binary data in return, after that connection is closed(in HTTP 1.1 persistent connections are available)
MSDN example:
public static void Main (string[] args)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create (args[0]);
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
Console.WriteLine ("Content length is {0}", response.ContentLength);
Console.WriteLine ("Content type is {0}", response.ContentType);
// Get the stream associated with the response.
Stream receiveStream = response.GetResponseStream ();
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);
Console.WriteLine ("Response stream received.");
Console.WriteLine (readStream.ReadToEnd ());
response.Close ();
readStream.Close ();
}
With sockets you go on the level lower and actually control the connection and send/receive raw bytes.
Example:
var remoteEndpoint=new IPEndPoint(IPAddress.Loopback, 2345);
var socket = new Socket(remoteEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(remoteEndpoint);
socket.Send(new byte[] {1, 2, 3, 4});
HTTP Connection
HTTP connection is a protocol that runs on a socket.
HTTP connection is a higher-level abstraction of a network connection.
With HTTP connection the implementation takes care of all these higher-level details and simply send HTTP request (some header
information) and receive HTTP response from the server.
Socket Connection
Socket is used to transport data between systems. It simply connects two systems together, an IP address is the address of the
machine over an IP based network.
With socket connection you can design your own protocol for network connection between two systems.
With Socket connection you need to take care of all the lower-level details of a TCP/IP connection.
for two endpoints to be able to talk to each other they should both follow a set of rules. in computer these set of rules is called protocol.
for example for an endpoint like browser and for another like a web server they should both follow a set of rules or protocol called http to be able to communicate and trade information . so in the world wide web and this kind of communications only those who talk based on this http protocol could successfully talk to each other.
socket is just an endpoint. it could follow http protocol to come in a communication in www as a client requesting a page or it could act as a server listening to connections. or maybe it could follow another set of rules or protocols like ssh, ftp and communicate in other ways.
now in socket programming you could make a socket , bind it to an ip address and a port number to act as a port number and tell it to follow http , ssh ,ftp or whatever you want based on the communications that you want to use your socket for.
HTTP programming or HTTP request is used for loosely coupling and platform-neutral language technology communication where as socket programming is used where system has language specification protocol
Socket programming is a kind of middleware, residing between the application layer and the TCP layer. It's able to carry anything present in the application layer; even HTTP data.

IP Spoofing at the IP level

I'm just reading about TCP and UDP and from what I've read when the packet gets encapsulated in the IP protocol and the header gets added is it not possible to create a false IP address at this stage?
Granted, the response will never be received on your connection, but is this possible?
I do not want to do this btw. I'm in no way associated with immoral ethics. It's just something that I had to ask whilst reading about TCP and UDP. I'm actually learning how to use sockets in C++ for a game I'm working on.
Yes, this is possible.
Use raw sockets and craft your own packets
Use scapy, hping, etc
Search for "packet crafting"
EDIT
A nice scapy tutorial that teaches you to send lots of valid and invalid stuff is here.

Is there a way to manipulate udp packets after an application sends it to a socket?

In other words, can I intercept those packets (possibly at the stack level) using a separate application, manipulate them and then send them to the destination the original application was trying to send them to?
You can open socket with PF_PACKET protocol type, intercept all packets on the interface and send them directly.
Check out man 7 packet and man socket. I believe you'll need root rights to run such application.
Sniffing Bytes over the Network

Categories