Gateway autodetection