In the file rpl-icmp6.c, in the method dio_input, the from variable is a local link address. I want to find the routes from the node who sent that DIO, using uip_ds6_route_lookup(&from). However, inside this method, they compare ip-addresses using uip_ipaddr_prefixcmp instead of uip_ipaddr_cmp. Therefore, I am wondering if there is a method in contiki that translate link-local addresses to prefix - global addresses of neighbor nodes?
EDIT:
uip_ipaddr_t from;
uip_ipaddr_copy(&from, &UIP_IP_BUF->srcipaddr);
route = uip_ds6_route_lookup(from);
if(route != NULL) {
const uip_ipaddr_t *nexthop = uip_ds6_route_nexthop(route);
if(uip_ipaddr_cmp(&from, &nexthop)) {
/* Test rank of the node */
return 1;
}
This is the code, and the method uip_ds6_route_lookup can not find any route because the ipaddress is local link.
Related
I was learning how to develop a front end for dApps by going through the code for Uniswap interface.
Then I found that there are two Web3Providers used in the app like below.
<Web3ReactProvider getLibrary={getLibrary}> // 1st
<Web3ProviderNetwork getLibrary={getLibrary}> // 2nd
<Blocklist>
// some other child nodes
</Blocklist>
<Web3ProviderNetwork>
</Web3ReactProvider>
As for Web3ReactProvider, it uses the component provided by the web3-react package, while Web3ProviderNetwork is created with a key "NETWORK" on the same file those providers are written.
Uniswap has a method useActiveWeb3React which returns web3context values depending on its active variable value.
In other words, default web3Context is returned if active variable is true, otherwise Web3Context with Network is returned. (code below)
export default function useActiveWeb3React() {
const interfaceContext = useWeb3React<Web3Provider>()
const interfaceNetworkContext = useWeb3React<Web3Provider>(
process.env.REACT_APP_IS_WIDGET ? undefined : NetworkContextName
)
if (interfaceContext.active) {
return interfaceContext
}
return interfaceNetworkContext
}
Does anyone know why they switch providers depending on the active variable?
Does it make any difference?
In this codpiece, I am finding it hard to figure out what is msg.sender is and how it works internally.
What I am understanding is, we have a mapping favoriteNumber, and the key is an address and the value is a uint.
What is the meaning of comment - "Update our favoriteNumber mapping to store _myNumber under msg.sender, I am understanding that we are updating favoriteNumber, but what does it mean that under msg.sender. What is the role of this method, how it's working?
mapping (address => uint) favoriteNumber;
function setMyNumber(uint _myNumber) public {
// Update our `favoriteNumber` mapping to store `_myNumber` under `msg.sender`
favoriteNumber[msg.sender] = _myNumber;
// ^ The syntax for storing data in a mapping is just like with arrays
}
function whatIsMyNumber() public view returns (uint) {
// Retrieve the value stored in the sender's address
// Will be `0` if the sender hasn't called `setMyNumber` yet
return favoriteNumber[msg.sender];
}
Every smart contract invocation has a caller address. Each EVM (Ethereum Virtual Machine that executes the code) knows which
account carries out each action. In Solidity, you can access the calling account by
referencing msg.sender
So when you call a function of solidity contract, your contract already gets the information of your account, so your account is the msg.sender
favoriteNumber is a mapping. think it like a javascript object. It maps the account addresses to their favourite number.
0x9C6520Dd9F8d0af1DA494C37b64D4Cea9A65243C -> 10
So when you call setMyNumber(_myNumber), you are passing your favourite number. so this number will be stored in favoriteNumber mapping like this:
yourAccountAdress -> yourFavouriteNumber
So when you call whatIsMyNumber function, since EVM already gets your account number, checks in the mappings and returns you your favourite number.
In solidity exists 3 types of variables: state, local and global.
example of global variables:
msg.sender (sender of the message)
msg.value (number of wei sent with the message)
pseudocode from favoriteNumber[msg.sender] = _myNumber;
given a favoriteNumber list,
select the address of the account calling this function,
assign _myNumber to that address
note: global variables are available in all contracts by default. see more info here: solidity docs - global variable
I'm building a bot therefore I want to use Tor. More, I want to set my Ip to chosen Geoloaction or Country. Is this possible?
Heres my Tor initializing code
public static void setUp() throws Exception {
//driver = new HtmlUnitDriver();
//driver = new FirefoxDriver();
String torPath = "/Applications/TorBrowser.app/Contents/MacOS/firefox";
String profilePath = "/Applications/TorBrowser.app/TorBrowser/Data/Browser/profile.default/";
FirefoxProfile profile = new FirefoxProfile(new File(profilePath));
FirefoxBinary binary = new FirefoxBinary(new File(torPath));
driver = new FirefoxDriver(binary, profile);
baseUrl = "https://qa2all.wordpress.com";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
All you have to do is edit the torrc config file used by the Browser Bundle (usually located at Browser/TorBrowser/Data/Tor) and add a config value like so:
ExitNodes {US}
Where US is the country code of the IP you want to use. You can specify multiples by comma separating them. Note: Country codes must be enclosed by {} in order to work. See the ExcludeNodes documentation for details on what's accepted.
Recently, i was facing a problem while resolving NSNetService.
I was published an NSNetService with type _http._tcp., to be just like an http server.
Other wise, on another device, i was start searching for this service, and it will find it.
After finding it, i was apply resolveWithTimeout on it.
While resolving, sometimes i was get only ipv6, that i can't make an HTTPRequest using NSURLConnection sendAsynchronousRequest: queue: completionHandler: on it.
How can i apply and HTTPRequest on url contains ipv6 ?
How can i deal with that problem ?
It looks like you're building a string like http://{IP}:{port}/ based on the information provided in NSNetService. And it works fine for an IPv4 address, the resulting string is like http://192.168.1.8:8080/.
However, IPv6 addresses use colons as a separator (instead of periods), so the same code generates a string like http://fe80::e31:db5a:0089:98ba:8080/, and the resulting address is incorrect. First, you need to wrap the address in square brackets: http://[fe80::e31:db5a:0089:98ba]:8080/. Second, fe80::/64 (as in the example) addresses are link-local and can be assigned to each IPv6-supporting interface, so you need to also provide the interface to use, e.g. http://[fe80::e31:db5a:0089:98ba%25en0]:8080/ where %25 is an encoded percent symbol and en0 is the interface name to use.
To sum up, you need to build different strings for IPv4 and IPv6 addresses. Speaking of which, there are Apple's recommendations:
As a rule, you should not resolve a service to an IP address and port number unless you are doing something very unusual.
– Connecting to a Bonjour Service by IP Address
Try to use this URL string if possible: http://{hostname}:{port}/, you won't need those extra IP address manipulations.
So this is what I end up using... it correctly translates address into URL including the interface:
NSString * result = nil;
char host[NI_MAXHOST];
char service[NI_MAXSERV];
int err;
err = getnameinfo(address.bytes, (socklen_t) address.length, host, sizeof(host), service, sizeof(service), NI_NUMERICHOST | NI_NUMERICSERV);
if (err == 0) {
struct sockaddr_storage *sockaddr = (struct sockaddr_storage *)address.bytes;
if (sockaddr->ss_family == AF_INET6) {
result = [NSString stringWithFormat:#"[%s]:%s", host, service];
} else if (sockaddr->ss_family == AF_INET) {
result = [NSString stringWithFormat:#"%s:%s", host, service];
}
}
I want to prepend IP header on an existing IP packet while inside NF_HOOK_LOCAL_OUT. The issue I face is that the skb expansion functions (such as copy/clone/expand/reallocate header) allocate a new sk_buff. We can not return this newly allocated pointer since netfilter hook function no longer (kernel version 2.6.31) passes the skb pointer's address (passes by value). How I solved the issue is as follows:
1. I got a new skb using skb_header_realloc(). This copies all the data from skb.
2. I modified the new skb (call it skb2) to prepend the new IP header, set appropriate values in the new IP header.
3. Replace the contents of the original skb (passed in the Netfilter hook function) with the contents of the skb2 using skb_morph(). Returned NF_ACCEPT.
Is this the only way of achieving what I intended to? Is there a more efficient solution? Are there other use cases of skb_morph (besides the IP reassembly code)?
This works for me, in 2.6 kernels:
...
struct iphdr* iph;
if (skb_headroom(skb) < sizeof(struct iphdr))
if (0 != pskb_expand_head(skb, sizeof(struct iphdr) - skb_headroom(skb), 0, GFP_ATOMIC)) {
printk("YOUR FAVOURITE ERROR MESSAGE");
kfree_skb(skb);
return NF_STOLEN;
}
iph = (struct iphdr*) skb_push(skb, sizeof(struct iphdr));
//Fill ip packet
return NF_ACCEPT;
Hope it helps.