P
P
Pavel2017-11-07 16:28:08
Rust
Pavel, 2017-11-07 16:28:08

How reliable is using gethostbyname()?

Hello. Are there any pitfalls when using this feature?
Maybe it doesn't always work correctly or something?
I plan to use it to authorize API requests. Those. check whether $_SERVER['REMOTE_ADDR']the received address matches with the help gethostbyname()from the domain sent in the request from the client. Well, i.e. that the request was from this domain, and not spoofed in the request. All these dances are needed, because. I haven't found a reliable way to get the host the request came from. $_SERVER['HTTP_REFERER']is not always present, and all other headings can be slipped whatever you like.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
Z
ziplane, 2019-08-14
@ziplane

I still don't understand how to do it in for.
The condition didn't work because I'm an idiot. Counting starts from 0 in an array/vector.
while solution:

pub fn mirror(input:&mut Vec<i32>) {

    let mut n = input.len()-1;

    let mut i = 0;
    while ( i < n) {
        if i != n {
            input.swap(i,n);
            n = n-1;
        }
        i+=1
    }

}

D
Dmitry Demin, 2019-08-21
@keksmen

The fact is that this section defines an iteration from 0 to z-1. Therefore, k is never equal to z. If you want to iterate from 0 to z, you should use the following syntax:
for k in 0..=z

H
humbug, 2019-08-14
@humbug

The vector is flipped in one cycle from 0 to half the length of the array, swapping 0th and last, 1st and penultimate...etc.

S
Stalker_RED, 2017-11-07
@Palych_tw

REFERRER can be passed any, or not passed at all.
Where do you get the domain for gethostbyname? You are aware that many computers do not have a domain name at all, and some may have many names.
More or less reliably, you get only IP, and even then, without taking into account proxy servers, which may not be "marked" in the headers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question