Whats the meaning from the IP Headers in C iph_tos? - c

Of course, some information are going to be send to the target machine. Something like the IP version and the length... But what does "tos" mean?
­­­­­­­­­­­­­­­­­­­­

From [man]: IP(7):
IP_TOS (since Linux 1.0)
Set or receive the Type-Of-Service (TOS) field that is sent...

Related

Specifying new option for hop by hop extension header IPv6?

I have been trying to get an answer for this for sometime now but not been able to find it.
Is there a way that I can specify a new option value for the hop by hop extension header in IPv6, so that I can parse the value in the user space rather than the kernel parsing it?
The kernel when tries to parse the value, sends me an ICMP reply stating parameter not recognized for that value in the header.
I'm wondering if there should be a way to deploy and test new options in IPv6 extension header without writing handlers for them as LKM.
There isn't a lot available on the web for IPv6, so any help from IPv6 experts would be great!
RFC 2460 mentions this. I assume you can create a new option type for testing any new applications:
Mindful of the need for compatibility with existing IPv6 deployments,
new IPv6 extension headers MUST NOT be created or specified, unless
no existing IPv6 Extension Header can be used by specifying a new
option for that existing IPv6 Extension Header. Any proposal to
create or specify a new IPv6 Extension Header MUST include a detailed
technical explanation of why no existing IPv6 Extension Header can be
used in the Internet-Draft proposing the new IPv6 Extension Header.
As for "The kernel when tries to parse the value, sends me an ICMP reply ..." you mentioned, by "kernel" I assume you means a remote ipv6 node ( either router or destination host ). Then you might set the "Option Type" wrong way in your egress packet sending by raw-socket.
As RFC 2460 says:
The Option Type identifiers are internally encoded such that their highest-order two bits specify the action that must be taken if the processing IPv6 node does not recognize the Option Type:
00, 01, 10, 11 ....
--- I guess you fill in "10" or "11", you could fill in "00"

Socket Direct Protocol error: "Address family not supported by protocol"

I thought I would try out SDP on our infiniband hardware.
However, when I try to add AF_INET_SDP as the first argument to socket() I get the following error:
"Address family not supported by protocol".
Originally I had:
#define AF_INET_SDP 26
But after doing some reading, noticed a patch applied some time back to change this value to 27.
When set to 26 I get the error:
"Error binding socket: No such device"
Has anyone managed to get SDP working on Ubuntu 12.04? what did you do to get it up and running?
I have installed libsdp1 and libsdpa-dev
Using the LD_PRELOAD method on iperf I also get the first error:
LD_PRELOAD=libsdp.so iperf -s
dir: /tmp/libsdp.log.1000 file: /tmp/libsdp.log.1000/log
socket failed: Address family not supported by protocol
bind failed: Bad file descriptor
Therefore I assume 27 is the correct domain number.
SDP hasn't been accepted on the mainline linux kernel. On recent fedora, they don't ship it, neither the user space libsdp.
If you still want to experiment, Matt is right, the module in question is 'ib_sdp'.
try modprobe ib_sdp and run your example again.

snmptrap IPv6 destination not working

I compile snmptrap as a "stand alone" application to run on an enbedded device.
Sending trap with IPv4 works like a charm, but when using an IPv6 address as the destination, the following is showing in the logs:
tdomain: tdomain_transport_full("snmptrap", "udp6:[fd64:3ef5:bb33::2]", 0, "[NIL]", "[NIL]")
tdomain: Found no domain from specifier "udp6"
I compiled my net-snmp (v5.7.2) libraries with
--enable-ipv6
--with-mib-modules="mibII/ipv6 host notification snmpv3mibs"
--with-transports="UDPIPv6 TCPIPv6"
And excecute the commandline app as:
snmptrap -v 1 -M ./mibs/ -c public 'udp6:[fd64:3ef5:bb33::2]' '1.2.
3.4.5.6' '172.16.11.144' 6 99 '55' 1.11.12.13.14.15 s "teststring"
Can anyone point me in the right direction for solving this?
Cheers,
Frank
Make sure the Ipv6[fd64:3ef5:bb33::2] address is reachable, and you have successfully compiled the net-snmp library using --ipv6 enable,
After compilation you have instructed the snmpd to use both udp and udp6 protocol.
you can debug the SNMP protocol using Wireshark
Alternately you can try other client as well to send the IPv6 pdu to make sure your client is sending the right data.

Finding interface name for destination address using routing table

i'm trying to find a linux C function which should obtain interface name(or id) of ipv6 destination address using routing informating.
I want use this interface name to send my raw packet through pcap_inject()
Does something like this exist? or i have to popen ip -6 route and parse information from this output?
what you are looking for is ICMPv6 protocol, messages are NeighborAdvertisment and NeighborSolicitation

getting the domain name by code in Linux

I am using getdomainname() and gethostbyname() to try to get the domain of the computer so I can show the correct information on my program. However sometimes these functions don't return the correct information.
Is there any other way (in plain C) to get the domain name in Linux?
Edit: just to make it a bit more clear: I want to check if the computer is part of a domain. If it is, get the domain name.
Currently I am using the functions mentioned above. Are there any others?
#unwind: please DO NOT edit this question for "brevity" if I would like to say thanks I'll say thanks.
Thanks!
If you want to get the (Internet) domain name there are certain issues you need to think about.
A computer can have multiple network interfaces, in fact it almost certainly has at least two including the loopback interface. Each interface has an IP address (possibly more than one) and each IP address can be mapped to from any number of DNS names and entries in the hosts file.
So which, if any of the many possible domain names that getdomainname() returns depends on a whole raft of configuration issues. e.g. which IP address is configured to be the primary address, whether the hosts file is used in preference to DNS, whether the hosts file is correctly configured, whether the IP address has a reverse lookup set and lots of other issues.
For instance, it is fairly common to misconfigure the hosts file. If you see an entry in it like:
192.168.1.1 foohost foohost.example.com
that is wrong. The first host name on a line is the canonical name (for the interface) and subsequent entries are merely aliases. If you want the domain to come out as example.com rather than nothing, it needs to look like this:
192.168.1.1 foohost.example.com foohost
Also, every IP address on the Internet should ideally have a reverse lookup record in DNS which maps the IP address to a hostname and domain. However, there is no rule to say it has to exist or to say that it has to be the domain by which you SSH'd in or pointed your web browser at.
On any given computer, there are many reasons why the domain name is not what you expect.
Unfortunately this information is not always set correctly. First of all, complain to your system administrator.
If all that fails, with something like the following you may get a field res->ai_canonname with a canonical hostname and then also iterate over all IP addresses:
struct addrinfo *res = NULL;
struct addrinfo hints = {
.ai_family = AF_UNSPEC,
.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG | AI_CANONNAME | (name ? 0 : AI_PASSIVE),
.ai_socktype = SOCK_STREAM,
};
getaddrinfo(name, NULL, &hints, &res);
for (struct addrinfo *p = res; p; p = p->ai_next) {
...
}
You'd then somehow have to select which ones are interesting for you (avoid loopback etc) and try to find a hostname corresponding to one of these IP addresses. But as IP addresses do not necessarily correspond to a valid hostname, this might fail also.
To get the hostname of the computer you are running the program on:
uname
/etc/hostname

Resources